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

c#中的一个例子:

#region name
//code
#endregion

当前回答

AndroidStudio地区 创建区域

首先,找到(并定义捷径如果需要)环绕菜单

然后,选择代码,按Ctrl+Alt+分号-> choose region..endregion…

前往地区

首先,找到自定义折叠捷径 其次,在代码的任何地方,按Ctrl+Alt+句号(键盘上的'>')

其他回答

在语言中没有对应的…基于ide…

例如在netbeans中:

NetBeans/Creator支持以下语法:

// <editor-fold defaultstate="collapsed" desc="Your Fold Comment">
...
// </editor-fold>

http://forums.java.net/jive/thread.jspa?threadID=1311

使用Android Studio,试试这个:

//region VARIABLES
private String _sMyVar1;
private String _sMyVar2;
//endregion

注意://region后面没有空行…

你会得到:

自定义代码折叠功能可以使用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

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

这更像是一个IDE特性,而不是语言特性。Netbeans允许您使用以下定义定义自己的折叠定义:

// <editor-fold defaultstate="collapsed" desc="user-description">
  ...any code...
// </editor-fold>

正如文章中提到的,这可能也得到了其他编辑器的支持,但不能保证。

在Eclipse中,您可以折叠括号来包装可变区域块。最接近的方法是这样做:

public class counter_class 
{ 

    { // Region

        int variable = 0;

    }
}