如何使用ASTParser从java文件中检索SuperClass名称? [英] How Can a SuperClass name be retrieved from a java file using ASTParser?

查看:92
本文介绍了如何使用ASTParser从java文件中检索SuperClass名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检索一个java文件的SuperClass名称(扩展一个类,我需要该类名)。为了做到这一点,我开始使用ASTParser,但我是新手,所以任何的例子或说明可以是有帮助的。我使用ASTView来理解AST保留java文件结构的方式,但是在尝试visit(),endvisit()函数时我被卡住了。我找不到任何详细的例子。



提前感谢...

解决方案


在访问者中,覆盖访问(TypeDeclaration node)然后在节点上调用 getSuperclassType()



如果返回 true 解析将继续在类型声明内,否则停止。


I need to retrieve SuperClass name of a java file (which extends a class, i need that class name). In order to do this, I began to use ASTParser but I'm newbie so any example or illustration can be helpful. I use ASTView to comprehend which ways that AST keeps a java file structure but I'm stuck while trying visit(), endvisit() functions. I could not find any detailed example.

Thanks in advance...

解决方案

You didn't say much of how far you had got already.

In the visitor, override visit(TypeDeclaration node) and then, on the node, call getSuperclassType().

If you return true the parsing will continue inside the type declaration, otherwise it stops.

这篇关于如何使用ASTParser从java文件中检索SuperClass名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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