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

爱⌒轻易说出口 提交于 2021-02-06 15:20:55

问题


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.


回答1:


In Netbeans 8.0.1:

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

Netbeans member sorting

Then:

Source -> Organize Members

Netbeans member sorting




回答2:


Eclipse can do it.




回答3:


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




回答4:


As @PaulCroarkin said - use eclipse, Or you can use Jalopy as 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)




回答5:


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.




回答6:


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.

Consider submitting a feature enhancement to Netbeans.




回答7:


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




回答8:


Here is the easy way to do it in 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.

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



来源:https://stackoverflow.com/questions/217257/how-can-i-sort-class-members-by-name-in-netbeans-or-another-java-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!