Skip to main content


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 23:05 Go to next message
Zvonimir Pavlinovic is currently offline Zvonimir PavlinovicFriend
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 23:09 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
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] Wed, 05 September 2012 00:26 Go to previous messageGo to next message
Zvonimir Pavlinovic is currently offline Zvonimir PavlinovicFriend
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 21:14 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
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 04:50 Go to previous message
Zvonimir Pavlinovic is currently offline Zvonimir PavlinovicFriend
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: Thu Apr 25 09:33:22 GMT 2024

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

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

Back to the top