如何在 Intellij 中创建命名代码块?
当 Intellij 为 UI 表单生成代码时,您可以折叠代码块,它被命名为:“UI Designer generated code”。可以折叠代码选择,但其折叠表示显示为“...”。是否可以给它一个自定义名称? 它看起来类似于 C# 中折叠的 #region 代码块。
When Intellij generates code for UI forms you can collapse the code block and it is named: "UI Designer generated code". It is possible to collapse a code selection but its collapsed representation is displayed as "...". Is it possible to give it a custom name?
It would look similar to a collapsed #region code block in C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
他们现在已经实施了区域支持!
来自 http://youtrack.jetbrains.com/issue/IDEA-80636
目前 Intellij IDEA支持两种基本类型的自定义折叠注释:
类 NetBeans:
和类 VisualStudio:
请注意,如果“#”字符为“region...endregion”,则行注释符号可以从“//”更改为“#”由某种语言支持。但默认情况下,自定义折叠注释使用与通常用于语言行注释的注释字符相同的注释字符。
在许多情况下,您可以使用 Ctrl+Alt+T(环绕),而不是手动输入注释。
如果您发现某些内容未按预期工作,请提交单独的问题。
They have implemented region-support now!
From http://youtrack.jetbrains.com/issue/IDEA-80636
Currently Intellij IDEA supports two basic types of custom folding comments:
NetBeans-like:
And VisualStudio-like:
Note that line commenting symbols for "region...endregion" can be changed from "//" to "#" if the '#' character is supported by a language. But by default custom folding comments use the same comment characters as normally used for language line comments.
Instead of typing the comments manually, in many cases you can use Ctrl+Alt+T (surround with).
Please submit separate issues if you find that something doesn't work as expected.
有一个快捷方式:
打开
Surround with
菜单,按Linux/Windows:Ctrl +Alt+T
Mac: Option ⌥+Command ⌘+T
然后选择
<编辑器折叠...>评论
选项或者您也可以手动执行此操作。
对于 Java/Scala 来说是:
对于 Python 来说几乎是一样的
示例:
There is a shortcut for that:
Open
Surround with
menu, by pressingLinux/Windows: Ctrl +Alt+T
Mac: Option ⌥+Command ⌘+T
And than choose
<editor-fold...> Comments
optionOr you can do it manually.
For Java/Scala it is:
For Python it's almost the same
Example:
IDEA 尚无此类功能,请观看/投票链接的问题.更新:此功能从 IDEA 11.1 版本开始可用。
IDEA doesn't have such feature yet, please watch/vote the linked issue.UPDATE: this feature is available starting from IDEA 11.1 release.
您只需将
#
替换为//
,如下所示:You just need to replace
#
by//
like below :