Title: Run import cleanup and modifier reordering as one pre-formatting pass · Issue #157 · openjavaformat/open-java-format · GitHub
Open Graph Title: Run import cleanup and modifier reordering as one pre-formatting pass · Issue #157 · openjavaformat/open-java-format
X Title: Run import cleanup and modifier reordering as one pre-formatting pass · Issue #157 · openjavaformat/open-java-format
Description: Upstream: google/google-java-format#1488 Kind: idea | Priority: medium google-java-format#1488 (merged 2026-10-20, a Google-internal change exported by copybara) folds unused-import removal, import sorting and modifier reordering into a ...
Open Graph Description: Upstream: google/google-java-format#1488 Kind: idea | Priority: medium google-java-format#1488 (merged 2026-10-20, a Google-internal change exported by copybara) folds unused-import removal, import...
X Description: Upstream: google/google-java-format#1488 Kind: idea | Priority: medium google-java-format#1488 (merged 2026-10-20, a Google-internal change exported by copybara) folds unused-import removal, import...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/157
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Run import cleanup and modifier reordering as one pre-formatting pass","articleBody":"**Upstream:** https://github.com/google/google-java-format/pull/1488 \n**Kind:** idea | **Priority:** medium\n\n[google-java-format#1488](https://github.com/google/google-java-format/pull/1488) (merged 2026-10-20, a Google-internal change exported by copybara) folds unused-import removal, import sorting and modifier reordering into a single \"cleanups\" stage that runs before layout. Unused imports are removed and imports sorted first, and when no pass changes non-whitespace text the already parsed compilation unit is reused for formatting. As a consequence `getFormatReplacements` became strictly whitespace-only and no longer reorders modifiers; callers that want modifier reordering on character ranges must go through `formatSource`.\n\nWhy it matters: our `Formatter.getFormatReplacements` still reorders modifiers internally, and an existing code comment there admits this is only safe because modifier order does not affect whitespace. IDE integrations (IntelliJ import optimizer, Eclipse plugin) that consume replacements are the ones exposed to that quirk. The parse reuse is also a small performance gain. The change touches the public API contract, so it is a deliberate decision rather than a mechanical port, and it has no effect on formatted output.\n\nAffected files in our repo:\n- open-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java (`getFormatReplacements`, and the import steps in `formatSource` and `formatSourceAndFixImports`)\n- open-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java (import removal and ordering before formatting)\n- open-java-format/src/main/java/com/palantir/javaformat/java/ModifierOrderer.java, RemoveUnusedImports.java, ImportOrderer.java\n- open-java-format-idea-plugin (import optimizer integration)\n\nSuggested action: investigate. Read the upstream diff (new CleanupPass and Cleanups classes plus a large test), decide whether we want the whitespace-only guarantee for `getFormatReplacements`, and if so adopt the idea, noting the API change in our release notes. Related earlier refactor (replacement-returning orderers) was skipped as no behaviour change.\n\n---\n_Filed from an upstream-watch ticket after manual review._","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-10-25T19:19:25Z","url":"https://github.com/openjavaformat/open-java-format/issues/157"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a83c4cc3-80f6-651f-609a-34f3905d4612 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D74C:39575D:289DC7:364B8C:6AFBB793 |
| html-safe-nonce | 5b74f1cedc92afe2d65fe0cef0349bb834516001e22fd01ca340ef01f5b7d055 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzRDOjM5NTc1RDoyODlEQzc6MzY0QjhDOjZBRkJCNzkzIiwidmlzaXRvcl9pZCI6Ijc5MzIwMDA0ODA4NDQ4MjI0MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e4c15c63397e879916abd3a84f40e21be3b1b204396ce7c10b8f78338eaedb06 |
| hovercard-subject-tag | issue:6028295258 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/157/issue_layout |
| twitter:image | https://opengraph.githubassets.com/df780e20367de617c39d6769ebdb7ce791283aeff0c4a2592eabdfe7db166e06/openjavaformat/open-java-format/issues/157 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/df780e20367de617c39d6769ebdb7ce791283aeff0c4a2592eabdfe7db166e06/openjavaformat/open-java-format/issues/157 |
| og:image:alt | Upstream: google/google-java-format#1488 Kind: idea | Priority: medium google-java-format#1488 (merged 2026-10-20, a Google-internal change exported by copybara) folds unused-import removal, import... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-preview |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width