Reputation: 2075
I want to develop an editor for eclipse which works with java projects.
The plugin needs to know the resources in the classpath of the project of the open file. Since the question is quite ambigious i always find threads about the classpath of the bundle/plugin not the project edited with. Can someone tell me the right buzzword(runtime project) or share some code/links for that topic?
To be clear. This editor and its auto-completion/validation has to behave different whenever a classpath entry is added/removed same as the standard java-file editor.
Upvotes: 0
Views: 134
Reputation: 2075
With helpful hint of @howgler i figured out how to get the classpath of the IJavaProject and scan it via google reflections. Hope that help somebody in the future.
@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();
}
}
Upvotes: 1