I will not post all the source code for this problem here because it is quite long, but I will get people to start.
All the documents you will need are here: http://publib.boulder.ibm.com/infocenter/iadthelp/v6r0/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/ eclipse / jdt / core / dom / package-summary.html
Document document = new Document("import java.util.List;\n\nclass X\n{\n\n\tpublic void deleteme()\n\t{\n\t}\n\n}\n"); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(document.get().toCharArray()); CompilationUnit cu = (CompilationUnit)parser.createAST(null); cu.recordModifications();
This will create a compiler for you from the source code you are passing.
Now this is a simple function that outputs all the methods inside the class definitions in what you passed:
List<AbstractTypeDeclaration> types = cu.types(); for(AbstractTypeDeclaration type : types) { if(type.getNodeType() == ASTNode.TYPE_DECLARATION) { // Class def found List<BodyDeclaration> bodies = type.bodyDeclarations(); for(BodyDeclaration body : bodies) { if(body.getNodeType() == ASTNode.METHOD_DECLARATION) { MethodDeclaration method = (MethodDeclaration)body; System.out.println("method declaration: "); System.out.println("name: " + method.getName().getFullyQualifiedName()); System.out.println("modifiers: " + method.getModifiers()); System.out.println("return type: " + method.getReturnType2().toString()); } } } }
That should make you all start.
It will take some time to get used to this (a lot in my case). But it works, and this is the best way I could handle it.
Good luck;)
Extremecoder
Edit:
Before I forget, this is the import I used to get this working (I spent quite a bit of time organizing them):
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 the version number.
Extremecoder
source share