Skip to content

fix(java-ast): deduplicate imports when references are used#10

Open
singhvishalkr wants to merge 1 commit intoamplication:mainfrom
singhvishalkr:fix/9845-java-ast-deduplicate-imports
Open

fix(java-ast): deduplicate imports when references are used#10
singhvishalkr wants to merge 1 commit intoamplication:mainfrom
singhvishalkr:fix/9845-java-ast-deduplicate-imports

Conversation

@singhvishalkr
Copy link
Copy Markdown

Problem

When multiple \ClassReference\ values pointed at the same type, \Writer\ emitted duplicate \import\ lines. \Set\ uses reference identity, so logically identical references were not merged.

Change

  • Track reference-derived imports as fully qualified strings (\.\) in a \Set.
  • Build the final import list as [...new Set([...this.imports, ...this.references])]\ so explicit imports and reference-derived imports are deduplicated together.

Verification


  • px nx run java-ast:test\ (all suites pass; \ComplexExample\ snapshot updated).

Fixes amplication/amplication#9845

Made with Cursor

Writer stored ClassReference instances in a Set, so distinct objects for the same type were not collapsed. Store fully qualified names as strings and merge explicit imports with reference-derived imports in a single Set before rendering.

Fixes amplication/amplication#9845
@singhvishalkr singhvishalkr force-pushed the fix/9845-java-ast-deduplicate-imports branch from 98e7a94 to f07fb6f Compare April 11, 2026 18:18
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.

🐛 Bug Report: @amplication/java-ast duplicates imports when references are used

1 participant