Our team is developing command-line static code analysis tool that helps you to format your java code. It is a java program that allows users to format their code with less effort and time using the provided config however it can be configured to your liking based on rules mentioned below.
- Java (Java 17+)
- JavaParser library
- Intellij IDEA
- Git
- Java programming language
- Gradle
- Commons Configuration and Commons BeanUtils libraries
- Download the built file from Formatter.
- Extract the
.zipfile. - Enter the directory called Formatter of the extracted directory.
- Execute cli command: (Java version should be the newest version or at least => 17.0.13).
java -jar Formatter.jarFor/While: Ensures spaces around operators, braces on the same line, and single-line body support.- For: Also supports formatting for for-each loops.
Do-While: Aligns do and { on the same line, and ensures proper spacing around the while keyword and condition.
If/Else: Standardizes placement of braces, spacing, and ladder structures.- Supports formatting of
ternary operationsfor concise conditionals.
- Supports formatting of
Switch: Formatscases, alignsdefault, and ensures indentation.
- Ensures spaces around assignment
=and arithmetic operators+,-,*, etc.
- Cleans up inconsistent spaces, tabs, and empty lines.
- Collapses multiple blank lines into one.
- Formatter has a configuration file that is located Formatter/config/formatter_config.cfg.
- File can be edited either from the CLI or directly with a file editor editing the
formatter_config.cfgfile directly.
| Option | Values |
|---|---|
| indent_style | tab/space |
| indent_size | 0 < x < 10 |
| open_brace_on_the_same_line | true/false |
| space_before_control_paren | true/false |
| space_around_operators | true/false |
| space_before_comma | true/false |
| space_after_comma | true/false |
| newline_at_end_of_file | true/false |
| blank_lines_after_imports | 0 < x < 10 |
For in-depth information about the formatting rules and configuration details, please refer to the docs/ directory. This includes detailed explanations on how the formatter works and how to configure it to suit your needs.