Skip to content

Java code Formater and Checkstyle configuration for development

romani edited this page Sep 27, 2012 · 7 revisions

Author is Ruslan Dyachenko.

After finishing work under your new check you need format your code with Checkstyle format to avoid error messages while building Checkstyle project with your check.

STEPS:

1. Use this formatter which is approximate to origin Checkstyle format. Run Eclipse: Windows — Preferences — Java — Code Style — Formatter and import it. Apply formatter on your code.

2. As provided formatter isn’t cover all Checkstyle requirements, this step represents the coverage of remaining cases.

2.1. Right click on project where you have written your check — Preferences — Checkstyle — ‘Local Check Configurations’ tab — New.

2.2. In opened dialog choose Type – External Configuration File. Write a Name of a new configuration. Browse Location: go to the Checkstyle project folder and choose checkstyle_checks.xml file. Download file and put in profile filesystem path. Press Additional properties… button:

2.3. Press Find unresolved properties button:

2.4. In opened dialog press Yes:

2.5. Now you need to add values for properties.

  • checkstyle.header.file property:
    Press Edit…. In Value text field paste a path to java.header file which is in Checkstyle project folder:

  • checkstyle.importcontrol.file property:
    Press Edit…. In Value text field paste a path to import-control.xml file which is in Checkstyle project folder:

  • checkstyle.suppressions.file property:
    Press Edit…. In Value text field paste a path to suppressions.xml file which is in Checkstyle project folder:

  • translation.severity property:
    Press Edit…. In Value text field write ignore:

2.6. Press Ok and return to the Checkstyle preference page. Choose Main tab, from combo list choose your new configuration. Press Ok:

2.7. Right click on your project — Checkstyle — Activate Checkstyle. Fix all checkstyle warnings.