Skip to content

feat: add java importing pattern util#260

Merged
morgante merged 3 commits intobiomejs:mainfrom
caiuswang:feature/add-java-import
Dec 1, 2025
Merged

feat: add java importing pattern util#260
morgante merged 3 commits intobiomejs:mainfrom
caiuswang:feature/add-java-import

Conversation

@caiuswang
Copy link
Contributor

Which problem is this PR solving?

Add java importing patterns, inclues:

  • remove_duplicate_import_statements
  • ensure_import_statement
  • replace_import_statement
  • remove_import_statement

Short description of the changes

  • Add java importing paterns

How to verify that this has the expected result

  • Tests are including in commit: _test_java_imports

Copy link
Collaborator

@morgante morgante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

private pattern before_each_file_stdlib() {
file($body) where {
$body <: init_vars(),
$body <: init_import()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd match this directly against accumulate_all_imports:

Suggested change
$body <: init_import()
$body <: $maybe contains bubble import_declaration() as $this_import where {
$GLOBAL_EXIST_IMPORTS += text(`$this_import`),
},

private pattern accumulate_all_imports() {
$_ where {
$program <: maybe contains bubble() import_declaration() as $this_import where {
$GLOBAL_EXIST_IMPORTS += text(`$this_import`),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use text here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall that you previously mentioned that using some will match all instances of the pattern in discord. Therefore, I opted for a safer approach to address the issue. So it would implementing a code-based solution offer better performance?
image

@morgante
Copy link
Collaborator

FYI the linter is failing, you need to format files with grit format.

* inline unnecessary second call
* add short-circuit
@caiuswang caiuswang force-pushed the feature/add-java-import branch from 0414902 to 8fb3e0c Compare November 22, 2025 15:06
@morgante morgante merged commit 42d432f into biomejs:main Dec 1, 2025
4 checks passed
@caiuswang caiuswang deleted the feature/add-java-import branch December 2, 2025 05: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.

2 participants