Reputation: 53
I need to retrieve SuperClass name of a java file (which extends a class, i need that class name). In order to do this, I began to use ASTParser but I'm newbie so any example or illustration can be helpful. I use ASTView to comprehend which ways that AST keeps a java file structure but I'm stuck while trying visit(), endvisit() functions. I could not find any detailed example.
Thanks in advance...
Upvotes: 1
Views: 901
Reputation: 8260
You didn't say much of how far you had got already.
In the visitor, override visit(TypeDeclaration node)
and then, on the node, call getSuperclassType()
.
If you return true
the parsing will continue inside the type declaration, otherwise it stops.
Upvotes: 2
Reputation: 2223
This code will work..
IType type = ...;
ITypeHierarchy a = type.newSupertypeHierarchy(new NullProgressMonitor());
IType[] superTypes = a.getAllSupertypes(type);
if(superTypes.length == 1 && superTypes[0].getKey().equals("Ljava/lang/Object;")){
this.isSuperClassObject = true;
}
else{
this.isSuperClassObject = false;
}
Upvotes: 0
Reputation:
Could you use the getSuperClass() method of the Class class in your code instead?
Upvotes: 1