我想在Eclipse中使用区域进行代码折叠;在Java中怎么做到呢?

c#中的一个例子:

#region name
//code
#endregion

当前回答

自定义代码折叠功能可以使用CoffeeScript代码折叠插件添加到eclipse。

这已被测试用于月食Luna和Juno。以下是步骤

Download the plugin from here Extract the contents of archive Copy paste the contents of plugin and features folder to the same named folder inside eclipse installation directory Restart the eclipse Navigate Window >Preferences >Java >Editor >Folding >Select folding to use: Coffee Bytes Java >General tab >Tick checkboxes in front of User Defined Fold Create new region as shown: Restart the Eclipse. Try out if folding works with comments prefixed with specified starting and ending identifiers

你也可以在这个博客上下载存档和查找步骤。

其他回答

最好的方法

//region DESCRIPTION_REGION
int x = 22;
// Comments
String s = "SomeString";
//endregion;

提示:将";"放在"endregion"的末尾

VSCODE

我使用vscode for java,它的工作原理与visual studio几乎相同,除了你使用注释:

//#region name

//code

//#endregion

在Visual Studio Code中,尝试这样做:

//region Variables
// Code you need
//endregion

自定义代码折叠功能可以使用CoffeeScript代码折叠插件添加到eclipse。

这已被测试用于月食Luna和Juno。以下是步骤

Download the plugin from here Extract the contents of archive Copy paste the contents of plugin and features folder to the same named folder inside eclipse installation directory Restart the eclipse Navigate Window >Preferences >Java >Editor >Folding >Select folding to use: Coffee Bytes Java >General tab >Tick checkboxes in front of User Defined Fold Create new region as shown: Restart the Eclipse. Try out if folding works with comments prefixed with specified starting and ending identifiers

你也可以在这个博客上下载存档和查找步骤。

对于Eclipse IDE, Coffee-Bytes插件可以做到这一点,下载链接在这里。

编辑:

关于Coffee-Bytes的最新信息在这里。