有什么方法可以在 Java/Eclipse 中对方法进行分组吗?

发布于 2024-09-16 05:08:56 字数 142 浏览 6 评论 0原文

我希望能够将类似的方法分组并让它们出现在 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 技术交流群。

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

发布评论

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

评论(6

饭团 2024-09-23 05:08:56

我使用 Coffee Bytes 插件 进行代码折叠,专门将其配置为折叠具有以下功能的代码:开始和结束标签。

虽然该插件无法从Google 代码页面页面上下载,但它已针对 Eclipse 3.5 重新编译并在其他地方提供;该版本似乎也适用于 Eclipse 3.6 和 3.7。它也可以在 Yoxos 市场 中找到。

我使用以下符号对属性的 getter 和 setter 以及属性的声明进行分组,尽管可以扩展相同的符号供您使用。

// {{ Id
private String id;

public String getId() {
    return id;
}

public void setId(final String id) {
    this.id = id;
}
// }}

需要通过在 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.

// {{ Id
private String id;

public String getId() {
    return id;
}

public void setId(final String id) {
    this.id = id;
}
// }}

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.

一身骄傲 2024-09-23 05:08:56

我真的很怀念 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.

不语却知心 2024-09-23 05:08:56

为了帮助 Vineet Reynolds 回答,我还想提供以下信息:

用法:

在“用户定义区域”选项卡中使用,例如:

开始标识符:区域    
结束标识符:endregion

在代码中:

//region SomeName
你的代码
//endregion 某些名称

安装说明:

  1. 安装插件
  2. 解压下载的文件 eclipse-folding-plugin.tar.gz
  3. 复制以下内容:
  4. 功能文件夹=> Eclipse 功能文件夹
  5. 插件文件夹=> Eclipse 插件文件夹
  6. 在 Eclipse 中配置插件:
  7. 选择“Windows -> 首选项”
  8. 选择“Java->编辑器->折叠”
  9. 选中“启用折叠”选项
  10. 在“选择要使用的折叠:”选项中选择“Coffee Bytes Java Folding”
  11. 选中“常规折叠设置:”选项中的“用户定义区域”

这来自: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:

USAGE:

in User Defined Regions tab use e.g.:

Start identifier: region    
End identifier: endregion

In code:

//region SomeName
your code
//endregion SomeName

Installation instructions:

  1. Install plugin
  2. Unpack the downloaded file eclipse-folding-plugin.tar.gz
  3. Copy the contents of the:
  4. features folder => eclipse features folder
  5. plugins folder => eclipse plugins folder
  6. Configure plugin in Eclipse:
  7. Select "Windows->Preferences"
  8. Select "Java->Editor->Folding"
  9. Check the "Enable folding" option
  10. Select "Coffee Bytes Java Folding" in the "Select folding to use:" option
  11. Check "User Defined Regions" in the "General Fold Setting:" option

This is from: http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html

夏日落 2024-09-23 05:08:56

至于你原来的问题,我相信这对于 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?

简单 2024-09-23 05:08:56

如果您的意思是按名称分组,请单击“大纲视图”上的“排序”按钮。

而且,视图中还有一些过滤器来‘隐藏静态’、‘隐藏非公开’……

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

匿名的好友 2024-09-23 05:08:56

我刚刚遇到这个问题,我想我应该指出,虽然这并不完全符合您的原始声明,但您可以在每个方法的文档块中添加一个 @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.

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