Skip to content

Formatting for Eclipse

Rajat Khanna edited this page Apr 25, 2018 · 13 revisions

To apply automatic formatting and style enforcement according to our guidelines with Eclipse, you will require three files from the codingstyle directoy: eclipse_code_cleanup.xml, soot_eclipse_formatter.xml and soot_eclipse_importorder.importorder.

Setup

Step 1.

Once you open the project in Eclipse, go to Windows -> Preferences -> Java -> Code Style -> Clean Up, click on "Import" and select the eclipse_code_cleanup.xml file from the directory codingstyle.

Step 2.

Go to Windows -> Preferences -> Java -> Code Style -> Formatter, click on "Import" and select the soot_eclipse_formatter.xml file from the directory codingstyle.

Step 3.

Go to Windows -> Preferences -> Java -> Code Style -> Organize Imports, click on "Import" and select the soot_eclipse_import.importorder file from the directory codingstyle. Change the values in the fields for "Number of imports needed for .* " and "Number of static imports needed for .* " to 999. And click "Apply and close".

Apply

Step 1.

In Package Explorer, right click on the directory src/main/java, navigate to Source -> Clean Up and select "Use configured profile" (eclipse-cs soot). Click next to preview the changes and finish to apply them.

Step 2.

Similarly, in Package Explorer right click on the directory src/main/java, navigate to Source -> Format.

Step 3.

Just as above, right click on the directory src/main/java, navigate to Source -> Organize Import.

Note: This will apply the automatic formatting to all source files. For new files, it is sufficient to run these steps on the new files only. Eclipse can automatically do this by configuring format-on-save operation. Format-on-save will not run clean up. We suggest running clean up before every commit.


After following the above 6 steps, you can now validate the formatting against the checkstyle configurations by executing mvn validate. Violations to the style conventions will be reported.

Eclipse also has a plugin that can automatically execute Checkstyle and report violations in the background. Having Soot configured as Maven project, installing the M2E Checkstyle Plugin should be sufficient.

Clone this wiki locally