I'm currently trying to implement a Eclipse plugin to calculate some OO metrics for Java application, as DIT (Depth of Inheritance Tree). However, i'm not being able to retrieve informations about a Class inheritance tree (distance between the class until Object). Assuming that a class is a CompilationUnit, I'm trying to getting into the class through the TypeDeclaration to compare if the class, for example, Dog (extends Animal) is a instance of Object. If not, it is done a recursive call to the visit method passing the Animal class as parameter, until the class is Object.
EDIT I managed to recover the superclass using typeDec.getSuperClassType()
, however I need to get the TypeDeclaration of this superclass to call the visit method recursively, passing this TypeDeclaration as parameter.
This is the idea of my code:
public class ClassVisitor extends ASTVisitor {
depthOfInheritanceTreeIndex = 1;
public boolean visit(CompilationUnit unit) {
for (Object type :unit.types()){
TypeDeclaration typeDec = (TypeDeclaration) type;
Type superClassType = typeDec.getSuperClassType();
TypeDeclaration superClazz;
if (superClassType.equals(Object.class.getSimpleName())){
return continue;
}else{
depthOfInheritanceTreeIndex++;
superClazz = (TypeDeclaration) superClassType.getParent();
return super.visit(superClazz);
}
}
return false;
}
}
Do you guys has any ideas in what i'm doing wrong or how to do that? Any help will be apprecieated!