有没有办法像“if”语句一样折叠 eclipse 子块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2369057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to fold eclipse sub-blocks like an "if" statement?
提问by Shawn
Currently Eclipse only fold the java doc and at function level, but when reading long methods, there could be quite a lot of if/else etc, is there a way to fold them?
目前Eclipse只折叠java文档和函数级别,但是在阅读长方法时,可能会有很多if/else等,有没有办法折叠它们?
采纳答案by pm_labs
It appears Eclipse does not have built-in support for folding if/else statements but allows folding for other more complex cases like Anonymous inner classes. Try looking for plugins like this one(last modified 2007, try it if it supports your Eclipse version).
Eclipse 似乎没有内置支持折叠 if/else 语句,但允许折叠其他更复杂的情况,如匿名内部类。尝试寻找像插件这一个(最后修订2007年,尝试它,如果它支持Eclipse版本)。
回答by hasanghaforian
I found the Coffee-Bytes
plugin. I downloaded it from this linkand found this guideby the author, for using it.
我找到了Coffee-Bytes
插件。我从这个链接下载了它并找到了作者的这个指南,用于使用它。
You can find more details in these references:
您可以在这些参考资料中找到更多详细信息:
What code folding plugins work on Eclipse 3.6?
How to use Coffee-Bytes code folding
回答by lahmania
in updated versions of Eclipse
在 Eclipse 的更新版本中
Change folding preferences at:
在以下位置更改折叠首选项:
Window -> Preferences -> C/C++ -> Editor -> Folding -> Enable folding of preprocessor branches (#if/#else)
Enable folding using ctrl + shift + /
启用折叠使用 ctrl + shift + /
回答by stacker
No, in the Preferences Dialog (Menu Window/Prefernces): Java/Editor/Folding you may choose,
不,在首选项对话框(菜单窗口/首选项)中:Java/Editor/Folding 您可以选择,
- Comments
- Head Comments
- Inner Types
- Members and Imports
- 注释
- 头条评论
- 内部类型
- 成员和进口
if Enable Folding is checked.
如果启用折叠被选中。
If you wan't to do this because the blocks are so long that can't reconize the structure you should consider to split if/else blocks into methods using Alt-Shift-M (Extract Method)
如果您不想这样做,因为块太长而无法重新调整结构,您应该考虑使用 Alt-Shift-M(提取方法)将 if/else 块拆分为方法
回答by z00l
Ok, this is a little bit older, but maybe someone could find this useful: In most cases you can surround the piece of code by an additional pair of scope brackets, and to remember what you folded you can add a line comment.
好吧,这有点旧,但也许有人会发现这很有用:在大多数情况下,您可以用一对额外的范围括号将代码段括起来,并且为了记住折叠的内容,您可以添加行注释。
For example, if you want to collapse the following:
例如,如果要折叠以下内容:
int SectionA_var1;
int SectionA_var2;
int SectionA_var3;
int SectionA_var4;
int SectionA_var5;
int SectionB_var1;
just add the brackets an the comment:
只需添加括号和评论:
{ // SectionA
int SectionA_var1;
int SectionA_var2;
int SectionA_var3;
int SectionA_var4;
int SectionA_var5;
}
int SectionB_var1;
Then you get the (-) sign and you can collapse the whole section to this:
然后你会得到 (-) 符号,你可以将整个部分折叠成这样:
{ // SectionA[...]
int SectionB_var1;
No plugin necessary, and until now I had no situation where this gave me any downsides, except that you cannot use it on a top level declaration to collapse methods.
不需要插件,直到现在我还没有遇到这给我带来任何缺点的情况,除了您不能在顶级声明中使用它来折叠方法。
回答by Ivan Kryvosheia
For now, there is built-in function.
Click "Window->Preferences->C/C++->Editor->Folding" and then enable appropriate option you want.
Apply, close and either refresh project or reopen eclipse.
目前,有内置功能。
Click "Window->Preferences->C/C++->Editor->Folding" and then enable appropriate option you want.
应用、关闭并刷新项目或重新打开 eclipse。
回答by Al Lelopath
For Python, i.e. Eclipse/PyDev, go to Windows > Preferences > PyDev > Editor > Code Folding
and check all the boxes.
对于 Python,即 Eclipse/PyDev,请转到Windows > Preferences > PyDev > Editor > Code Folding
并选中所有复选框。
回答by Kishan
As weird as it looks like, sounds like developers never thought about that. if you have a big if statement or any switch/loop ... just use notepad++ to be able to fold/unfold
尽管看起来很奇怪,但听起来开发人员从未想过这一点。如果你有一个很大的 if 语句或任何开关/循环......只需使用记事本++就可以折叠/展开
回答by Luke
Fold java source code like "if else for" statement
像“if else for”语句一样折叠java源代码
install pluins com.cb.eclipse.folding
restart your Eclipse make sure the pluins enabled
重新启动 Eclipse 确保已启用插件
Click "Window->Preferences->Java->Editor->Folding"
点击“窗口->首选项->Java->编辑器->折叠”
- Select folding: select "Coffee Bytes Java Folding"
- Switch to "User Defined Regions"
- "Start Identifier" = { ; End Identifier = }
- click "Apply and Close"
- Reopen java source editor you will see "if" or "for" block is collapsable
- 选择折叠:选择“Coffee Bytes Java Folding”
- 切换到“用户定义区域”
- “起始标识符” = { ; 结束标识符 = }
- 点击“应用并关闭”
- 重新打开 Java 源代码编辑器,您将看到“if”或“for”块是可折叠的