提取类使用AST解析器实现的接口 [英] extract interface that a class implementing using AST parser

查看:241
本文介绍了提取类使用AST解析器实现的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AST解析器编译项目源。我可以通过什么方式提取类层次结构信息,即它是实现任何接口还是从另一个类扩展?

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?

推荐答案

您可以访问 TypeDeclaration 节点并从中获取类型绑定。

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;
}

这篇关于提取类使用AST解析器实现的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆