Add test showing type annotations don't appear in stubs
(Or signature files)
This is because the PsiTypePrinter only includes type use annotations
if the constant `SUPPORT_TYPE_USE_ANNOTATIONS` is true, which it isn't.
This wil be updated in followup CLs to allow printing the annotations
in signature files, but to leave the status quo in stubs for now.
Bug: 311619997
Test: Added test
Change-Id: Idb440b2f44d7045f902552c9e168cf85815d9e84
diff --git a/metalava/src/test/java/com/android/tools/metalava/stub/StubsTest.kt b/metalava/src/test/java/com/android/tools/metalava/stub/StubsTest.kt
index f565b74..feb9f20 100644
--- a/metalava/src/test/java/com/android/tools/metalava/stub/StubsTest.kt
+++ b/metalava/src/test/java/com/android/tools/metalava/stub/StubsTest.kt
@@ -1654,4 +1654,76 @@
),
)
}
+
+ @Test
+ fun `Type-use annotations are not included in stubs`() {
+ check(
+ sourceFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+ @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE)
+ public @interface TypeAnnotation {}
+ """
+ ),
+ java(
+ """
+ package test.pkg;
+ @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD)
+ public @interface MethodAnnotation {}
+ """
+ ),
+ java(
+ """
+ package test.pkg;
+ @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.TYPE_USE})
+ public @interface MethodAndTypeAnnotation {}
+ """
+ ),
+ java(
+ """
+ package test.pkg;
+ import java.util.List;
+ public class Foo {
+ @MethodAnnotation
+ @MethodAndTypeAnnotation
+ public @TypeAnnotation List<@TypeAnnotation String> foo() {}
+ }
+ """
+ )
+ ),
+ stubFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+ @SuppressWarnings({"unchecked", "deprecation", "all"})
+ public class Foo {
+ public Foo() { throw new RuntimeException("Stub!"); }
+ @test.pkg.MethodAndTypeAnnotation
+ @test.pkg.MethodAnnotation
+ public java.util.List<java.lang.String> foo() { throw new RuntimeException("Stub!"); }
+ }
+ """
+ )
+ ),
+ format = FileFormat.V2,
+ api =
+ """
+ package test.pkg {
+ public class Foo {
+ ctor public Foo();
+ method @test.pkg.MethodAndTypeAnnotation @test.pkg.MethodAnnotation public java.util.List<java.lang.String> foo();
+ }
+ @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.TYPE_USE}) public @interface MethodAndTypeAnnotation {
+ }
+ @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface MethodAnnotation {
+ }
+ @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) public @interface TypeAnnotation {
+ }
+ }
+ """
+ )
+ }
}