如何在 NetBeans 或其他 Java IDE 中按名称对类成员进行排序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/217257/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:27:36  来源:igfitidea点击:

How can I sort class members by name in NetBeans, or another Java IDE?

javasortingnetbeansmethods

提问by Lipis

I want to sort members by name in the source code. Is there any easy way to do it?

我想在源代码中按名称对成员进行排序。有什么简单的方法可以做到吗?

I'm using NetBeans, but if there is another editor that can do that, just tell me the name of it.

我正在使用 NetBeans,但如果有其他编辑器可以做到这一点,请告诉我它的名称。

回答by Johnny Baloney

In Netbeans 8.0.1:

在 Netbeans 8.0.1 中:

Tools -> Options -> Editor -> Formatting -> Category: Ordering

Netbeans member sorting

Netbeans 会员排序

Then:

然后:

Source -> Organize Members

Netbeans member sorting

Netbeans 会员排序

回答by Paul Croarkin

Eclipse can do it.

Eclipse 可以做到。

回答by Gili

This is implemented in Netbeans 7.3: http://netbeans.org/bugzilla/show_bug.cgi?id=212528

这是在 Netbeans 7.3 中实现的:http: //netbeans.org/bugzilla/show_bug.cgi?id= 212528

回答by Martin

As @PaulCroarkin said - use eclipse, Or you can use Jalopyas part of your build which will do all manner of magical formatting to your source files in the process (whether this is a good thing or not is open to debate)

正如@PaulCroarkin 所说 - 使用 eclipse,或者您可以使用Jalopy作为构建的一部分,它将在此过程中对您的源文件进行各种神奇的格式化(这是否是一件好事还有待商榷

回答by Martin

Netbeans lets you sort the methods in the Navigator. Personally, I never saw the point in sorting methods in the code. When possible I like to keep methods together that work together. For example, the getter() and setter(). Incremental search or being able to control-click on a method to navigate to the declaration is much more useful, IMHO.

Netbeans 允许您对导航器中的方法进行排序。就我个人而言,我从未在代码中看到排序方法的意义。如果可能,我喜欢将可以协同工作的方法放在一起。例如,getter() 和 setter()。恕我直言,增量搜索或能够控制单击方法以导航到声明更有用。

回答by James Schek

As of 6.0/6.1, this feature isn't available in the built-in tools. The "Navigator" view is intended to give you an ordered index of your members. To see the Navigator, go to Window->Navigating->Navigator or hit Control-F7.

自 6.0/6.1 起,此功能在内置工具中不可用。“导航器”视图旨在为您提供成员的有序索引。要查看导航器,请转到 Window->Navigating->Navigator 或按 Control-F7。

Consider submitting a feature enhancement to Netbeans.

考虑向Netbeans提交功能增强

回答by Ted Feng

For C/C++ mode, right click on the method name inside the Navigator window, then there's choice of "Sort by Name" or "Sort by Source", choose the one you like :)

对于 C/C++ 模式,在导航器窗口中的方法名称上单击鼠标右键,然后可以选择“按名称排序”或“按源排序”,选择您喜欢的一个:)

回答by Greg

Here is the easy way to do it in NetBeans:

这是在 NetBeans 中执行此操作的简单方法:

  1. Go to the Tools tab and chose Options. The option Window should appear.
  2. Click on Editor and chose the Formatting Tab.
  3. Select Ordering for Category. Ordering is the last element from the drop down Category list.
  4. Uncheck the Sort Members By Visibility field. At this point only the "Sort Members in Groups Alphabetically" should be checked.
  5. Click Apply and exit the Option window. Now you globally set to sort members alphabetically.
  6. Open or Select the source file you want to sort the members.
  7. Click the Source Tab (upper right corner) and chose Organize Members.
  1. 转到“工具”选项卡并选择“选项”。应出现选项窗口。
  2. 单击编辑器并选择格式选项卡。
  3. 为类别选择订购。排序是下拉类别列表中的最后一个元素。
  4. 取消选中“按可见性排序成员”字段。此时只应检查“按字母顺序排列组中的成员”。
  5. 单击应用并退出选项窗口。现在您全局设置为按字母顺序对成员进行排序。
  6. 打开或选择要对成员进行排序的源文件。
  7. 单击“源”选项卡(右上角)并选择“组织成员”。

And that is it. Your source file should have the members sorted alphabetically.

就是这样。您的源文件应按字母顺序对成员进行排序。