Skip to content
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

Allow AddOrUpdateAnnotationAttribute to add values to an array #4157

Open
timtebeek opened this issue Apr 29, 2024 · 1 comment
Open

Allow AddOrUpdateAnnotationAttribute to add values to an array #4157

timtebeek opened this issue Apr 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@timtebeek
Copy link
Contributor

What problem are you trying to solve?

AddOrUpdateAnnotationAttribute can not currently add values to an array. When you try that you get

ClassCastException: class org.openrewrite.java.tree.J$NewArray cannot be cast to class org.openrewrite.java.tree.J$Literal

Describe the solution you'd like

To be able to add a value as seen here

Before

@SpringBootApplication(scanBasePackages = {"com.abc"})

After

@SpringBootApplication(scanBasePackages = {"com.abc", "com.xyz"})

Have you considered any alternatives or workarounds?

We could create a new recipe, or explicitly not allow this.
Not clear yet if we should append to existing array, or overwrite existing value.

@timtebeek timtebeek added the enhancement New feature or request label Apr 29, 2024
@timtebeek
Copy link
Contributor Author

From further discussion duplicates should be prevented; append when element is not already present.
For removal of elements a similar change can be made to the remove attribute from annotation recipe.

public class RemoveAnnotationAttribute extends Recipe {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

1 participant