by, 11-04-2011 at 07:14 PM (996 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.
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:
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).
I will dig deep on folding options in this post. Do read the first part of this one first.
If you wish to collapse all the members of the class (including methods), select 'Collapse All' from the Folding window.
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.
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
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.