diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt index 0569bfd71b..04c2f80e79 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt @@ -89,11 +89,11 @@ class CheckFlaggedApisTest { fun testParseApiSignature() { val expected = setOf( - Pair(Symbol("android.Clazz"), Flag("android.flag.foo")), - Pair(Symbol("android.Clazz.Clazz()"), Flag("android.flag.foo")), - Pair(Symbol("android.Clazz.FOO"), Flag("android.flag.foo")), - Pair(Symbol("android.Clazz.getErrorCode()"), Flag("android.flag.foo")), - Pair(Symbol("android.Clazz.Builder"), Flag("android.flag.bar")), + Pair(Symbol("android/Clazz"), Flag("android.flag.foo")), + Pair(Symbol("android/Clazz/Clazz()"), Flag("android.flag.foo")), + Pair(Symbol("android/Clazz/FOO"), Flag("android.flag.foo")), + Pair(Symbol("android/Clazz/getErrorCode()"), Flag("android.flag.foo")), + Pair(Symbol("android/Clazz/Builder"), Flag("android.flag.bar")), ) val actual = parseApiSignature("in-memory", API_SIGNATURE.byteInputStream()) assertEquals(expected, actual) @@ -111,11 +111,11 @@ class CheckFlaggedApisTest { fun testParseApiVersions() { val expected: Set = setOf( - Symbol("android.Clazz"), - Symbol("android.Clazz.Clazz()"), - Symbol("android.Clazz.FOO"), - Symbol("android.Clazz.getErrorCode()"), - Symbol("android.Clazz.Builder"), + Symbol("android/Clazz"), + Symbol("android/Clazz/Clazz()"), + Symbol("android/Clazz/FOO"), + Symbol("android/Clazz/getErrorCode()"), + Symbol("android/Clazz/Builder"), ) val actual = parseApiVersions(API_VERSIONS.byteInputStream()) assertEquals(expected, actual) @@ -136,14 +136,14 @@ class CheckFlaggedApisTest { fun testFindErrorsDisabledFlaggedApiIsPresent() { val expected = setOf( - DisabledFlaggedApiIsPresentError(Symbol("android.Clazz"), Flag("android.flag.foo")), + DisabledFlaggedApiIsPresentError(Symbol("android/Clazz"), Flag("android.flag.foo")), DisabledFlaggedApiIsPresentError( - Symbol("android.Clazz.Clazz()"), Flag("android.flag.foo")), - DisabledFlaggedApiIsPresentError(Symbol("android.Clazz.FOO"), Flag("android.flag.foo")), + Symbol("android/Clazz/Clazz()"), Flag("android.flag.foo")), + DisabledFlaggedApiIsPresentError(Symbol("android/Clazz/FOO"), Flag("android.flag.foo")), DisabledFlaggedApiIsPresentError( - Symbol("android.Clazz.getErrorCode()"), Flag("android.flag.foo")), + Symbol("android/Clazz/getErrorCode()"), Flag("android.flag.foo")), DisabledFlaggedApiIsPresentError( - Symbol("android.Clazz.Builder"), Flag("android.flag.bar")), + Symbol("android/Clazz/Builder"), Flag("android.flag.bar")), ) val actual = findErrors( diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt index 0c078a0b93..0f2fbef719 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt @@ -41,21 +41,29 @@ import org.w3c.dom.Node * a Java symbol slightly differently. To keep things consistent, all parsed APIs are converted to * Symbols. * - * All parts of the fully qualified name of the Symbol are separated by a dot, e.g.: + * Symbols are encoded using the format similar to the one described in section 4.3.2 of the JVM + * spec [1], that is, "package.class.inner-class.method(int, int[], android.util.Clazz)" is + * represented as *
- *   package.class.inner-class.field
- * 
+ * package.class.inner-class.method(II[Landroid/util/Clazz;) + *
+ *
+ * Where possible, the format has been simplified (to make translation of the
+ * various input formats easier): for instance, only / is used as delimiter (#
+ * and $ are never used).
+ *
+ * 1. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.2
  */
 @JvmInline
 internal value class Symbol(val name: String) {
   companion object {
-    private val FORBIDDEN_CHARS = listOf('#', '$')
+    private val FORBIDDEN_CHARS = listOf('#', '$', '.')
 
     /** Create a new Symbol from a String that may include delimiters other than dot. */
     fun create(name: String): Symbol {
       var sanitizedName = name
       for (ch in FORBIDDEN_CHARS) {
-        sanitizedName = sanitizedName.replace(ch, '.')
+        sanitizedName = sanitizedName.replace(ch, '/')
       }
       return Symbol(sanitizedName)
     }
@@ -255,7 +263,9 @@ internal fun parseApiVersions(input: InputStream): Set {
           "Bad XML:  element without name attribute"
         }
     val className =
-        requireNotNull(field.getParentNode()?.getAttribute("name")) { "Bad XML: top level  element" }
+        requireNotNull(field.getParentNode()?.getAttribute("name")) {
+          "Bad XML: top level  element"
+        }
     output.add(Symbol.create("${className.replace("/", ".")}.$fieldName"))
   }