Skip to content
Danny Thomas edited this page Sep 18, 2026 · 1 revision

The formatter has one built-in style and does not read project-specific formatting configuration.

Setting Behavior
Block indentation 4 spaces
Continuation indentation 8 spaces
Code lines No fixed maximum length; breaks are based on Java syntax
Javadoc Wrapped to 80 columns
Imports import module, java.* and javax.*, third-party, then static
Operators Placed at the beginning of a continuation line
Control statement braces Required around non-empty bodies
Opening braces Kept on the same line as the declaration or control statement

Comments that divide imports into groups remain attached to their groups. When such comments are present, the authored order of the groups is preserved rather than moving imports away from the comments that describe them.

Structural line breaks

A fixed line-length limit cannot distinguish a long name from an expression containing many separate parts. Line breaks are instead inserted at boundaries in Java syntax. This keeps the parts of calls, expressions, and method chains from becoming widely separated without breaking merely because an identifier or literal is long.

A long identifier can therefore remain on one line:

return configurationResolver.resolveInheritedApplicationConfiguration(applicationEnvironment);

As an expression gains nested calls, operators, or chain elements, continuation lines expose those boundaries:

downstream.push(SharedSecrets.getJavaUtilCollectionAccess()
        .listFromTrustedArrayNullsAllowed(window));

A list may remain on one line, continue onto a second line, or place each element on its own line. A single continuation is used when one break is enough:

invoke(one, two, three, four, five, six,
        seven);

Longer or more structured lists may use one element per line:

ToolDefinition formatter = new ToolDefinition(
        "alternative-formatter",
        "fmt",
        Optional.empty(),
        Optional.of("com.example.formatter"),
        "alternative-formatter",
        Optional.of("1"),
        Set.of("module-source-path"),
        List.of());

For nested calls, the outer arguments are separated first. Nested lists do not become vertical merely because the enclosing call breaks:

assertEquals(
        List.of("--module-path", "/path with spaces", "--add-modules", "a,b", "#value"),
        ArgumentFiles.parse(argumentFile));

Continuation lines in declarations align with the first parameter when that alignment remains practical:

static void someMethod(int anArgument, Object anotherArgument, String yetAnotherArgument,
                       Object andStillAnotherArgument) {}

When the first parameter is too far to the right, continuation lines use the standard 8-space continuation indentation:

static <A, B> G<A, B> extraordinarilyLongMethodName(F<A, B> first,
        H<A, I<B>> second) {}

Control statement braces

Braces are added around non-empty if, else, for, while, and do bodies, even when the body contains only one statement:

if (ready) {
    start();
}

This follows the Java code conventions, makes the extent of the controlled body explicit, and prevents a newly added statement from accidentally falling outside it. Empty statement bodies and else if chains are left in their conventional forms.

Comments

Javadoc prose is wrapped to 80 columns. Existing wrapping that already fits is preserved, as are words, inline tags such as {@link}, and preformatted content. These elements may extend beyond column 80.

Line and block comments are not reflowed, preserving deliberately arranged lists, diagrams, or code.

Clone this wiki locally