有什么方法可以在 Java/Eclipse 中对方法进行分组吗?
我希望能够将类似的方法分组并让它们出现在 Eclipse 的大纲视图中。这使得浏览大量代码变得更容易,并且更容易找到所需的方法。在 Objective-C 中,有一个可以设置的 pragma mark 命令。
java/eclipse 有类似的东西吗?
I would like to be able to group similar methods and have them appear in my Outline view in Eclipse. This makes navigating large swaths of code a little easier on the eye, and easier to find methods you need. In Objective-C there was a pragma mark command that you could set.
Anything like that for java/eclipse?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我使用 Coffee Bytes 插件 进行代码折叠,专门将其配置为折叠具有以下功能的代码:开始和结束标签。
虽然该插件无法从Google 代码页面页面上下载,但它已针对 Eclipse 3.5 重新编译并在其他地方提供;该版本似乎也适用于 Eclipse 3.6 和 3.7。它也可以在 Yoxos 市场 中找到。
我使用以下符号对属性的 getter 和 setter 以及属性的声明进行分组,尽管可以扩展相同的符号供您使用。
需要通过在 Windows > 可用的代码折叠部分中设置适当的首选项来完成相同的配置。首选项>爪哇>编辑>折叠。请记住选择 Coffee Bytes Java Folding,并启用对用户定义区域的支持。
尽管对分组/折叠的支持仅限于编辑器,但折叠内方法的自然顺序可以保留在大纲视图中。恐怕我不知道该插件之外的任何分组功能。
I use the Coffee Bytes plugin for code folding, specifically configuring it for folding code that has start and end tags.
Although the plugin is not downloadable off the page listed on the Google Code page, it has been recompiled against Eclipse 3.5 and made available elsewhere; the version appears to work against Eclipse 3.6 and 3.7 as well. It is also available in the Yoxos marketplace.
I use the following notation to group getters and setters of properties along with declaration of the property, although the same notation could be extended for your use.
Configuration of the same needs to be done by setting appropriate preference in the code folding section available via Windows > Preferences > Java > Editor > Folding. Remember to choose Coffee Bytes Java Folding, and enable support for User Defined Regions.
Although the support for grouping/folding is restricted to the editor, the natural order of the methods within the fold can be retain in the outline view. I'm afraid that I'm unaware of any grouping capabilities beyond this plug-in.
我真的很怀念 Smalltalk 的时代。
表示这些类别的最佳方法是向代码本身添加注释。然后,您需要创建一个使用这些注释的专用大纲视图。听起来像是一个不错的 Google Summer of Code 项目。
I really miss it from the days of Smalltalk.
The best way to denote these categories would be adding annotations to the code itself. You would then need to create a specialized outline view which uses these annotations. Sounds like a good Google Summer of Code project.
为了帮助 Vineet Reynolds 回答,我还想提供以下信息:
这来自:http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
To help with Vineet Reynolds answer, I would also like to offer this:
This is from: http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
至于你原来的问题,我相信这对于 Java/Eclipse 是不可能的。
但是,如果您有一组相似的方法,需要与同一类中的另一组方法区分开来,为什么不使用这组相似的方法创建一个新类呢?
As to your original question, I believe that is not possible with Java/Eclipse.
However, if you have a group of similar methods that you need to distinguish from another group of methods within the same class, why not create a new class with the group of similar methods?
如果您的意思是按名称分组,请单击“大纲视图”上的“排序”按钮。
而且,视图中还有一些过滤器来‘隐藏静态’、‘隐藏非公开’……
If you mean group by name, click the button 'Sort' on 'Outline view'.
Moreover, there are some filters in the view to 'hide static', 'hide non-public'...
我刚刚遇到这个问题,我想我应该指出,虽然这并不完全符合您的原始声明,但您可以在每个方法的文档块中添加一个
@category
指令,然后仅过滤方法类别你想看看。我用它来只查看我在任何时候感兴趣的那些方法组。I just ran across this and thought I should point out that while this doesn't exactly meet your original statement you can add a
@category
directive in the documentation block of each method then filter for just the method categories you would like to see. I have used this to only look at those groups of methods I am interested in at any one time.