tag:blogger.com,1999:blog-1616206987206690523.post448303905791339334..comments2023-04-03T03:55:38.181-07:00Comments on The Coder Lounge: Abstract Syntax TreeDeepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1616206987206690523.post-62230907574078592592011-08-10T22:00:29.616-07:002011-08-10T22:00:29.616-07:00Alright.thanks deepak. I have come across another ...Alright.thanks deepak. I have come across another issue. I want to insert code inside a method's body using JDT. <br />Ex: <br />String code= " a = a -1;<br /> val = false;<br /> return a; " <br /><br />Now , above code string, I want to insert into a method's body.<br />for ex: Method b4 inserting is <br /> <br /> public int decrement(int a){<br /><br /> }<br /><br />and method after inserting should be:<br /> <br /> public int decrement(int a){<br /> a = a -1;<br /> val = false;<br /> return a; " <br /> }<br />----------------<br />How this can be done? I am able to find out a particular method, code string is also ready. <br />Is there any way I can create block of statements and directly add to a method body? <br />or do I have to create individually 3 expressions (for above case) and then add it individually to the method? <br /><br />Kindly help<br />Thanks<br /><br />regards<br />sagarsagarhttps://www.blogger.com/profile/05219870982329548619noreply@blogger.comtag:blogger.com,1999:blog-1616206987206690523.post-87935253341070854862011-08-07T07:45:09.178-07:002011-08-07T07:45:09.178-07:00Yup, all JDT apis can be used easily from a plug-i...Yup, all JDT apis can be used easily from a plug-in. If you have a simple java project, you can use some apis but not all and have to jump through more hoops.<br /><br />While the article does not say that use a plug-in, the example project is a plug-in.Deepakhttps://www.blogger.com/profile/12947774811212314687noreply@blogger.comtag:blogger.com,1999:blog-1616206987206690523.post-5105406322419843722011-08-07T07:32:11.094-07:002011-08-07T07:32:11.094-07:00Hi deepak, In continuation of the previous problem...Hi deepak, In continuation of the previous problem, I have got a link : <br />http://www.programcreek.com/2011/05/java-lang-illegalstateexception-workspace-is-closed/#comment-1939<br /><br />It says that: " In brief, this is caused by simply adding dependent jar files to regular java project.<br /><br />To use JDT, you need to have the program running as a plug-in (or at least, an OSGi-enabled application) rather than using it as a jar. "<br /><br />So, doest it mean I have to create a plug in project , instead of simple java project for using FileBuffers.getTextFileBufferManager() method? But article doesnt point out this issue <br /><br />waiting for reply. <br />Thankssagarhttps://www.blogger.com/profile/05219870982329548619noreply@blogger.comtag:blogger.com,1999:blog-1616206987206690523.post-14363187107972034652011-08-06T20:24:48.132-07:002011-08-06T20:24:48.132-07:00Hey Hi deepak.
Thanks for reply. as per the artic...Hey Hi deepak. <br />Thanks for reply. as per the article, I can create abstract syntax tree (ast) for a java source file, and modify ast. But, the reflecting the changes back to the original source code file is not working. <br />Kindly refer "Write it down" section of article . It says to declare: <br />ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();<br /> // get the buffer manager<br /><br />But I am getting following Exception at this line.<br /><br />Exception in thread "main" java.lang.ExceptionInInitializerError<br /> at ASTModifier.main(ASTModifier.java:205)<br />Caused by: java.lang.IllegalStateException: Workspace is closed.<br /> at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:340)<br /> at org.eclipse.core.filebuffers.FileBuffers.(FileBuffers.java:52)<br /> ... 1 more<br /><br /><br />What can be this error? everything else works fine. But for making the changes of ast reflected back to the original source file is not working? <br />Kindly help<br />thanks<br /><br />regards<br />sagarsagarhttps://www.blogger.com/profile/05219870982329548619noreply@blogger.comtag:blogger.com,1999:blog-1616206987206690523.post-65309243235636934312011-07-24T19:58:58.771-07:002011-07-24T19:58:58.771-07:00@Sagar: The article gives the complete details, ar...@Sagar: The article gives the complete details, are you stuck at a particular point ?Deepakhttps://www.blogger.com/profile/12947774811212314687noreply@blogger.comtag:blogger.com,1999:blog-1616206987206690523.post-78735194288115893342011-07-24T18:52:25.890-07:002011-07-24T18:52:25.890-07:00Hi Deepak,
How can i change an Abstract syntax tr...Hi Deepak, <br />How can i change an Abstract syntax tree of simple java source code and reprint the modified java source code.? Kindly help me.sagarhttps://www.blogger.com/profile/05219870982329548619noreply@blogger.com