Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Generating Resolved AST without a Project
Generating Resolved AST without a Project [message #255481] Thu, 07 August 2008 18:01 Go to next message
Eclipse UserFriend
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 #255485 is a reply to message #255481] Thu, 07 August 2008 21:11 Go to previous messageGo to next message
Eclipse UserFriend
Timothy Braje a écrit :
> 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
It is not possible right now to get bindings without a java project.
In order to create a project, you need to run a headless Eclipse.
Please add yourself to https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391.
--
Olivier
Re: Generating Resolved AST without a Project [message #255489 is a reply to message #255485] Thu, 07 August 2008 22:24 Go to previous message
Eclipse UserFriend
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
Previous Topic:Can one use the .jardesc file with an ant jar task?
Next Topic:Disable formatter with Java comment
Goto Forum:
  


Current Time: Thu May 08 23:09:04 EDT 2025

Powered by FUDForum. Page generated in 0.06920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top