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

Closed
timtebeek opened this issue Apr 29, 2024 · 1 comment · Fixed by #4667
Closed

Allow AddOrUpdateAnnotationAttribute to add values to an array #4157

timtebeek opened this issue Apr 29, 2024 · 1 comment · Fixed by #4667
Assignees
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 timtebeek moved this to Backlog in OpenRewrite 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 {

@nielsdebruin nielsdebruin self-assigned this Nov 13, 2024
@nielsdebruin nielsdebruin linked a pull request Nov 13, 2024 that will close this issue
3 tasks
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Nov 19, 2024
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
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants