Snap for 12373988 from ae85ba72e9a8fe78bbb15afe1855214228e78fda to 24Q4-release
Change-Id: Ifdbc4c5e41c6f0349c4e7e834b7e275083b6bf0a
diff --git a/metalava-model/src/main/java/com/android/tools/metalava/model/ModifierListWriter.kt b/metalava-model/src/main/java/com/android/tools/metalava/model/ModifierListWriter.kt
index d9234a8..97b9f09 100644
--- a/metalava-model/src/main/java/com/android/tools/metalava/model/ModifierListWriter.kt
+++ b/metalava-model/src/main/java/com/android/tools/metalava/model/ModifierListWriter.kt
@@ -254,11 +254,6 @@
// Do not write @Deprecated for a parameter unless it was explicitly marked
// as deprecated.
item is ParameterItem -> item.originallyDeprecated
- // Do not write @Deprecated for a field if it was inherited from another class
- // and was not explicitly qualified.
- item is FieldItem ->
- if (item.inheritedFromAncestor) item.originallyDeprecated
- else item.effectivelyDeprecated
else -> item.effectivelyDeprecated
}
if (writeDeprecated) {
diff --git a/metalava/src/test/java/com/android/tools/metalava/DeprecatedTestCase.kt b/metalava/src/test/java/com/android/tools/metalava/DeprecatedTestCase.kt
index 4f44a34..a4d786b 100644
--- a/metalava/src/test/java/com/android/tools/metalava/DeprecatedTestCase.kt
+++ b/metalava/src/test/java/com/android/tools/metalava/DeprecatedTestCase.kt
@@ -50,11 +50,141 @@
}
}
""",
+ stubFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+ /** @deprecated */
+ @SuppressWarnings({"unchecked", "deprecation", "all"})
+ @Deprecated
+ public class Foo {
+ @Deprecated
+ public Foo(int p1, @Deprecated int p2) { throw new RuntimeException("Stub!"); }
+ @Deprecated
+ public void method(int p1, @Deprecated int p2) { throw new RuntimeException("Stub!"); }
+ }
+ """
+ )
+ ),
)
}
@Test
- fun `Test deprecated not written out for field inherited from hidden class`() {
+ fun `Test deprecated is not written out for field inherited from deprecated hidden class`() {
+ // Makes sure that deprecated status is not copied when the inherited field is only
+ // deprecated implicitly because it is contained with a class that is deprecated.
+ check(
+ sourceFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+
+ /** @deprecated */
+ @Deprecated
+ interface Constants {
+ int INHERITED = 0;
+ }
+ """
+ ),
+ java(
+ """
+ package test.pkg;
+
+ public class Foo implements Constants {
+ private Foo() {}
+ public static final int CONSTANT = 1;
+ }
+ """
+ ),
+ ),
+ api =
+ """
+ // Signature format: 5.0
+ package test.pkg {
+ public class Foo {
+ field public static final int CONSTANT = 1; // 0x1
+ field public static final int INHERITED = 0; // 0x0
+ }
+ }
+ """,
+ stubFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+ @SuppressWarnings({"unchecked", "deprecation", "all"})
+ public class Foo {
+ Foo() { throw new RuntimeException("Stub!"); }
+ public static final int CONSTANT = 1; // 0x1
+ public static final int INHERITED = 0; // 0x0
+ }
+ """
+ )
+ ),
+ )
+ }
+
+ @Test
+ fun `Test deprecated is written out for deprecated field inherited from hidden class`() {
+ // Makes sure that deprecated status is copied when the inherited field is explicitly
+ // deprecated.
+ check(
+ sourceFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+
+ interface Constants {
+ /** @deprecated */
+ @Deprecated
+ int INHERITED = 0;
+ }
+ """
+ ),
+ java(
+ """
+ package test.pkg;
+
+ public class Foo implements Constants {
+ private Foo() {}
+ public static final int CONSTANT = 1;
+ }
+ """
+ ),
+ ),
+ api =
+ """
+ // Signature format: 5.0
+ package test.pkg {
+ public class Foo {
+ field public static final int CONSTANT = 1; // 0x1
+ field @Deprecated public static final int INHERITED = 0; // 0x0
+ }
+ }
+ """,
+ stubFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+ @SuppressWarnings({"unchecked", "deprecation", "all"})
+ public class Foo {
+ Foo() { throw new RuntimeException("Stub!"); }
+ public static final int CONSTANT = 1; // 0x1
+ /** @deprecated */
+ @Deprecated public static final int INHERITED = 0; // 0x0
+ }
+ """
+ )
+ ),
+ )
+ }
+
+ @Test
+ fun `Test deprecated is written out for field inherited into deprecated class from hidden class`() {
check(
sourceFiles =
arrayOf(
@@ -86,10 +216,27 @@
package test.pkg {
@Deprecated public class Foo {
field @Deprecated public static final int CONSTANT = 1; // 0x1
- field public static final int INHERITED = 0; // 0x0
+ field @Deprecated public static final int INHERITED = 0; // 0x0
}
}
""",
+ stubFiles =
+ arrayOf(
+ java(
+ """
+ package test.pkg;
+ /** @deprecated */
+ @SuppressWarnings({"unchecked", "deprecation", "all"})
+ @Deprecated
+ public class Foo {
+ @Deprecated
+ Foo() { throw new RuntimeException("Stub!"); }
+ @Deprecated public static final int CONSTANT = 1; // 0x1
+ @Deprecated public static final int INHERITED = 0; // 0x0
+ }
+ """
+ )
+ ),
)
}
@@ -143,6 +290,7 @@
api = """
// Signature format: 5.0
""",
+ stubPaths = emptyArray(),
)
}
}