Skip to content

Showroom examples and Java levels

Layout

  • FormatterShowcase.java under examples/inputs/java8, java17, java21, and java25 drives the 24 golden files (examples/outputs/..., 6 formatter configs × 4 language trees). Scenario comments in those files label each block.
  • Do not add extra .java files under examples/inputs/java*/ for showroom-only syntax: fold new cases into FormatterShowcase.java for the right level, then run REGENERATE_SHOWROOM=true ./gradlew :core:test --tests RegenerateShowroomGoldens so examples/outputs/ stays in sync. ExamplesCorpusFormatTest still walks every .java input, but the golden matrix is defined only for FormatterShowcase.java.
  • Commit messages for input/golden changes: a new numbered scenario here usually goes with feat: (broader, intentional work); fix: for a narrow bug with no new scenario; feat!: for substantive docs/canonical-formatting-rules.md / contract change. See Showroom, examples, and golden files in docs/contributing.md (TDR-018).

Scenario numbering vs. language level

Scenarios 1–20 are valid on Java 8 and appear in every tree.

Scenario 9 covers binary-operator wrapping, including a wrapped multiplication with a trailing line comment that must be preserved exactly once and converge to a fixed point.

Scenarios 21–25 (records, sealed types, pattern instanceof, switch expressions, text blocks) require Java 17 semantics. They appear in java17, java21, and java25, and are omitted from java8 (the java8 file jumps from scenario 20 to 31 so later scenario numbers stay aligned).

Scenarios 26–30 use Java 21 features (for example record patterns in switch, when guards, virtual threads). They appear in java21 and java25, and are omitted from java8 and java17.

Scenarios 31–44 are shared control-flow and wrapping cases; they appear in all four trees.

Scenario 45 (switch entry with a long guard) is only in Java 17+ trees (java17, java21, java25).

Scenario 46 (flexible constructor bodies, JEP 513) is only in java25.

Scenario 53 (interface with a long extends clause) appears in all four trees.

Scenario 54 (nested wrapped method call: outer call with two arguments where the first argument is another multi-argument call with long names) appears in all four trees. It is a regression guard for continuation indent across nested (...) so inner closing delimiters are not flushed to the outer call’s indent column.

Scenario 55 (nested static class with two consecutive // line comments immediately before the first field) appears in all four trees. It is a regression guard against inserting a blank line between those comments when formatting type members.

Scenario 56 (wrapped method call with comments interleaved between arguments and before the closing parenthesis) appears in all four trees. It covers comment ordering and closing-delimiter preservation in argument lists, distinct line and block comments on a chained call and its argument, and trailing line and block comments after a sole argument in a method chain.

Scenario 57 (annotation array with mixed comments between elements and before the closing brace) appears in all four trees. It covers comment ordering and closing-delimiter preservation in annotation values.

Scenario 58 (nested array initializers with line and block comments) appears in all four trees. It includes an empty row whose comments must stay inside its braces. Tab-indentation regressions also verify that following members retain their indentation.

Scenarios 68–77 (static initializer block, instance initializer block, constructor / array-constructor method references, long throws clause, constructor with throws clause, long cast chains, labeled break/continue, varargs parameter at declaration and call site, curried lambda, enum with abstract method per-constant body) appear in all four trees. They cover Java 8-compatible language constructs that were previously absent from the showcase but exercise meaningful wrapping decisions across wrapStyle and closingParenOnNewLine settings.

Scenario 78 (sealed class — not interface — with long permits clause) and Scenario 79 (local record and local class declared inside a method body) appear only in java17, java21, and java25. Sealed classes were finalized in Java 17 (JEP 409); local records require Java 16+ (JEP 395 / JEP 397). Java 8 omits both numbers.

Scenario 80 (enum mixing a plain constant with per-constant anonymous bodies, constructor arguments, and trailing field/constructor/method members) appears in all four trees; it is Java 8-compatible enum syntax. It extends the per-constant anonymous-body separator-placement regression coverage from Scenario 77 (issue #47 / the TDR-023 correction) to a constant list that also contains a plain (body-less) constant and constants with constructor arguments.

Scenario 81 (consecutive line comments between fluent method calls) appears in all four trees and uses Java 8-compatible syntax. It checks that every comment line survives in order beside the next call.

Scenario 82 (classes annotated with a multi-pair, single-pair and single-member annotation whose string values overflow the line) appears in all four trees. It is a regression guard for TDR-030: the annotation's values wrap per wrapStyle before any string literal is split into +-joined chunks.

Scenarios 83-85 (char literals whose Unicode escapes denote isolated surrogate code units; Javadoc, block, and line comments containing escaped NUL \u0000 and surrogate escapes; a string array of ANSI color escapes such as \u001B[31m that overflows the line) appear in all four trees. They are regression guards for #131: isolated surrogates and NUL are re-emitted as printable Unicode escapes in literals and every comment location (so the output survives a strict UTF-8 round trip instead of degrading to ? or raw control bytes), and escaped literals are measured at their escaped width so wrapping never splits an escape sequence.

Scenario 86 (trailing line comments in array initializers) appears in all four trees and uses Java 8-compatible syntax. It is a regression guard for duplicated trailing comments: each row's // comment prints once, after the row's final value, and a block comment before a trailing line comment keeps its source order. It covers a multi-row int[], a byte[] table with empty block separators, and a method-local String[] with mixed block and line comments.