View RSS Feed

My Java Tips

Folding

Rate this Entry
by , 11-04-2011 at 07:14 PM (862 Views)
I will introduce folding option provided by Eclipse which is very helpful if you wish to fold (collapse) elements of a class.


You might have experienced a situation where you have a class with lot of methods and comments. You may wish to collapse all the comments, or the methods or both to have a bird’s eye view of what the class is offering.

Name:  foldin_option.PNG
Views: 154
Size:  31.0 KB

Right click on the left most line (border) of the class. A window will open in which Folding will display the option of your interest. The first option ‘Enable Folding’ will enable folding and doing so will enable other available options like:

Expand All
Collapse All
Reset Structure
Collapse Members
Collapse Comments

Remember, if you enable folding, you may collapse or expand methods and comments manually by clicking the plus or minus symbol (available on the left margin of method comment structure).

Name:  manual_folding.PNG
Views: 48
Size:  6.9 KB

I will dig deep on folding options in this post. Do read the first part of this one first.

More...

If you wish to collapse all the members of the class (including methods), select 'Collapse All' from the Folding window.

Name:  all_shrinked.PNG
Views: 57
Size:  16.9 KB

You may see that all the structures of the class are collapsed. You may expand any member by simply clicking the plus corresponding symbol.

Now you wish to only collapse the methods and not the comments. Simply select ‘Collapse Members’ from the Folding window. Try the other options out. Use the appropriate when needed.

Name:  members_collapsed.PNG
Views: 39
Size:  23.3 KB

Its also handy to remember the short keys for the most used option.

Now let me present folding preferences that you may set for your Java project as default.


You will find a window to set folding preferences in the following;

Windows > Preferences > Java > Editor > Folding

Name:  foldingpreferences.PNG
Views: 41
Size:  33.4 KB

Select/deselect the option as you prefer. By default folding is enables and only imports and header comments are collapsed.

I hope this was informative.

Submit "Folding" to Facebook Submit "Folding" to Digg Submit "Folding" to del.icio.us Submit "Folding" to StumbleUpon Submit "Folding" to Google

Tags: None Add / Edit Tags
Categories
Eclipse

Comments