Java Eclipse 按字母顺序组织方法

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

Eclipse organize methods in alphabetical order

javaeclipseclassmethodsalphabetical

提问by zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

I have a large class that contains about 30 methods. Is it possible to automatically sort them in alphabetical order in eclipse? I was hoping to do this so they would be easier to find when java browsing or looking at the class outline window.

我有一个包含大约 30 个方法的大类。是否可以在 eclipse 中按字母顺序自动对它们进行排序?我希望这样做,以便在 Java 浏览或查看类大纲窗口时更容易找到它们。

采纳答案by Perception

If you just want to view your class members in sorted order without modifying the code then you can click on the A/Z icon on the outline view, as others have pointed out. Alternatively, you may wish to sort the class members in the code itself, in which case you should right click your source or source file name to get the context sensitive menu, then select Source(Alt-Shift-S), Sort Members.

如果您只想按排序顺序查看您的班级成员而不修改代码,那么您可以单击大纲视图上的 A/Z 图标,正如其他人所指出的那样。或者,您可能希望在代码本身中对类成员进行排序,在这种情况下,您应该右键单击源或源文件名以获取上下文相关菜单,然后选择 Source(Alt-Shift-S), Sort Members。

It will pop up a dialog box allowing you to customize the sort, choose your desired options and click ok.

它将弹出一个对话框,允许您自定义排序,选择所需的选项并单击确定。

回答by Torsten

You can use the alphabetic sort in the overview window for this.

为此,您可以在概览窗口中使用字母排序。

alphabetic sorticon

字母排序图标

回答by jtoberon

Press the Sort button in the Outline view. It has A, Z, and an arrow in it.

在大纲视图中按排序按钮。它有 A、Z 和一个箭头。

I wouldn't modify the Java source if I were you. If you're using an IDE such as Eclipse, then this adds no benefit, and there are a few costs, including:

如果我是你,我不会修改 Java 源代码。如果您使用的是 Eclipse 等 IDE,那么这不会增加任何好处,并且会产生一些成本,包括:

  1. If the code already is checked in to source control, then resorting it can break the history
  2. I've never heard of a group with a coding convention of sorting methods alphabetically
  1. 如果代码已经被签入到源代码管理,那么重新使用它可以打破历史
  2. 我从未听说过有按字母顺序排序方法的编码约定的组

回答by Pieter De Bie

You can actually sort members of your class in your code with eclipse, in my opinion this improves readability but should be used with caution.

实际上,您可以使用 eclipse 对代码中的类成员进行排序,我认为这可以提高可读性,但应谨慎使用。

select the class, Source > Sort Members

选择类,源 > 排序成员

Thanks to marcggs' answer.

感谢marcggs 的回答