-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
8u201
-
x86
-
os_x
A DESCRIPTION OF THE PROBLEM :
Given an annotation processor processing an ElementKind.CLASS. The class being processed has an annotation on a type parameter bound. The processor tries to get all type parameter annotations via calling getAnnotationMirrors() on each element returned by TypeElement#getTypeParameters().getTypeParameters(), however, CLASS_TYPE_PARAMETER_BOUND annotations are not returned.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Write a trivial annotation processor and corresponding trivial annotation. The annotation processor need only output the number of entries returned by getTypeParameters(). Create another annotation that has a target of (at least) ElementType.TYPE_USE and use it to annotate a class that has type bound parameter.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling getAnnotationMirrors() on each element returned by getTypeParameters() should return the type bound parameter annotation mirror
ACTUAL -
They are not returned
---------- BEGIN SOURCE ----------
// a trivial annotation processor
@SupportedAnnotationTypes("name here")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class TestProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment environment) {
annotations.forEach(annotation -> {
Set<? extends Element> elementsAnnotatedWith = environment.getElementsAnnotatedWith(annotation);
elementsAnnotatedWith.forEach(element -> {
if (element.getKind() == ElementKind.CLASS) {
TypeElement typeElement = (TypeElement) element;
List<? extends TypeParameterElement> typeParameters = typeElement.getTypeParameters();
typeParameters.forEach(p -> processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Found: " + p.getAnnotationMirrors().size()));
}
});
});
return true;
}
}
// the annotation to use for processing
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface TestProcessorAnnotation {
}
// the annotation to use on the class
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface TestAnnotation {
}
// the class
@TestProcessorAnnotation
public class Test<T extends @TestAnnotation List> {
}
---------- END SOURCE ----------
FREQUENCY : always
Given an annotation processor processing an ElementKind.CLASS. The class being processed has an annotation on a type parameter bound. The processor tries to get all type parameter annotations via calling getAnnotationMirrors() on each element returned by TypeElement#getTypeParameters().getTypeParameters(), however, CLASS_TYPE_PARAMETER_BOUND annotations are not returned.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Write a trivial annotation processor and corresponding trivial annotation. The annotation processor need only output the number of entries returned by getTypeParameters(). Create another annotation that has a target of (at least) ElementType.TYPE_USE and use it to annotate a class that has type bound parameter.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling getAnnotationMirrors() on each element returned by getTypeParameters() should return the type bound parameter annotation mirror
ACTUAL -
They are not returned
---------- BEGIN SOURCE ----------
// a trivial annotation processor
@SupportedAnnotationTypes("name here")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class TestProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment environment) {
annotations.forEach(annotation -> {
Set<? extends Element> elementsAnnotatedWith = environment.getElementsAnnotatedWith(annotation);
elementsAnnotatedWith.forEach(element -> {
if (element.getKind() == ElementKind.CLASS) {
TypeElement typeElement = (TypeElement) element;
List<? extends TypeParameterElement> typeParameters = typeElement.getTypeParameters();
typeParameters.forEach(p -> processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Found: " + p.getAnnotationMirrors().size()));
}
});
});
return true;
}
}
// the annotation to use for processing
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface TestProcessorAnnotation {
}
// the annotation to use on the class
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface TestAnnotation {
}
// the class
@TestProcessorAnnotation
public class Test<T extends @TestAnnotation List> {
}
---------- END SOURCE ----------
FREQUENCY : always