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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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;
}
回答2:
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);