Eclipse:列出所有类的方法和变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/749746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse : list methods and variables of all classes
提问by euphoria83
I am starting to use some Java code which was written by someone else. I have to understand, change and test it. The author is not available now. The package has some 50 files (and so classes) of different sizes. It would be great if I could just see/print out the names of the methods (public and private) and the public variables (like they are visible in the "outline window" in Eclipse). It would really help in understanding the code since I can just look at this and understand the general purpose of each class.
我开始使用一些由其他人编写的 Java 代码。我必须理解、改变和测试它。作者现在不在。该包有大约 50 个不同大小的文件(以及类)。如果我能看到/打印出方法(公共和私有)和公共变量的名称(就像它们在 Eclipse 的“大纲窗口”中可见),那就太好了。这对理解代码真的很有帮助,因为我可以看看这个并理解每个类的一般目的。
Can I do it in Eclipse other than by generating Javadoc, since Javadoc really creates too much details ? Is there a Eclipse plugin for this ? Or any other tool ?
除了生成 Javadoc 之外,我是否可以在 Eclipse 中执行此操作,因为 Javadoc 确实创建了太多细节?是否有用于此的 Eclipse 插件?或任何其他工具?
Example:
例子:
For a Class file which represents a student, I could just get :
对于代表学生的 Class 文件,我可以得到:
String name
int[] marks
int year
int idNumber
Student()
printName()
printMarks()
setName(String name)
...
...
采纳答案by Nathan Feger
javap might give you what you want too:
javap 也可能给你你想要的东西:
http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javap.html
http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javap.html
回答by Peter
In Package Explorer, right click on the package in question, select Open Type Hierarchy(Shortcut F4) gives a nice view of the hierarchy of objects in that package, selecting a class in that view will give you the class details. Not exactly what you're asking for but it'll help in understanding the package that you're changing.
在Package Explorer 中,右键单击有问题的包,选择Open Type Hierarchy(快捷键 F4)可以很好地查看该包中的对象层次结构,在该视图中选择一个类将为您提供类的详细信息。不完全是您所要求的,但它有助于了解您正在更改的包。
回答by willcodejavaforfood
Nathan Feger's answer seems to be spot on. I made a plugin not long ago that tries to analyze the relationship between member variables/methods and might bring another perspective on things. Variable Usage Plugin
内森·费格 (Nathan Feger) 的回答似乎恰到好处。前不久我做了一个插件,试图分析成员变量/方法之间的关系,可能会给事物带来另一个视角。 变量用法插件
回答by Peter Lawrey
You could create a Javadoc for the code and look at the index which shows the public classes/methods.
您可以为代码创建一个 Javadoc 并查看显示公共类/方法的索引。
回答by Juri
Often generating a Javadoc out of the source code might also help you in navigating through the source code and getting a better understanding. You can do this through "Project/Generate Javadoc" menu.
通常从源代码生成 Javadoc 也可能有助于您浏览源代码并获得更好的理解。您可以通过“项目/生成 Javadoc”菜单执行此操作。
I have some doubts on whether there is a tool which does exactly what you want. Maybe you could achieve this by writing your own small tool that recursively walks over the code files and through Reflection prints out these infos.
我怀疑是否有一种工具可以完全满足您的需求。也许您可以通过编写自己的小工具来实现这一点,该工具递归地遍历代码文件并通过反射打印出这些信息。
Other tools that might help you in understanding the source code are Metrics plugins. There exists onefor Eclipse.
其他可能帮助您理解源代码的工具是 Metrics 插件。Eclipse存在一个。
回答by duffymo
I'm an IntelliJ user, so I can't help with an Eclipse plug-in, but I'd wonder if importing this into a UML tool like JUDEmight be more helpful. It'll show you the methods, the attributes, and the relationships between objects. Personally, I think pictures are worth a thousand words, but that's just me.
我是 IntelliJ 用户,所以我对 Eclipse 插件无能为力,但我想知道将它导入像JUDE这样的 UML 工具是否可能更有帮助。它将向您展示对象之间的方法、属性和关系。就个人而言,我认为图片值一千字,但这只是我。