简体   繁体   English

Java类解析器

[英]Java class parser

I am parsing all the class files in a jar via Objectweb asm ( http://forge.ow2.org/projects/asm/ ). 我正在通过Objectweb asm( http://forge.ow2.org/projects/asm/ )解析jar中的所有类文件。 The idea is to parse and store (and use for something later) all the public/protected methods and fields in each class file. 这个想法是解析和存储(并在以后使用)某些类文件中所有公共/受保护的方法和字段。 It is working as expected. 它按预期工作。 What I dont get is the list of methods, declared by the interface and those inherited from superclasses and superinterfaces. 我没有得到的是由接口以及从超类和超接口继承的方法声明的方法列表。 Is there a smart parser available that would give me the above list? 是否有可用的智能解析器提供上述列表?

I could load the class file and then use java.lang.Class object to get what I need. 我可以加载类文件,然后使用java.lang.Class对象获取所需的信息。 But loading classes might fail because of dependencies. 但是由于依赖关系,加载类可能会失败。 I would rather parse and get that info. 我宁愿解析并获取该信息。

The data you want is simply not there. 您所需的数据根本就不存在。 Inherited members are implicit: you only have the names of the class and interfaces where they can be looked for, and you need to parse the corresponding class files. 继承的成员是隐式的:您只有可在其中查找它们的类和接口的名称,并且您需要解析相应的类文件。

您可以简单地做到这一点:

Class superclass = aClass.getSuperclass(); aClass.getClass().getInterfaces(); aClass.getClass().getMethods();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM