Java netBeans/Eclips 如何折疊一段代碼使整個代碼看起來簡潔
最近剛用Java,以前寫C#的時候,通過region操作可以使一段代碼折疊起來,使整段程序縮成一行,看起來清爽了許多,現在用netBeans, 發現自帶的代碼折疊功能只能折疊一個整個的method,不能選擇一段進行折疊,請問能實現類似於C#的功能嗎?
如 #region
很長的代碼
#endregion
NetBeans內Editor設置了類似的功能。
只需要在模塊開始注釋以//<editor-fold>開始,
在模塊結束行以 //</editor-fold>結束即可
本人測試有效
Can I Create Custom Code Folds?
Apart from usual folds, you can define custom folds. To add your custom fold, type in two special comments as shown in this example:
// <editor-fold> Your code goes here... // </editor-fold>
You may define the default description of a collapsed fold by adding a "desc" tag:
// <editor-fold desc="This is my super secret genius code."> Your code goes here... // </editor-fold>
You may set a fold to be collapsed by default by adding a "defaultstate" tag:
// <editor-fold defaultstate="collapsed"> Your code goes here... // </editor-fold>
Please note that the above examples are for java language. In other languages custom folds may not be supported or you may have to use different characters for marking line comments. Also <editor-fold/> element syntax is not a real XML, we use a simple regex to find your custom folds in a document, which means that there are limitations in the syntax. The most important one is that attributes may only be combined in this specific order: defaultstate, desc.
Applies to: NetBeans 5.x, 6.x
Platforms: All
