check-flagged-apis: change internal format
Switch the internal format to represent Symbols to (something close to)
the format described in section 4.3.2 of the JVM spec, i.e.
com/android/SomeClass/someMethod(II[Ljava/lang/String;)Z
This will make parsing method parameters from api-versions.xml easier,
as that file already uses this format, and converting API signature
files to the same format is less painful than going in the other
direction.
Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I1e1fb8fe208cd51cce2cc129f5aa1cb495672c16
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 0c078a0..0f2fbef 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 @@
* 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
* <pre>
- * package.class.inner-class.field
- * </pre>
+ * package.class.inner-class.method(II[Landroid/util/Clazz;)
+ * <pre>
+ *
+ * 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 @@
"Bad XML: <field> element without name attribute"
}
val className =
- requireNotNull(field.getParentNode()?.getAttribute("name")) { "Bad XML: top level <field> element" }
+ requireNotNull(field.getParentNode()?.getAttribute("name")) {
+ "Bad XML: top level <field> element"
+ }
output.add(Symbol.create("${className.replace("/", ".")}.$fieldName"))
}