我想在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

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

其他回答

只需安装并启用Coffee-Bytes插件(Eclipse)

我刚从c#转到java,遇到了同样的问题,最好的和准确的区域替代方案如下(在Android Studio工作,不知道intelliJ):

 //region [Description]
 int a;
 int b;
 int c;
//endregion

快捷方式如下:

1-选择代码

2-按下ctrl + alt + t

3-按c并写下你的描述

与大多数人所发布的相反,这不是一个IDE的事情。这是语言问题。区域是一个c#语句。

如果有人感兴趣,在Eclipse中,你可以一次折叠你所有的方法,当你通常插入断点时,只需右键单击,点击“折叠”>“折叠所有”。它知道这不是问题的答案,但只是提供了一种快速代码折叠的替代方案。

实际上,#表示它是一个预处理器指令,这基本上意味着它告诉IDE要做什么。

在代码中使用#region和#endregion的情况下,它在最终代码中是否存在没有区别。如果使用它没有任何改变,你真的能称它为语言元素吗?

除此之外,java没有预处理器指令,这意味着代码折叠的选项是在每个ide的基础上定义的,例如在netbeans中使用//< code-fold>语句