Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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
Zvonimir Pavlinovic is currently offline Zvonimir Pavlinovic
Messages: 10
Registered: June 2012
Junior Member
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
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 997
Registered: July 2009
Senior Member
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
Zvonimir Pavlinovic is currently offline Zvonimir Pavlinovic
Messages: 10
Registered: June 2012
Junior Member
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
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 997
Registered: July 2009
Senior Member
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
Zvonimir Pavlinovic is currently offline Zvonimir Pavlinovic
Messages: 10
Registered: June 2012
Junior Member
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: Wed Aug 27 11:03:29 EDT 2014

Powered by FUDForum. Page generated in 0.02392 seconds