extract interface that a class implementing using AST parser

China☆狼群 提交于 2019-12-06 09:20:28

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!