如何确定要使用的 eclipse 依赖项

How to determine which eclipse dependencies to use

在 eclipse PDE 中,当我从 Internet 复制一个片段并且缺少依赖项时,我如何确定我需要导入哪些依赖项? 说我有这个片段:

public static IMethod getSelectedMethod() throws JavaModelException {
    IWorkbenchPage page = PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow().getActivePage();
    ITextEditor editor = (ITextEditor) page.getActiveEditor();
    IJavaElement elem = JavaUI.getEditorInputJavaElement(editor
            .getEditorInput());
    if (elem instanceof ICompilationUnit) {
        ITextSelection sel = (ITextSelection) editor.getSelectionProvider()
                .getSelection();
        IJavaElement selected = ((ICompilationUnit) elem).getElementAt(sel
                .getOffset());
        if (selected != null
                && selected.getElementType() == IJavaElement.METHOD) {
            return (IMethod) selected;
        }
    }

    return null;
}

我在 IMethod、JavaModelException、IJavaElement、JavaUI、ICompulationUnit、IJavaElement 和 IMethod 上遇到语法错误。我碰巧从脑海中知道我需要依赖项 org.eclipse.jdt.coreorg.eclipse.jdt.ui。但是说我不知道​​我需要这些。我如何找出正确的依赖项是什么?

最简单的方法是只使用 'Open Type' 对话框打开您缺少的类型,然后使用上下文菜单中的 'Show In > Package Explorer' 选项。这应该会向您显示 'External Plug-ins'.

中 Eclipse 插件项目中 class 的位置

为了使这项工作顺利进行,您需要安装 Eclipse 源代码(在从 'Eclipse Project Updates' 站点安装新软件中为您的版本安装 'Eclipse SDK'(例如 http://download.eclipse.org/eclipse/updates/4.9 2018-09)。一些 Eclipse 下载可能已经安装了这个。

使 'Open Type' 包含 Eclipse 插件 select 'Include all plug-ins from target in Java search' 选项在首选项的 'Plug-in Development' 页面中。