views:

775

answers:

6

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.

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 ?

Example:

For a Class file which represents a student, I could just get :

String name
int[] marks
int year
int idNumber

Student()
printName()
printMarks()
setName(String name)

...

A: 

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 JUDE might 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.

duffymo
i am afraid how i will print the uml for 50 classes on one page, however big.
euphoria83
they shouldn't be on one page. It makes far more sense to do it package by package, as classes are grouped together. if you have a large model, understanding at a glance will be difficult to do no matter if you use UML or simple text.
duffymo
+2  A: 

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.

Peter
+1  A: 

javap might give you what you want too:

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javap.html

Nathan Feger
That seems to be spot on!
willcodejavaforfood
A: 

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

willcodejavaforfood
A: 

You could create a Javadoc for the code and look at the index which shows the public classes/methods.

Peter Lawrey
A: 

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.

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 one for Eclipse.

Juri