Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Incomplete code AST(Get the AST of an incomplete user statement)
Incomplete code AST [message #908194] Tue, 04 September 2012 19:05 Go to next message
Eclipse UserFriend
Hi all,

My goal is to develop a plugin which will use the user code. I was doing some previous work with ASTParser and I would get the AST only if the code was fully compileable. However, it is possible that the user inputs some statement fraction. In that case, ASTParser will, as far as I know, return me an empty AST. Is it possible to circumvent or hack this and to get the AST?
Re: Incomplete code AST [message #908195 is a reply to message #908194] Tue, 04 September 2012 19:09 Go to previous messageGo to next message
Eclipse UserFriend
Have a look at org.eclipse.jdt.core.dom.ASTParser.setKind(int)

HTH,
Stephan
Re: Incomplete code AST [message #908212 is a reply to message #908195] Tue, 04 September 2012 20:26 Go to previous messageGo to next message
Eclipse UserFriend
Stephan Herrmann wrote on Tue, 04 September 2012 19:09
Have a look at org.eclipse.jdt.core.dom.ASTParser.setKind(int)

HTH,
Stephan


Maybe I got something wrong, but I think that can't provide me with an AST of the following piece of code:

...
String str = "I am some string";
int a = str.length +


Re: Incomplete code AST [message #909273 is a reply to message #908212] Thu, 06 September 2012 17:14 Go to previous messageGo to next message
Eclipse UserFriend
oh, I didn't know how incomplete your code is.
Have you tried ASTParser.setStatementsRecovery(true) ?
Of course there are limits what a parser can recognize if it's not legal code (and incomplete statements are by definition illegal ...).

Stephan
Re: Incomplete code AST [message #909396 is a reply to message #909273] Fri, 07 September 2012 00:50 Go to previous message
Eclipse UserFriend
Stephan Herrmann wrote on Thu, 06 September 2012 17:14
oh, I didn't know how incomplete your code is.
Have you tried ASTParser.setStatementsRecovery(true) ?
Of course there are limits what a parser can recognize if it's not legal code (and incomplete statements are by definition illegal ...).

Stephan


Thanks Stephan, that is quite helpful. I can see with ASTView that in this case it recovers in a way that it removes the "+" sign. I think this will be good enough only if I can somehow "apply" that tree to remove that "+". Basically, I would like to remove that part and then add some mine. How hard/easy is that?
Previous Topic:Annotations parsing in Eclipse view plugin
Next Topic:How to get the resources when the plugin install at eclipse??
Goto Forum:
  


Current Time: Tue Jul 22 18:47:58 EDT 2025

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

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

Back to the top