http://chenzhou123520.iteye.com/blog/1627618
The previous article introduced the Code specification series (i): Eclipse code templates settings, which mainly describes the configuration of Checkstyle in Eclipse. About Checkstyle, the introduction of Baidu Encyclopedia is described as follows: Checkstyle is a project under SourceForge, providing a tool to help Java developers comply with certain coding specifications. It automates the process of code specification checking, freeing developers from this important, but tedious, task. The main contents of Checkstyle inspection include: Javadoc annotation, naming convention, title, import statement, volume size, white space, modifier, block, code problem, class design, hybrid check.
If we want to use Checkstyle, we first have to install the Checkstyle plugin in Eclipse, and the installation tutorials on plugins are all over the web, which is skipped here. The following is mainly about the configuration of Checkstyle. The steps are as follows:
1. Open Windows-->preferences-->checkstyle in eclipse as shown in:
Through the interface we can find that the Checkstyle plug-in has a default built-in 2 code-checking configuration files: Sun Checks, Sun Checks (Eclipse). The configuration of the options that the Checkstyle needs to check is defined separately in these two profiles. The general project team will customize a profile based on the project requirements and import it into eclipse. Today, we mainly introduce this kind of way.
2. Click New, in the popup screen Type drop-down box select external configuration file, and then introduce our custom configuration check XML file, name can be customized as shown in:
Click OK to save, then we can see the configuration we just imported in the previous screen. is the Chenzhou_checkstyle.
We can select the line with the mouse and click on the Set as Default button on the right so that the Checkstyle is already configured.
With the Checkstyle configured, we also need to activate the Checkstyle check separately in the project by:
Right-click on the item-->properties-->checkstyle, and in the popup screen, select the check box Checkstyle active for this project. At the same time, check our custom configuration Chenzhou_checkstyle in the Configure bar as shown in
Click OK to save the project will be rebuild, so the Checkstyle check has been activated.
We can open our code, and if there is a specification in the code that does not conform to the Checkstyle definition, eclipse will be highlighted in yellow, as shown in:
If we hover the mouse over the highlighted code, eclipse will give you a warning message.
For detailed configuration of the Checkstyle check option, we can make configuration changes in eclipse, such as selecting Chenzhou_checkstyle
Click on the Configure button on the right to eject the following interface
, the menu item on the left represents the options that we can configure, and each menu item can be expanded to multiple submenu items. We can configure them separately. Where the menu item is marked with a green tick indicates that the item and all subkeys have been added to the check. If the subkey is not all added, the parent menu item does not display a green checkmark.
If we need to add a configuration item, you can click to select a menu item, then click the Add button below, select OK after the item's submenu item will be displayed in the right area, we can check the menu item before the box to configure the specific item. As shown
For the specific meaning of each, do not elaborate, should be everyone can read!
Code Specification Series (ii): Eclipse checkstyle Configuration