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
// from deps on the classpath@Retention(SOURCE)
@interface A {}
// class i'm inspectingclassMyClass {
@ApublicvoidmethodA() {}
}
I would like to be able to determine what the RetentionPolicy being used for @A is. For my particular use case this is necessary to determine whether a dependency is directly referenced in bytecode or not (so that we can fix the deps listed in the pom correctly) but I believe there are many situations where this might be useful.
Describe the solution you'd like
I'm not sure I'm qualified to comment on what the ideal situation would be here, but it would be nice if there was a way to go from a JavaType that represented an annotation to a list of J.Annotations on that annotation rather than just a list of JavaType.Class.
Eg something like
classVisitorimplementsJavaIsoVisitor<ExecutionContext> {
@OverridepublicAnnotationvisitAnnotation(Annotationannotation, ExecutionContextcontext) {
booleanisRetained = annotation.getType()
.getAnnotations()
.stream()
.map(a -> (AnnotationClass)a) // AnnotationClass could be a subtype of JavaType / JavaType.Class that maintains it's args
.filter(a -> a.getFullyQualifiedName().equals("java.lang.annotation.Retention"))
.flatMap(a -> a.getArguments().stream())
.noneMatch(arg -> isSourceRetentionPolicy(arg));
returnsuper.visitAnnotation(annotation, context);
}
privatebooleanisSourceRetention(Expressionarg) {
// check if it's value = RetentionPolicy.SOURCE
}
}
Have you considered any alternatives or workarounds?
The current workaround that I am moving forward with is to pass the classpath urls through from the build to the recipe execution so that a special recipe can use classgraph to find the full class information for the annotations I'm inspecting, but I don't believe this is portable to moderne's saas infrastructure as it requires that all of the dependency jars be available on the local filesystem during recipe execution.
What problem are you trying to solve?
Given a class structure like this
I would like to be able to determine what the
RetentionPolicy
being used for@A
is. For my particular use case this is necessary to determine whether a dependency is directly referenced in bytecode or not (so that we can fix the deps listed in the pom correctly) but I believe there are many situations where this might be useful.Describe the solution you'd like
I'm not sure I'm qualified to comment on what the ideal situation would be here, but it would be nice if there was a way to go from a
JavaType
that represented an annotation to a list ofJ.Annotation
s on that annotation rather than just a list ofJavaType.Class
.Eg something like
Have you considered any alternatives or workarounds?
The current workaround that I am moving forward with is to pass the classpath urls through from the build to the recipe execution so that a special recipe can use classgraph to find the full class information for the annotations I'm inspecting, but I don't believe this is portable to moderne's saas infrastructure as it requires that all of the dependency jars be available on the local filesystem during recipe execution.
Additional context
Related slack conversation: link
Are you interested in contributing this feature to OpenRewrite?
I would be willing to help with this feature but I do not believe I have enough context to propose the best solution here.
The text was updated successfully, but these errors were encountered: