Eclipse implements code block folding-similar to #region in vs ... #endregion

Source: Internet
Author: User

Background

Just when writing code, wrote more than 10 lines can be said to be repeated code:

  

If the whole method or class of code more, feel that they are too TM occupy the place, to the reader in reading code caused great difficulties, so that the thought can be "condensed" into a line, the first flash in the mind is Visual Studio #region and #endregion.

Friends who have not used VisualStudio can first look at the effects of #region and #endregion on code grooming:

Open the second method to look inside the collapsed code block:

If you can also implement custom code block folding like this in eclipse, how refreshing it feels to find something else on the internet really has this thing ~ ~



Eclipse implements code folding

With com.cb.eclipse.folding such a small plug-in can be easily done

1. Download http://download.csdn.net/detail/huyuyang6688/9280759

2, install, that is, put the downloaded Com.cb.eclipse.folding_1.0.6.jar into the eclipse\plugins directory, restart eclipse

3, configuration, such as:

Windows→preference→java→editor→folding

Tick "Enable folding" and select coffee Bytes Java folding after select folding to use (if you do not have a select folding to use option in your Eclipse, see step 4th, Otherwise the 4th step can be ignored), at the bottom of the General tab below, select "User Defined regions (see Below)"

Apply (Submit)

  

Customize the start and end tags in the User Defined Regions tab, where the start and end tags are defined as "region" and "endregion"

  

The installation is successful, just try it! (Don't forget to restart your eclipse!) )

4, if the above three steps are correct, you can skip directly.

If your eclipse does not have a select folding to use option, for example, then it is likely that your Com.cb.eclipse.folding_1.0.6.jar placement directory is incorrect and should be placed in plugins in the Eclipse root directory. , and remember to restart Eclipse.



Test

Include the code block with the annotation symbol ""//"+ start Tag", "" "//" + END tag ", for example, here with"//region "and"//endregion "containing the code block, of course, the start tag can be written after the comment of this code.
The effect is as follows

  

In order to illustrate, the start and end tags are in region and endregion, but the actual start and end tags of the small series are beginning and ending, which makes it easier for Java programmers to read my code, and even if the code is ported to other environments where the plugin is not installed , it is also easier to read and understand.

is not very simple ah, come and try it!


"Reprint please indicate the source--Hu Yuyang" play to Eclipse "--eclipse implement code block folding-similar to the #region in vs ... #endregion"

Eclipse implements code block folding-similar to #region in vs ... #endregion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.