I am compiling a project source using AST parser. In what way i can extract class hierarchy infromation, that is whether it is implementing any interface or extends from another class?
You can visit the TypeDeclaration
node and get the type binding from it.
ITypeBinding typeBind = typDec.resolveBinding();
You can then get the super class and implemented interfaces as follows:
public boolean visit(TypeDeclaration typeDeclaration) {
ITypeBinding typeBind = typeDeclaration.resolveBinding();
ITypeBinding superTypeBind = typeBind.getSuperclass();
ITypeBinding[] interfaceBinds = typeBind.getInterfaces();
return true;
}
If you have an IType instance (type), you can get get the class hierarchy in an ITypeHierarchy as follows
ITypeHierarchy typeHierarchie = type.newTypeHierarchy(new NullProgressMonitor());
The ITypeHierarchy has methods to query the implemented interfaces
typeHierarchie.getSuperInterfaces(type);
as well as which classes were extended
typeHierarchie.getSuperclass(type);
typeHierarchie.getAllSuperclasses(type);
来源:https://stackoverflow.com/questions/15800942/extract-interface-that-a-class-implementing-using-ast-parser