rewrite
rewrite copied to clipboard
Allow `AddOrUpdateAnnotationAttribute` to add values to an array
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.
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. https://github.com/openrewrite/rewrite/blob/bf4dcfe8a4656f089b8de75a56263f7669950b74/rewrite-java/src/main/java/org/openrewrite/java/RemoveAnnotationAttribute.java#L29