You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m working on a linter for detecting certain methods in our code base. The linting is based on method annotations. The annotation in question has a value attached which I need for making the linting decision. The method in question is only in the classpath, not part of the source files.
Dependency lib in the classpath:
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface EssentialTracker {
String value();
}
public class TestEssentialTracker {
@EssentialTracker("aaa")
public String getEssentialTracker() {
return "test-essential-tracker";
}
}
Source file input I'm linting:
String result = new TestEssentialTracker().getEssentialTracker();
In this case, I want to be able to access the value "aaa" in the recipe.
Preserve the annotation value pairs in the parsed LST.
Have you considered any alternatives or workarounds?
I don't think there is a workaround with OpenRewrite. I worked around in my solution by loading all classes and use reflection to inspect the actual annotation values, which is a bit cumbersome.
What problem are you trying to solve?
I’m working on a linter for detecting certain methods in our code base. The linting is based on method annotations. The annotation in question has a value attached which I need for making the linting decision. The method in question is only in the classpath, not part of the source files.
Dependency lib in the classpath:
Source file input I'm linting:
In this case, I want to be able to access the value "aaa" in the recipe.
I did some experiments. It seems in the recipe I can access the annotation type but not the “value” because it was converted into
JavaType.FullyQualified
here without knowledge of the value: https://github.com/openrewrite/rewrite/blob/main/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java#L696Describe the solution you'd like
Preserve the annotation value pairs in the parsed LST.
Have you considered any alternatives or workarounds?
I don't think there is a workaround with OpenRewrite. I worked around in my solution by loading all classes and use reflection to inspect the actual annotation values, which is a bit cumbersome.
Additional context
n/a
Are you interested in contributing this feature to OpenRewrite?
Yes, here is the patch I worked on. I don't have good understanding of OpenRewrite implementation holistically though, would love your feedback.
The text was updated successfully, but these errors were encountered: