Skip to content

Output Showcase

This page shows the same Java source formatted with different configuration options. All examples use the java17 input from examples/inputs/java17/FormatterShowcase.java. The full set of 24 golden outputs lives in the examples/outputs/ directory.


Wrap style

wrapStyle is the most consequential option. It controls how elements are distributed across lines once wrapping is triggered.

Constructor with many parameters (Scenario 3)

Input

public FormatterShowcase(String legacyField, List<String> items,
        Map<String, List<Optional<CompletableFuture<String>>>> complexGenericField,
        boolean validateOnConstruction, String defaultLocale, ExecutorService executorService) {
    ...
}

balanced (default) — fits on one line or one element per line; no messy middle:

public FormatterShowcase(
        String legacyField,
        List<String> items,
        Map<String, List<Optional<CompletableFuture<String>>>> complexGenericField,
        boolean validateOnConstruction,
        String defaultLocale,
        ExecutorService executorService
) {

wide — pack as much as fits on each line before breaking:

public FormatterShowcase(String legacyField, List<String> items,
        Map<String, List<Optional<CompletableFuture<String>>>> complexGenericField, boolean validateOnConstruction,
        String defaultLocale, ExecutorService executorService
) {

narrow — one element per line as soon as any wrapping is needed (same as balanced here because the parameter list does not fit on one line):

public FormatterShowcase(
        String legacyField,
        List<String> items,
        Map<String, List<Optional<CompletableFuture<String>>>> complexGenericField,
        boolean validateOnConstruction,
        String defaultLocale,
        ExecutorService executorService
) {

Generic method with arguments (Scenario 4)

Input

public static <T extends Comparable<T>> List<T> filterAndSort(List<T> input, Predicate<T> predicate, java.util.Comparator<T> comparator, boolean removeDuplicates, int maxResults) {

balanced / narrow:

public static <T extends Comparable<T>> List<T> filterAndSort(
        List<T> input,
        Predicate<T> predicate,
        java.util.Comparator<T> comparator,
        boolean removeDuplicates,
        int maxResults
) {

wide — packs the first two arguments on the opening line:

public static <T extends Comparable<T>> List<T> filterAndSort(List<T> input, Predicate<T> predicate,
        java.util.Comparator<T> comparator, boolean removeDuplicates, int maxResults
) {

Binary operators (Scenario 9)

Input

return legacyField != null && !legacyField.isBlank() && items != null && !items.isEmpty() && items.stream().allMatch(item -> item != null && !item.isBlank()) && complexGenericField != null && complexGenericField.size() > 0;

balanced / narrow — each operand on its own line:

return legacyField != null
        && !legacyField.isBlank()
        && items != null
        && !items.isEmpty()
        && items.stream().allMatch(item -> item != null && !item.isBlank())
        && complexGenericField != null
        && complexGenericField.size() > 0;

wide — packs operands until the line is full:

return legacyField != null && !legacyField.isBlank() && items != null && !items.isEmpty()
        && items.stream().allMatch(item -> item != null && !item.isBlank()) && complexGenericField != null
        && complexGenericField.size() > 0;

Continuation indent

Continuation indent for delimited list continuations is always 2 * indentSize (8 spaces with the default indentSize=4). This follows the Oracle/IntelliJ convention and guarantees that wrapped parameters are visually distinct from the method body:

public FormatterShowcase(
        String legacyField,              // 8 spaces (continuation)
        List<String> items,
        ExecutorService executorService
) {
    this.legacyField = legacyField;      // 4 spaces (body indent) — clearly separate

Method-chain exception. Wrapped method-chain segments use a single indentSize step (4 spaces with the default), not 2 * indentSize. Each segment is already visually distinguished by its leading ., so the deeper continuation indent isn't needed and would only push deeply-nested chains far to the right:

return items
    .stream()                            // 4 spaces past the receiver's column
    .filter(item -> !item.isBlank())
    .map(String::trim)
    .collect(Collectors.toList());

See docs/formatting-rules.md "Method Chaining" and TDR-015 for the rationale.


Closing parenthesis placement

closingParenOnNewLine controls whether ) gets its own line when a parameter or argument list wraps.

closingParenOnNewLine: true (default):

public FormatterShowcase(
        String legacyField,
        List<String> items,
        ExecutorService executorService
) {
    // ← closing paren on its own line

closingParenOnNewLine: false:

public FormatterShowcase(
        String legacyField,
        List<String> items,
        ExecutorService executorService) {
    this.legacyField = legacyField;

Interactive comparison

Open examples/compare.html in a browser for a live diff viewer: pick a Java version, choose two configurations from the dropdowns, and the two outputs are shown side-by-side with changed lines highlighted. Scroll is synchronized between the two panes.

Viewing all 24 outputs

The examples/outputs/ directory contains one file per configuration:

examples/outputs/
  java8/
  java17/
    balanced-closingparen-true.java
    balanced-closingparen-false.java
    narrow-closingparen-true.java
    narrow-closingparen-false.java
    wide-closingparen-true.java
    wide-closingparen-false.java
  java21/
  java25/

Each file is the full FormatterShowcase.java formatted with that combination of options (the two vary-able options are wrapStyle and closingParenOnNewLine; indentStyle, indentSize, lineLength, and trailingCommas are held at their defaults).

To regenerate after changing formatting behaviour:

REGENERATE_SHOWROOM=true ./gradlew :core:test --tests RegenerateShowroomGoldens
./gradlew generateCompareHtml

The second command re-embeds the updated outputs into examples/compare.html.