8336942: Improve test coverage for class loading elements with annotations of different retentions

Reviewed-by: vromero
This commit is contained in:
Liam Miller-Cushon 2024-09-26 15:11:03 +00:00
parent 95d3e9d199
commit e36ce5f034

View File

@ -41,6 +41,8 @@ import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -93,13 +95,15 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
private static final Map<String, Class<? extends Annotation>> nameToAnnotation =
Map.ofEntries(new NameToAnnotationEntry("java.lang.Override", Override.class),
new NameToAnnotationEntry("java.lang.annotation.Repeatable", Repeatable.class),
new NameToAnnotationEntry("java.lang.annotation.Retention", Target.class),
new NameToAnnotationEntry("java.lang.annotation.Target", Target.class),
new NameToAnnotationEntry("BasicAnnoTests.Test", BasicAnnoTests.Test.class),
new NameToAnnotationEntry("BasicAnnoTests.Tests",BasicAnnoTests.Tests.class),
new NameToAnnotationEntry("BasicAnnoTests.TA", BasicAnnoTests.TA.class),
new NameToAnnotationEntry("BasicAnnoTests.TB", BasicAnnoTests.TB.class),
new NameToAnnotationEntry("BasicAnnoTests.TC", BasicAnnoTests.TC.class),
new NameToAnnotationEntry("BasicAnnoTests.TCs", BasicAnnoTests.TCs.class));
new NameToAnnotationEntry("BasicAnnoTests.TCs", BasicAnnoTests.TCs.class),
new NameToAnnotationEntry("BasicAnnoTests.TD", BasicAnnoTests.TD.class));
static class NameToAnnotationEntry extends AbstractMap.SimpleEntry<String, Class<? extends Annotation>> {
public NameToAnnotationEntry(String key, Class<? extends Annotation> entry) {
@ -520,6 +524,12 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
TC[] value();
}
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TD {
int value();
}
// Test cases
// TODO: add more cases for arrays
@ -657,6 +667,10 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
@Test(posn=1, annoType=TA.class, expect="23")
public Set<@TA(23) ? super Object> f9;
@Test(posn=0, annoType=TA.class, expect="1")
@Test(posn=0, annoType=TD.class, expect="2")
public @TA(1) @TD(2) int f10;
// Test type use annotations on uses of type variables
@Test(posn=6, annoType = TA.class, expect = "25")
@Test(posn=6, annoType = TB.class, expect = "26")