diff options
author | Mårten Kongstad <amhk@google.com> | 2024-05-06 10:28:02 +0200 |
---|---|---|
committer | Mårten Kongstad <amhk@google.com> | 2024-05-07 13:16:13 +0200 |
commit | 02525a88deeb23ead4edcb26ac6d27e1f2859374 (patch) | |
tree | 76598f053df72dd1386008901eb8f6b520c03e58 | |
parent | 5a99056218e4baa26de4d7ee1f0f53b2bd7a3b8d (diff) | |
download | build-02525a88deeb23ead4edcb26ac6d27e1f2859374.tar.gz |
check-flagged-apis: api-versions.xml: correctly parse nested class ctor
The constructor of a nested class is represented as follows in
api-versions.xml:
<class name="android/Clazz$Foo$Bar" since="1">
<method name="<init>()V"/>
</class>
The nested dollar signs are not replaced by forward slashes before the
parsing logic uses `split("/")` to find the name of the inner-most
class, incorrectly resulting in `Class$Foo$Bar` instead of `Bar`. Fix
this by immediately replacing dollar signs with forward slashes after
extracting the package and class.
Also clean up the following call of `Symbol.create`.
Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I8c0619faae90ded7eb14dcc20ecb94a086a1c764
-rw-r--r-- | tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt | 21 | ||||
-rw-r--r-- | tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt | 7 |
2 files changed, 25 insertions, 3 deletions
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 2f76b2a5a7..1f36a640dc 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt @@ -140,6 +140,27 @@ class CheckFlaggedApisTest { } @Test + fun testParseApiVersionsNestedClasses() { + val apiVersions = + """ + <?xml version="1.0" encoding="utf-8"?> + <api version="3"> + <class name="android/Clazz${'$'}Foo${'$'}Bar" since="1"> + <method name="<init>()V"/> + </class> + </api> + """ + .trim() + val expected: Set<Symbol> = + setOf( + Symbol("android/Clazz/Foo/Bar"), + Symbol("android/Clazz/Foo/Bar/Bar()"), + ) + val actual = parseApiVersions(apiVersions.byteInputStream()) + assertEquals(expected, actual) + } + + @Test fun testFindErrorsNoErrors() { val expected = setOf<ApiError>() val actual = 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 e8b1b65fce..4e7335756f 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt @@ -279,12 +279,13 @@ internal fun parseApiVersions(input: InputStream): Set<Symbol> { var (methodName, methodArgs, _) = methodSignatureParts val packageAndClassName = requireNotNull(method.getParentNode()?.getAttribute("name")) { - "Bad XML: top level <method> element, or <class> element missing name attribute" - } + "Bad XML: top level <method> element, or <class> element missing name attribute" + } + .replace("$", "/") if (methodName == "<init>") { methodName = packageAndClassName.split("/").last() } - output.add(Symbol.create("${packageAndClassName.replace("/", ".")}.$methodName($methodArgs)")) + output.add(Symbol.create("$packageAndClassName/$methodName($methodArgs)")) } return output |