我想在Eclipse中使用区域进行代码折叠;在Java中怎么做到呢?
c#中的一个例子:
#region name
//code
#endregion
我想在Eclipse中使用区域进行代码折叠;在Java中怎么做到呢?
c#中的一个例子:
#region name
//code
#endregion
当前回答
实际上,#表示它是一个预处理器指令,这基本上意味着它告诉IDE要做什么。
在代码中使用#region和#endregion的情况下,它在最终代码中是否存在没有区别。如果使用它没有任何改变,你真的能称它为语言元素吗?
除此之外,java没有预处理器指令,这意味着代码折叠的选项是在每个ide的基础上定义的,例如在netbeans中使用//< code-fold>语句
其他回答
Android Studio(或IntelliJ IDEA)中最快的方法
突出显示要围绕它的代码 按CTRL + Alt + t 按c ==>输入描述 享受
自定义代码折叠功能可以使用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
你也可以在这个博客上下载存档和查找步骤。
VSCODE
我使用vscode for java,它的工作原理与visual studio几乎相同,除了你使用注释:
//#region name
//code
//#endregion
AndroidStudio地区 创建区域
首先,找到(并定义捷径如果需要)环绕菜单
然后,选择代码,按Ctrl+Alt+分号-> choose region..endregion…
前往地区
首先,找到自定义折叠捷径 其次,在代码的任何地方,按Ctrl+Alt+句号(键盘上的'>')
#region
// code
#endregion
只有在IDE中才有好处。在Java中,IDE中没有固定的标准,因此实际上没有与#region并行的标准。