重构值对象的疯狂继承层次结构 - 如何获取所有字段和类型的列表?

发布于 2024-10-06 02:53:33 字数 437 浏览 8 评论 0原文

所以基本上,我需要手动调整继承层次结构。我希望这些类是完美的,没有额外的字段,而且它们只是 DTO。然而,很容易迷失方向并添加重复字段,而且很难看出我正在寻找的内容是否已经存在。我真正想要的是一种列出类中所有字段的方法,包括其继承的字段(也是私有的)。就像一个扁平化的纯场视图,没有 getter 和 setter 使一切变得混乱。

我找到了一种方法,可以通过右键单击/文件成员在 netbeans 中显示它,但我无法复制粘贴并将其保存在文本文件或其他任何内容中。

基本上只有这些专栏:

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

有人知道如何做到这一点,或者有更好的方法来做我想做的事情吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

变身佩奇 2024-10-13 02:53:33

如果找不到预先存在的工具,那么编写使用反射从 DTO 类中提取此信息的东西应该不难。您需要重新编译并重新运行程序以进行更新,但这总比没有好。

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.

御弟哥哥 2024-10-13 02:53:33

您可以使用 Eclipse 的“层次结构视图”。当您单击一个类时,您会看到它的成员。单击“显示所有继承的成员”图标将显示按成员类型(静态字段、静态方法、实例字段等)排序的视图。您可以按照通常的方式选择实例字段,右键单击,然后“复制限定名称”。您将得到类似这样的信息,其中包括该成员最初定义的位置。

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

在此示例中,“originalMatrix”被多重定义。 (在层次视图中更容易看到。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文