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

AddOrUpdateAnnotationAttribute not working with nested annotations #4765

Closed
danielshamis opened this issue Dec 10, 2024 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@danielshamis
Copy link
Contributor

I am using

  • Maven plugin v5.46.1

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

<plugin>
   <groupId>org.openrewrite.maven</groupId>
   <artifactId>rewrite-maven-plugin</artifactId>
   <version>5.46.1</version>
   <configuration>
      <exportDatatables>true</exportDatatables>
      <activeRecipes>
         <recipe>test.AddOrUpdateAnnotationAttributeExample</recipe>
      </activeRecipes>
   </configuration>
</plugin>

What is the smallest, simplest way to reproduce the problem?

@Test({
        @TestFunction(name = "a"),
        @TestFunction(name = "b"),
})

What did you expect to see?

@Test({
        @TestFunction(name = "a", value = ""),
        @TestFunction(name = "b", value = ""),
})

What did you see instead?

I am trying to add an attribute to each nested Annotation but no changes are being made. Updating an existing attribute does not work either.

@danielshamis danielshamis added the bug Something isn't working label Dec 10, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Dec 10, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Dec 10, 2024
@timtebeek
Copy link
Contributor

Hi @danielshamis ; Looks like the recipe was missing a call to super.visitAnnotation(..). Would you mind trying our snapshot version in ~15 minutes or so? Sorry that took a while to get to.

@danielshamis
Copy link
Contributor Author

Hi, thank you for your quick response! Unfortunately I can't use external Maven repositories. Furthermore I couldn't find the updated snapshot version in nexus.

To give more context to my issue, I am now using the latest available version of the maven plugin (5.46.2) but the problem persists. I am using declarative yaml format like this to add new attributes:

recipeList:
-org.openrewrite.java.AddOrUpdateAnnotationAttribute:
annotationType:TestFunction
attributeName:value
attributeValue:'""'
addOnly:true
appendArray:false

AddOrUpdateAnnotationAttribute works for single annotations but has no effect on nested annotations. However both ChangeAnnotationAttributeName and RemoveAnnotationAttribute work fine with nested annotations.

Sorry for the trouble!

@timtebeek
Copy link
Contributor

If our snapshot versions aren't an option for you then we'll do another release tomorrow that should pick up this change. Hope that helps!

@danielshamis
Copy link
Contributor Author

I've tried the latest release 5.46.3 with this change, but the issue remains.

@timtebeek
Copy link
Contributor

There's been a bit of a delay getting the latest release out; We'll finally hope to get it out today with new versions of the plugins to follow

@danielshamis
Copy link
Contributor Author

In version 5.47.3 still unresolved unfortunately

@timtebeek
Copy link
Contributor

Hmm, thanks for trying newer versions. Perhaps we'd need to write a unit test for this using the sample you've provided above. Would you mind opening up a draft PR adding a new unit test based on this example? Then we can take it from there.

@Test
void addValueAttribute() {
rewriteRun(
spec -> spec.recipe(new AddOrUpdateAnnotationAttribute("org.example.Foo", null, "hello", null, null)),
java(
"""
package org.example;
public @interface Foo {
String value() default "";
}
"""
),
java(
"""
import org.example.Foo;
@Foo
public class A {
}
""",
"""
import org.example.Foo;
@Foo("hello")
public class A {
}
"""
)
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants