Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to manipulate the AST?
How to manipulate the AST? [message #798475] Tue, 14 February 2012 18:42 Go to next message
b x is currently offline b x
Messages: 16
Registered: February 2012
Junior Member
hi,
I am working on AST, and now I want to modify an AST and store these modifications back into Java source code.
Do you know how to do it, like creating a new AST node?
Re: How to manipulate the AST? [message #798549 is a reply to message #798475] Tue, 14 February 2012 20:43 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier Thomann
Messages: 518
Registered: July 2009
Senior Member
Check the documentation of the class org.eclipse.jdt.core.dom.rewrite.ASTRewrite. To create new nodes, check the class org.eclipse.jdt.core.dom.AST.

HTH,

Olivier
Re: How to manipulate the AST? [message #798919 is a reply to message #798549] Wed, 15 February 2012 08:22 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam Kandula
Messages: 444
Registered: July 2009
Senior Member
http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html could also help you.
Re: How to manipulate the AST? [message #800039 is a reply to message #798475] Thu, 16 February 2012 16:07 Go to previous messageGo to next message
b x is currently offline b x
Messages: 16
Registered: February 2012
Junior Member
Thank you, and now I want to create an assignment node, so first I should write like "Assignment a = ast.newAssignment()", then what else should I do?
Re: How to manipulate the AST? [message #800207 is a reply to message #800039] Thu, 16 February 2012 20:38 Go to previous messageGo to next message
Joey Zhu is currently offline Joey Zhu
Messages: 7
Registered: February 2012
Junior Member
There are various types of nodes in AST tree. There is an ASTViewer eclipse plugin, which would be very very helpful for you to understand what kinds of nodes included in a java source file.
Re: How to manipulate the AST? [message #811843 is a reply to message #800207] Fri, 02 March 2012 22:24 Go to previous messageGo to next message
b x is currently offline b x
Messages: 16
Registered: February 2012
Junior Member
now I am going to create a java file and store the modifications back into that file, I used ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager() to get the buffer manager, but when I executed it, I got an ExceptionInInitializerError, could you tell me how to solve it?
Re: How to manipulate the AST? [message #811913 is a reply to message #811843] Sat, 03 March 2012 00:47 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier Thomann
Messages: 518
Registered: July 2009
Senior Member
It would help to get a stack trace for the ExceptionInInitializerError.
--
Olivier
Re: How to manipulate the AST? [message #813937 is a reply to message #798475] Mon, 05 March 2012 21:36 Go to previous messageGo to next message
b x is currently offline b x
Messages: 16
Registered: February 2012
Junior Member
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:399)
at org.eclipse.core.filebuffers.FileBuffers.<clinit>(FileBuffers.java:52)
... 1 more
how to solve the exception here?
Re: How to manipulate the AST? [message #814334 is a reply to message #813937] Tue, 06 March 2012 10:21 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam Kandula
Messages: 444
Registered: July 2009
Senior Member
As from the error, the workspace seems to be closed. What is your application - Is it a normal Java application or an Eclipse plugin? May be http://www.eclipsezone.com/eclipse/forums/t74795.html could help.
Re: How to manipulate the AST? [message #814473 is a reply to message #814334] Tue, 06 March 2012 13:48 Go to previous messageGo to next message
Harutyun Arzumanian is currently offline Harutyun Arzumanian
Messages: 35
Registered: February 2012
Member
If it's a plugin, then you should code it like a plugin and not through a main method java legacy, you need to have a file in your root: plugin.xml which will hold your plugin configuration. your action class must implement
IWorkbenchWindowActionDelegate
classes and your plugin must be run against an active eclipse workspace.
Re: How to manipulate the AST? [message #855126 is a reply to message #814473] Tue, 24 April 2012 14:45 Go to previous message
ouhrani ouahiba is currently offline ouhrani ouahiba
Messages: 1
Registered: April 2012
Junior Member
No Message Body

[Updated on: Tue, 24 April 2012 14:46]

Report message to a moderator

Previous Topic:maven-antrun-plugin
Next Topic:java files in src/main/resources without m2e plugin
Goto Forum:
  


Current Time: Sat Oct 25 05:38:24 GMT 2014

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

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