Skip to content

Check the cases of Java 17 on every surface through the visitor for JDK 17 - #296

Open
abashev wants to merge 1 commit into
21.X.Xfrom
abashev/cases-of-java-17-on-every-surface
Open

abashev wants to merge 1 commit into
21.X.Xfrom
abashev/cases-of-java-17-on-every-surface

Conversation

@abashev

@abashev abashev commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Before this PR

FormatterCasesJava17Test (#294) lays out test-cases-java17/ through the visitor of JDK 17 with formatSourceAndFixImports only. The other surfaces each case is checked on create formatters of their own, which take the visitor of the running JDK:

  • the in-process service, as formatDiff runs it without the native binary;
  • --output-replacements, which the bootstrapping and native services run;
  • the command line printing a range.

Those surfaces are checked by FormatterCasesJava21Test alone, on JDK 21 and later. A release line for Java 17 (#293) runs its tests on JDK 17, where that class is disabled, so nothing would check them there.

After this PR

  • The visitor reaches every surface. FormatterServiceImpl and Main take the JDK whose visitor lays out the code through package-private constructors. By default it is the running one, as before. Main hands it to FormatFileCallable.
  • FormatterCasesTest checks every surface with the visitor it is given.
    • FormatterCasesJava17Test uses the visitor of JDK 17.
    • The classes for JDK 21 and later use the visitor of the JDK they run on, as before.
  • FormatterCasesJava21Test keeps test-cases-java17/. On JDK 21 and later the visitor of JDK 21 is the one that lays out that code.
  • FormatterVisitorTest shows that the service and the command line use the visitor they are given. On JDK 21 and later both format a guarded case label with the visitor of JDK 21 and fail on it with the one of JDK 17.
  • ADR-002 says so.

The output does not change. The tests pass on JDK 21, 25 and 27, and all 898 cases of test-cases-java17/ pass on every surface through the visitor of JDK 17.

Possible downsides?

  • On JDK 21 and later the cases of test-cases-java17/ now run the command line and the service twice each, once per visitor: about 1,800 more command-line runs in process, a few seconds.
  • FormatterServiceImpl, Main and FormatFileCallable gain a package-private constructor each. The public ones behave as before.

…DK 17

FormatterCasesJava17Test laid out test-cases-java17 through the visitor of
JDK 17 with formatSourceAndFixImports only: the service and the command line
create formatters of their own, which took the visitor of the running JDK.
The other surfaces were checked by FormatterCasesJava21Test alone, on JDK 21
and later, so on JDK 17 nothing would check them.

FormatterServiceImpl and Main now take the visitor's JDK through
package-private constructors, the running one by default, and Main hands it
to FormatFileCallable. FormatterCasesTest checks every surface with the
visitor it is given: FormatterCasesJava17Test with the one of JDK 17, the
classes for newer JDKs with the one of the JDK they run on, as before.
FormatterVisitorTest shows that the service and the command line use the
visitor they are given: on JDK 21 and later both format a guarded case label
with the visitor of JDK 21 and fail on it with the one of JDK 17.

FormatterCasesJava21Test keeps test-cases-java17: on JDK 21 and later the
visitor of JDK 21 is the one that lays out that code.

This prepares a release line for Java 17 (#293).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant