I'm not sure what you want to do:
- In the running Eclipse plug-in, show all the classes running in the JVM with the plug-in (for example, for other editors, views, Eclipse machines)?
- In the running Eclipse plug-in show all classes created in open Java projects in the workspace? (Since you used the word “workspace,” I suspect that this is what you are looking for.)
Please note that in the latter case, you cannot get the actual Java Class<...> objects, because projects edited and compiled are not loaded for execution in the same JVM as your plugin. Your plug-in code will run along with the Eclipse IDE and Eclipse JDT tool code; only time classes in open projects will be loaded for execution (creating Class<...> objects somewhere) will be when starting or debugging one of these projects., in this case you are dealing with a completely new JVM, and your plugin will no longer exists. It makes sense?
If I read you correctly, I think you will probably want to find “compilation units” rather than “class files”. The "compilation units" correspond to the source .java files, and the "class files" correspond to the pre-built binary class files (often in the JAR). Or maybe you need both. Even better, it looks like what you really want, these are the “types” inside them.
Check out the JDT Core guide for some pretty good information that is very hard to find. Please note that some analysis is possible at the Java model level, but more detailed analyzes (for example, searching “inside” method definitions) will require parsing code fragments in the AST and moving from there. The Java model is pretty usable, but AST can be a little complicated for the first time.
Also consider the Java search engine (documented above) and IType.newTypeHierarchy() for searching and navigating types.
Good luck
Woody zenfell iii
source share