我希望能够将相似的方法分组,并使它们在Eclipse的大纲视图中显示。这样可以更轻松地浏览大量的代码,更容易找到需要的方法。在Objective-C中有一个pragma mark命令,你可以设置。
Java/Eclipse有类似的功能吗?
// {{ Id
private String id;
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
// }}
需要配置相同的偏好设置,可以通过Windows > Preferences > Java > Editor > Folding中可用的代码折叠部分进行。记得选择Coffee Bytes Java Folding,并启用对用户定义区域的支持。
尽管分组/折叠的支持仅限于编辑器,但折叠内方法的自然顺序可以保留在大纲视图中。恐怕我不知道除了这个插件之外还有其他的分组能力。
我非常怀念Smalltalk时代的技术。
最好的方式是在代码本身添加注释来表示这些类别。然后,您需要创建一个使用这些注释的专门的大纲视图。听起来像是一个不错的Google Summer of Code项目。
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:
- Install plugin
- Unpack the downloaded file eclipse-folding-plugin.tar.gz
- Copy the contents of the:
- features folder => eclipse features folder
- plugins folder => eclipse plugins folder
- Configure plugin in Eclipse:
- Select "Windows->Preferences"
- Select "Java->Editor->Folding"
- Check the "Enable folding" option
- Select "Coffee Bytes Java Folding" in the "Select folding to use:" option
- Check "User Defined Regions" in the "General Fold Setting:" option
该链接来源:http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
关于您最初的问题,我认为在Java/Eclipse中不可能实现。
然而,如果您有一组相似的方法需要与同一类中的另一组方法区分开来,为什么不创建一个新类来包含这组相似的方法呢?
如果您是指按名称分组,请在“大纲视图”上单击“排序”按钮。
此外,视图中还有一些筛选器,可用于“隐藏静态内容”、“隐藏非公共内容”...
@category
指令,然后过滤只显示你想要查看的方法类别。我曾经使用过这种方法,只查看我感兴趣的那些方法组。