RCP 插件检索运行时项目的类路径

RCP plugin retrieving classpath of the runtime project

我想开发一个适用于 java 个项目的 eclipse 编辑器。

插件需要知道打开文件的项目的类路径中的资源。由于这个问题很含糊,我总是找到关于 bundle/plugin 的类路径的线程,而不是用它编辑的项目。有人可以告诉我正确的流行语(运行时项目)或分享一些关于该主题的 code/links 吗?

说清楚。只要类路径条目 added/removed 与标准 java 文件编辑器相同,此编辑器及其 auto-completion/validation 的行为就必须不同。

在@howgler 的帮助提示下,我想出了如何获取 IJavaProject 的类路径并通过 google 反射扫描它。希望对以后的人有所帮助。

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    INSTANCE = this;
    super.init(site, input);
    FileEditorInput fei = (FileEditorInput) input;
    IFile file = fei.getFile();
    IProject project = file.getProject();
    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject targetProject = JavaCore.create(project);
            final IClasspathEntry[] resolvedClasspath = targetProject.getResolvedClasspath(true);
            ArrayList<URL> urls = new ArrayList<>();
            for (IClasspathEntry classpathEntry : resolvedClasspath) {

                if (classpathEntry.getPath().toFile().isAbsolute()) {
                    urls.add(classpathEntry.getPath().toFile().toURI().toURL());
                } else {
                    urls.add(new File(project.getWorkspace().getRoot().getLocation().toFile(),classpathEntry.getPath().toString()).toURI().toURL());
                }
            }
            URLClassLoader urlCl = new URLClassLoader(urls.toArray(new URL[urls.size()]));

            Reflections reflections = new Reflections(urlCl,new TypeAnnotationsScanner(),new SubTypesScanner(true));
            Set<Class<?>> classes = reflections.getTypesAnnotatedWith(<???>.class);
            System.out.println(classes);
        }
    } catch (CoreException | IOException e1) {
        e1.printStackTrace();
    }

}