Skip to content

Commit

Permalink
8336942: Improve test coverage for class loading elements with annota…
Browse files Browse the repository at this point in the history
…tions of different retentions
  • Loading branch information
cushon committed Jul 22, 2024
1 parent e3acf4c commit 2b6d50b
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
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;
Expand Down Expand Up @@ -94,12 +96,14 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
Map.ofEntries(new NameToAnnotationEntry("java.lang.Override", Override.class),
new NameToAnnotationEntry("java.lang.annotation.Repeatable", Repeatable.class),
new NameToAnnotationEntry("java.lang.annotation.Target", Target.class),
new NameToAnnotationEntry("java.lang.annotation.Retention", 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) {
Expand Down Expand Up @@ -520,6 +524,12 @@ R scan(Iterable<? extends TypeMirror> iter, P p) {
TC[] value();
}

@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TD {
int value();
}

// Test cases

// TODO: add more cases for arrays
Expand Down Expand Up @@ -657,6 +667,10 @@ public class Inner6<T extends Object & Cloneable & @TA(17) Serializable> {}
@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")
Expand Down

0 comments on commit 2b6d50b

Please sign in to comment.