Skip to content

Formatting for IntelliJ

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

To apply automatic formatting and style enforcement according to our guidelines with IntelliJ, you will require the Eclipse Code Formatter Plugin for IntelliJ, and two files from the codingstyle directoy: soot_eclipse_formatter.xml and soot_eclipse_importorder.importorder.

Setup

Step 1.

Once you have installed the Eclipse Code Formatter Plugin and opened the project in IntelliJ, go to File -> Settings -> Other Settings -> Eclipse Code Formatter, select "Use the Eclipse code formatter" radio button.

Step 2.

Import the "Eclipse Java Formatter config file", by clicking on browse and selecting the path for soot_eclipse_formatter.xml file.
Check "Optimize Imports", and load the import order configuration from soot_eclipse_import.importorder file in the directory codingstyle.

Step 3.

Go to File -> Settings -> Editor -> Code Style -> Java -> Imports.
Check "Use single class imports".
Ensure there is no package in the table "Packages to use Imports with .* ". If there are, remove them.
Change the values in the fields for "Class count to use import with .* " and "Names count to use import with .* " to 999. And click "Apply".

Apply

Step 1.

In Package Explorer, right click on the directory src/main/java, and navigate to Analyze -> Run inspection by name....
Type "Control Flow statements without braces" and hit enter. Ensure that the scope is set to "Directory '...\src\main\java [soot]'" in the dialog box that appears, and click "Ok".

Step 2.

In Inspection results, if any problem is reported, click "Add braces to statement".

Step 3.

In Package Explorer, right click on the directory src/main/java, and click "Reformat code".
Check the options "Include subdirectories" and "Optimize imports".
Ensure that the option "Rearrange entries" is unchecked.

Step 4.

Click "Run".
Now IntelliJ will start formatting the selected directory, it will take a few minutes to complete.


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

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

Clone this wiki locally