I am using Eclipse's AST Parser to parse a standalone Java files. This is my below overridden code to get the CompilationUnit (ie Java file) details:
@Override
public boolean visit(CompilationUnit node) {
System.out.println("Compilation unit: " + node.getPackage().getName());
System.out.println("Imports: " + node.imports());
System.out.println("Class Name: " + ??); //How to get this?
return super.visit(node);
}
As you can see from above code, I am able to get package name, imports etc from CompilationUnit. But the main problem I am facing is, I am not able to get name of the class. I tried printing node.toString() it prints entire source code, I tried with node.getClass(); but it returns me name as CompilationUnit. What I want is name of the class of the file which I am parsing. Is there any in-build methods using I can get this info?