Generating Resolved AST without a Project [message #255481] |
Thu, 07 August 2008 18:01  |
Eclipse User |
|
|
|
Originally posted by: tbraje.coverity.com
I have a seemingly simple problem. From outside of eclipse plugin, I
would like to generate an AST that I can traverse to gather information on
the source code. I need for this AST to be resolved with references. So,
I have tried:
ASTParser eclipseAstParser = ASTParser.newParser( AST.JLS3 );
eclipseAstParser.setKind(ASTParser.K_COMPILATION_UNIT);
eclipseAstParser.setResolveBindings(true);
(I am using the public api: org.eclipse.jdt.core.dom.ASTParser)
In order to get references, I need to set a classpath. However, the only
way I can figure out how to set a classpath is to create an IJavaProject
and set that against the parser like:
eclipseAstParser.setProject(...);
However, I cannot figure out how to create an instance of IJavaProject. I
am not running from within eclipse, so I don't have a Workspace. If I do
this, for example:
IWorkspace workspace = ResourcesPlugin.getWorkspace();
then I am greeted with an exception:
Exception in thread "main" java.lang.IllegalStateException: Workspace is
closed.
at
org.eclipse.core.resources.ResourcesPlugin.getWorkspace(Reso urcesPlugin.java:339)
.....
Is there a way around this?
Thanks,
Tim Braje
|
|
|
|
Re: Generating Resolved AST without a Project [message #255489 is a reply to message #255485] |
Thu, 07 August 2008 22:24  |
Eclipse User |
|
|
|
Originally posted by: tbraje.coverity.com
Thanks for the response. I have been perusing the source code and it
seems like there is a reasonable api for invoking the 'internal' eclipse
compiler, with reasonable command line arguments. This, of course, gives
back an 'internal' ASTNode which is more difficult to handle than the
public dom. I know it would satisfy me if there were merely a public way
to transform an 'internal' AST into the public dom. It seems that the
classes that do this are package private....
Tim
|
|
|
Powered by
FUDForum. Page generated in 0.06920 seconds