Skip to content

Fix import binding preservation and comment formatting - #29

Merged
DanielThomas merged 1 commit into
mainfrom
fix/formatter-correctness
Nov 10, 2026
Merged

DanielThomas merged 1 commit into
mainfrom
fix/formatter-correctness

Conversation

@DanielThomas

Copy link
Copy Markdown
Member

Summary

Fix correctness issues identified while reviewing Guillaume Laforge's formatter comparison, plus an additional import-binding defect found during reproduction.

  • Respect explicit type imports during ordinary and static wildcard expansion. Previously, the CLI could change a field's type from java.lang.Thread to a wildcard-imported custom.Thread while leaving the result compilable.
  • Retain used explicit java.lang imports instead of unconditionally removing them. Removing them can introduce ambiguity or change bindings; unused imports are still removed.
  • Stabilize comment-only blocks by consistently placing comments attached to closing braces inside the body. This fixes the reported two-cycle Formatting did not converge failure without changing forced-break width accounting.
  • Correct closing-brace indentation for tabular array initializers ending in line comments.
  • Preserve line-comment text in flat layouts, including $NON-NLS$ and suppression markers, consistently with the existing no-reflow policy.
  • Record the integrated-source fixes in the vendor patch.

Validation

Regression tests were added before the fixes and reproduced the reported failures. Coverage includes comment-only methods, constructors, initializers, type declarations, control-flow blocks and lambdas; array comments with and without trailing commas; and standalone JBang directives and trailing comment markers.

Import regression tests compile source before and after formatting and inspect the resulting field type for ordinary and static wildcard imports.

  • ja test --all: 221 tests passed
  • git diff --check: clean

Scope

No changes to structural wrapping policy are included. The style-evaluation document is excluded from this PR. Pre-existing drift between the vendor patch and the integrated visitor source is not reconciled here; this change adds only the correctness fixes to that patch.

Respect explicit type imports when expanding wildcards and retain used java.lang imports to avoid changing type bindings.

Stabilize comment-only blocks, align tabular array closing braces, and preserve line-comment markers in flat layouts. Add regression coverage, including compiled field-type checks, and record the fixes in the vendor patch.
@DanielThomas
DanielThomas merged commit c2218dc into main Nov 10, 2026
1 check passed
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