Refactoring crazy inheritance hierarchies of value objects - How to get a list of all fields and types?

StackOverflow https://stackoverflow.com/questions/4349606

문제

So basically, I need to manually adjust an inheritance hierarchy. I'd like for the classes to be perfect, no extra fields, and they're just DTO's. However, it's really easy to get lost and add duplicate fields, and it's really hard to see if what I'm looking for is already there. Something I'd really love to have is a way to list all the fields within a class, including its inherited fields (private too). Like a flattened field-only view with no getters and setters cluttering everything up.

I've found a way to show it in netbeans with right-click/File members, but I can't copy-paste and save it in a text file or anything.

Basically just these columns:

Name     Type            Superclass
id       int  
theDate  java.util.Date  com.something.AbstractDTO
...

Anyone know how to do it, or a better way to do what I'm trying to do?

도움이 되었습니까?

해결책

If no pre-existing tool can be found it shouldn't be hard to write something that uses reflection to extract this information from your DTO classes. You'd need to recompile and re-run the program for updates, but that's better than nothing.

다른 팁

You can use Eclipse's "Hierarchy View". When you click on a class you get its members. Clicking the "Show all inherited members" icon gives you a view sorted by member type (static fields, static methods, instance fields, etc.). You can select the instance fields in the usual way, right click, and "copy qualified name". You'll get something like this, which includes where the member was originally defined.

nz.ac.vuw.ecs.kcassell.cluster.MatrixBasedAgglomerativeClusterer.distanceMatrix
nz.ac.vuw.ecs.kcassell.cluster.MatrixBasedAgglomerativeClusterer.originalMatrix
nz.ac.vuw.ecs.kcassell.cluster.DisjointClusterer.originalMatrix
nz.ac.vuw.ecs.kcassell.cluster.DisjointClusterer.originalSeed1
nz.ac.vuw.ecs.kcassell.cluster.DisjointClusterer.originalSeed2
nz.ac.vuw.ecs.kcassell.cluster.MatrixBasedAgglomerativeClusterer.previousIteration
...

In this example, "originalMatrix" is multiply defined. (It's even easier to see in the hierarchy view.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top