Skip to content

Fix only the imports in the out-of-process fixImports - #236

Merged
abashev merged 3 commits into
21.X.Xfrom
abashev/Fix-imports-out-of-process
Nov 18, 2026
Merged

abashev merged 3 commits into
21.X.Xfrom
abashev/Fix-imports-out-of-process

Conversation

@abashev

@abashev abashev commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #221. Independent of the other open pull requests; based on 21.X.X.

BootstrappingFormatterService.fixImports and NativeImageFormatterService.fixImports ran Main - with no flags, as formatSourceReflowStringsAndFixImports does: the imports were fixed, and the whole file was laid out and its long strings reflowed along with them. FormatterServiceImpl.fixImports, in process, fixes only the imports. Both out-of-process services now pass --fix-imports-only.

What changes for users

Nothing calls fixImports through these services today. It is what an import optimizer in the IntelliJ plugin would call on every Optimize imports (#222, ADR-003); palantir-java-format's optimizer was removed as slow because of this.

Tests

The input is the one from #221: three imports, one unused, and a class body that is not formatted.

  • JvmFormatterServicesTest (new): fixImports on the in-process and the bootstrapping services. It needs no native binary, so it runs in every build, on every JDK.
  • FormatterServicesTest.fixes_only_the_imports: on the bootstrapping and native services, in the native jobs.

On 21.X.X the bootstrapping and native runs fail, with the whole file formatted; the in-process one passes. With the change:

  • JDK 21: ./gradlew check passes.
  • JDK 25: :open-java-format-jdk-bootstrap:test passes.
  • -PnativeImage=true :open-java-format-jdk-bootstrap:test (macOS aarch64, GraalVM 25): 10 of 10 in FormatterServicesTest and 2 of 2 in JvmFormatterServicesTest pass.

BootstrappingFormatterService.fixImports and
NativeImageFormatterService.fixImports ran Main with no flags, as
formatSourceReflowStringsAndFixImports does: the imports were fixed,
and the whole file was laid out and its long strings reflowed with
them. FormatterServiceImpl.fixImports, in process, fixes only the
imports. Both now pass --fix-imports-only.

Nothing calls fixImports through these services today. An import
optimizer in the IntelliJ plugin would, on every Optimize imports, and
the one palantir-java-format had was removed as slow (#222).

JvmFormatterServicesTest checks fixImports on the in-process and the
bootstrapping services, and runs in every build; FormatterServicesTest,
in the native jobs, checks it on the bootstrapping and native ones.

Closes #221
@abashev
abashev merged commit c15deb4 into 21.X.X Nov 18, 2026
17 checks passed
@abashev
abashev deleted the abashev/Fix-imports-out-of-process branch November 18, 2026 08:49
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.

FormatterService.fixImports formats the whole file out of process

1 participant