-
Notifications
You must be signed in to change notification settings - Fork 424
Feat/java add explicit imports #5318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/java add explicit imports #5318
Conversation
rewrite-java/src/main/java/org/openrewrite/java/AddExplicitImport.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/style/PreserveImportLayoutStyle.java
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/style/PreserveImportLayoutStyle.java
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/AddExplicitImportTest.java
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/AddExplicitImportTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/style/PreserveImportLayoutStyle.java
Show resolved
Hide resolved
Hmm, we had intentionally not added a recipe for this, as adding an import by itself could lead to then having an unused import. Instead we handle imports from other recipes through a method called Could you describe the use case you see for having an explicit recipe? When would you need this in isolation, or how would you combine this? My worry is having a recipe like this might lead to confusion, and folks adopting this over self contained recipes that handle the imports for the elements they are adding. |
@timtebeek, I agree with you, but when it comes to the For example, I discourage the use of the |
For that wildcard option we have configurable styles: https://docs.openrewrite.org/concepts-and-explanations/styles I have yet to see a convincing case before we merge and maintain this going forward, as I'm afraid folks (and AI assistants) will learn then wrong patterns when they see a recipe like this, and start adding explicit imports through this recipe. |
rewrite-java/src/main/java/org/openrewrite/java/style/PreserveImportLayoutStyle.java
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/style/PreserveImportLayoutStyle.java
Show resolved
Hide resolved
…ort.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ImportLayoutStyle.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ortTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ortTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ort.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
e2758dc
to
38de4b2
Compare
rewrite-java/src/main/java/org/openrewrite/java/style/PreserveImportLayoutStyle.java
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/AddExplicitImportTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/AddExplicitImportTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/AddExplicitImportTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/AddExplicitImportTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
What's changed?
This recipe appends a list of imports to java files.
What's your motivation?
I Added a recipe to append a list of imports to a java file.
I assume that there are already existing recipes to do that, but this one preserves the already existing imports style. In other words, to changes of the recipe do not interfere with the already established imports layout.
It does not order the imports, nor that it groups them in a
star
(*) import style.It inserts the imports and does not check if the compilation unit is using them or not.
It takes care of the static imports as well.
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
@jevanlingen FYI
Have you considered any alternatives or workarounds?
Any additional context
Checklist