There's no such standard equivalent. Some IDEs - Intellij, for instance, or Eclipse - can fold depending on the code types involved (constructors, imports etc.), but there's nothing quite like #region.
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
You can download archive and find steps at this Blog also.
我从 C# 转向 java,遇到了同样的问题,区域的最佳和准确替代方案如下所示(在 Android Studio 中工作,不了解 intelliJ):
//region [Description]
int a;
int b;
int c;
//endregion
快捷方式如下所示:
1- 选择代码
2- 按ctrl + alt + t
3- 按 c 并写下您的描述
I were coming from C# to java and had the same problem and the best and exact alternative for region is something like below (working in Android Studio, dont know about intelliJ):
//region [Description]
int a;
int b;
int c;
//endregion
If anyone is interested, in Eclipse you can collapse all your methods etc in one go, just right click when you'd normally insert a break point, click 'Folding' > 'Collapse all'. It know it's not an answer to the question, but just providing an alternative to quick code folding.
除此之外,java 没有预处理器指令,这意味着代码折叠选项是在每个 ide 的基础上定义的,例如在 netbeans 中使用 //<;代码折叠>陈述
Actually johann, the # indicates that it's a preprocessor directive, which basically means it tells the IDE what to do.
In the case of using #region and #endregion in your code, it makes NO difference in the final code whether it's there or not. Can you really call it a language element if using it changes nothing?
Apart from that, java doesn't have preprocessor directives, which means the option of code folding is defined on a per-ide basis, in netbeans for example with a //< code-fold> statement
发布评论
评论(23)
JetBrains IDEA 有这个功能。您可以使用热键“环绕”(ctrl + alt + T)。这只是一个IDEA功能。
那里的地区看起来像这样:
JetBrains IDEA has this feature. You can use hotkey "surround with" for that (ctrl + alt + T). It's just an IDEA feature.
Regions there look like this:
没有这样的标准等价物。一些 IDE(例如 Intellij 或 Eclipse)可以根据所涉及的代码类型(构造函数、导入等)进行折叠,但没有什么比
#region
更好的了。There's no such standard equivalent. Some IDEs - Intellij, for instance, or Eclipse - can fold depending on the code types involved (constructors, imports etc.), but there's nothing quite like
#region
.使用 Android Studio,尝试以下操作:
小心://region ... 之后没有空行
,您将得到:
With Android Studio, try this:
Careful : no blank line after //region ...
And you will get:
语言中没有等效项...基于 IDE...
例如在 netbeans 中:
NetBeans/Creator 支持以下语法:
http://forums.java.net/jive/thread.jspa?threadID=1311
No equivalent in the language... Based on IDEs...
For example in netbeans:
NetBeans/Creator supports this syntax:
http://forums.java.net/jive/thread.jspa?threadID=1311
可以使用 CoffeeScript 代码折叠插件将自定义代码折叠功能添加到 eclipse 中。
经过测试,可以与 eclipse Luna 和 Juno 一起使用。步骤如下
从此处下载插件
导航
Window >Preferences > Java > 编辑器 > 折叠 > 选择要使用的折叠:Coffee Bytes Java > 常规选项卡 > 勾选用户定义的折叠前面的复选框
创建新区域,如下所示:
重新启动 Eclipse。
尝试折叠是否适用于以指定的开始和结束标识符为前缀的注释
您可以在此博客 也。
Custom code folding feature can be added to eclipse using CoffeeScript code folding plugin.
This is tested to work with eclipse Luna and Juno. Here are the steps
Download the plugin from here
Extract the contents of archive
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
You can download archive and find steps at this Blog also.
对于 Eclipse IDE,Coffee-Bytes 插件 可以开始吧,下载链接在这里。
编辑:
有关咖啡的最新信息-字节在这里。
For Eclipse IDE the Coffee-Bytes plugin can do it, download link is here.
EDIT:
Latest information about Coffee-Bytes is here.
这更多的是 IDE 功能,而不是语言功能。 Netbeans 允许您使用以下定义定义自己的折叠定义 :
正如文章中所述,其他编辑器也可能支持这一点,但不能保证。
This is more of an IDE feature than a language feature. Netbeans allows you to define your own folding definitions using the following definition:
As noted in the article, this may be supported by other editors too, but there are no guarantees.
突出显示要包围的代码
ctrl
+
alt
+t
c
==>然后输入描述highlight the code
you want to surround itctrl
+alt
+t
c
==> then enter the descriptionAndroidStudio
区域创建区域
首先,查找(并根据需要定义快捷方式)
Surround With
菜单然后,选择代码,按
Ctrl+Alt+分号
->选择region..endregion...
转到区域
首先,找到
自定义折叠
快捷方式其次,从代码中的任意位置按
Ctrl+Alt+Period('>' 键盘上的)
AndroidStudio
regionCreate region
First, find (and define short cut if need) for
Surround With
menuThen, select the code, press
Ctrl+Alt+Semicolon
-> chooseregion..endregion...
Go to region
First, find
Custom Folding
short cutSecond, from anywhere in your code, press
Ctrl+Alt+Period('>' on keyboard)
与大多数人发布的内容相反,这不是 IDE 的东西。这是语言的事情。 #region 是一个 C# 语句。
Contrary to what most are posting, this is NOT an IDE thing. It is a language thing. The #region is a C# statement.
我从 C# 转向 java,遇到了同样的问题,区域的最佳和准确替代方案如下所示(在 Android Studio 中工作,不了解 intelliJ):
快捷方式如下所示:
1- 选择代码
2- 按
ctrl
+alt
+t
3- 按
c
并写下您的描述I were coming from C# to java and had the same problem and the best and exact alternative for region is something like below (working in Android Studio, dont know about intelliJ):
the shortcut is like below:
1- select the code
2- press
ctrl
+alt
+t
3- press
c
and write your description最好的方法
提示:输入“;”在“endregion”的末尾
The best way
Tip: Put ";" at the end of the "endregion"
如果有人感兴趣,在 Eclipse 中你可以一次性折叠所有方法等,只需在通常插入断点时右键单击,单击“折叠”>“折叠”即可。 “全部折叠”。它知道这不是问题的答案,而只是提供快速代码折叠的替代方案。
If anyone is interested, in Eclipse you can collapse all your methods etc in one go, just right click when you'd normally insert a break point, click 'Folding' > 'Collapse all'. It know it's not an answer to the question, but just providing an alternative to quick code folding.
这是一个例子:
100%works in Android studio
here is an example:
100% works in Android studio
实际上只会让您在 IDE 中获得任何好处。对于 Java,IDE 中没有固定的标准,因此实际上没有与
#region
平行的标准。Really only gets you any benefit in the IDE. With Java, there's no set standard in IDE, so there's really no standard parallel to
#region
.vscode
我使用 vscode for java,它的工作方式与 Visual Studio 几乎相同,除了使用注释:
vscode
I use vscode for java and it works pretty much the same as visual studio except you use comments:
我通常需要它来注释代码,因此我在其开头和结尾处使用大括号。
它可以用于代码片段,但可能会在某些代码中产生问题,因为它改变了变量的范围。
I usually need this for commented code so I use curly brackets at start and end of that.
It could be used for code snippets but can create problems in some code because it changes the scope of variable.
了解自定义折叠区域 < kbd>⌥⌘T
Meet custom folding regions ⌥⌘T
在 Visual Studio Code 中,尝试以下操作:
In Visual Studio Code, try this:
实际上,johann,
#
表示它是一个预处理器指令,这基本上意味着它告诉 IDE 要做什么。如果在代码中使用
#region
和#endregion
,无论它们是否存在,对最终代码都没有影响。如果使用它没有任何改变,你真的可以称它为语言元素吗?除此之外,java 没有预处理器指令,这意味着代码折叠选项是在每个 ide 的基础上定义的,例如在 netbeans 中使用 //<;代码折叠>陈述
Actually johann, the
#
indicates that it's a preprocessor directive, which basically means it tells the IDE what to do.In the case of using
#region
and#endregion
in your code, it makes NO difference in the final code whether it's there or not. Can you really call it a language element if using it changes nothing?Apart from that, java doesn't have preprocessor directives, which means the option of code folding is defined on a per-ide basis, in netbeans for example with a //< code-fold> statement
在 Mac 和 Android Studio 上请遵循以下顺序:
您还可以选择其他选项:
On Mac and Android Studio follow this sequence:
<editor-fold>
Also you can select other options:
在 Eclipse 中,您可以折叠包围变量区域块的括号。最接近的是做这样的事情:
In Eclipse you can collapse the brackets wrapping variable region block. The closest is to do something like this:
只需安装并启用 Coffee-Bytes 插件 (Eclipse)
Just intall and enable Coffee-Bytes plugin (Eclipse)