i want to parse a project in which some classes have inner classes.how can i extract inner classes name other information using eclips JDT?
You can traverse through the Compilation
unit of the Java class and visit the TypeDeclaration
AST node. The below code can then be used to check if it is not a top-level class, i.e an inner class.
public boolean visit(TypeDeclaration typeDeclarationStatement) {
if (!typeDeclarationStatement.isPackageMemberTypeDeclaration()) {
System.out.println(typeDeclarationStatement.getName());
// Get more details from the type declaration.
}
return true;
}
For getting anonymous inner classes use the below code too:
public boolean visit(AnonymousClassDeclaration anonyomousClassDeclaration) {
System.out.println(anonyomousClassDeclaration.toString());
return true;
}
Details on Class traversal using JDT can be found from below link: