java - Using the Eclipse AST -
I recently came across a need to modify some Java code (adding methods, changing signatures of certain areas and methods Removal) and I think that all this may be accomplished, though the use of AST using Eclipse SDK.
I know from some research that how a parse is done in a source file, but I do not know what I mentioned above. Does anyone know a good tutorial or can someone give me a brief explanation about how to solve this issue?
Thank you very much,
Extreme Coder
Edit:
I now have JavaScript I have started to see more and I think it can be very easy to use, but I do not know the existing documents can be loaded in it.
<
I will not post the whole source code here because it is quite long but I I will start.
Also the document you need here:
Document document = new document ("import java.util.List; \ n \ n class X \ n {\ n \ n \ tpublic void deleteme ( ) \ N \ t {\ n \ t} \ n \ n} \ n "); ASPPers parser = ASTPerser.NEPper (AST.JLS3); parser.setSource (document.get) toCharArray ().); CompilationUnit CU = (Compilation Unit) Parser.Socket AATT (null); cu.recordModifications ();
This will create a compilation unit from source code for you that you pass.
Now this is a simple task Land that all methods in print does went to pass by the definition:
List & lt; AbstractTypeDeclaration & gt; Type = cu.types (); For (Absertypedclay type: type) {if (type.getNodeType () == ASTNode.tep_declaration) {// Class deaf list & lt; Body dereliction & gt; Bodies = type Repetition (); (Body declaration body: bodies) {if (body.getNodeType () == ASTNode.MATH_declaration) {method lecture method = (method lecture) body; System.out.println ("Method Declaration:"); System.out.println ("name:" + method.getName (). GetFullyQualifiedName ()); System.out.println ("Modifier:" + method.getModifiers ()); System.out.println ("Return Type:" + method.getReturnType2 (). ToString ()); }}}}
This should get you all started.
(A lot in my case) takes some time to get used to this. But this works and the best way I can get my hands on is
good luck;)
ExtremeCoder
Edit .:
Before I forget, these imports that I used to get this work done (I took quite a bit of time to organize these ):
org.eclipse.jdt.core_xxxx.jar org.eclipse.core.resources_xxxx.jar org.eclipse.core.jobs_xxxx.jar org.eclipse.core.runtime_xxxx.jar org. Eclipse.core.contenttype_xxxx.jar org.eclipse.equinox .common_xxxx.jar org.eclipse.equinox.preferences_xxxx.jar org.eclipse.osgi_xxxx.jar org.eclipse.text_xxxx.jar
Where xxxx represents a version number.
Comments
Post a Comment