Switch signature_to_elements to use tuple

Previously, it used a structured string of format <type>:<value>. A
tuple is more efficient and less prone to edge cases, such as when the
value is a field signature which itself contains a ":".

Bug: 202154151
Test: m out/soong/hiddenapi/hiddenapi-flags.csv
      atest --host signature_trie_test verify_overlaps_test
      pyformat -s 4 --force_quote_type double -i scripts/hiddenapi/signature_trie*
      /usr/bin/pylint --rcfile $ANDROID_BUILD_TOP/tools/repohooks/tools/pylintrc scripts/hiddenapi/signature_trie*
Change-Id: I80abaff243d98aad325df1b5a655bba7f9d04e2c
This commit is contained in:
Paul Duffin 2022-03-09 14:51:17 +00:00
parent 19255f1d91
commit ea93542e90
2 changed files with 37 additions and 37 deletions

View file

@ -156,16 +156,16 @@ class InteriorNode(Node):
# 3 - class:UnicodeScript
# 4 - member:of(I)Ljava/lang/Character$UnicodeScript;
return list(
chain([f"package:{x}" for x in packages],
[f"class:{x}" for x in classes],
[f"member:{x}" for x in member],
[f"wildcard:{x}" for x in wildcard]))
chain([("package", x) for x in packages],
[("class", x) for x in classes],
[("member", x) for x in member],
[("wildcard", x) for x in wildcard]))
# pylint: enable=line-too-long
@staticmethod
def split_element(element):
element_type, element_value = element.split(":", 1)
element_type, element_value = element
return element_type, element_value
@staticmethod

View file

@ -29,34 +29,34 @@ class TestSignatureToElements(unittest.TestCase):
def test_nested_inner_classes(self):
elements = [
"package:java",
"package:lang",
"class:ProcessBuilder",
"class:Redirect",
"class:1",
"member:<init>()V",
("package", "java"),
("package", "lang"),
("class", "ProcessBuilder"),
("class", "Redirect"),
("class", "1"),
("member", "<init>()V"),
]
signature = "Ljava/lang/ProcessBuilder$Redirect$1;-><init>()V"
self.assertEqual(elements, self.signature_to_elements(signature))
def test_basic_member(self):
elements = [
"package:java",
"package:lang",
"class:Object",
"member:hashCode()I",
("package", "java"),
("package", "lang"),
("class", "Object"),
("member", "hashCode()I"),
]
signature = "Ljava/lang/Object;->hashCode()I"
self.assertEqual(elements, self.signature_to_elements(signature))
def test_double_dollar_class(self):
elements = [
"package:java",
"package:lang",
"class:CharSequence",
"class:",
"class:ExternalSyntheticLambda0",
"member:<init>(Ljava/lang/CharSequence;)V",
("package", "java"),
("package", "lang"),
("class", "CharSequence"),
("class", ""),
("class", "ExternalSyntheticLambda0"),
("member", "<init>(Ljava/lang/CharSequence;)V"),
]
signature = "Ljava/lang/CharSequence$$ExternalSyntheticLambda0;" \
"-><init>(Ljava/lang/CharSequence;)V"
@ -64,43 +64,43 @@ class TestSignatureToElements(unittest.TestCase):
def test_no_member(self):
elements = [
"package:java",
"package:lang",
"class:CharSequence",
"class:",
"class:ExternalSyntheticLambda0",
("package", "java"),
("package", "lang"),
("class", "CharSequence"),
("class", ""),
("class", "ExternalSyntheticLambda0"),
]
signature = "Ljava/lang/CharSequence$$ExternalSyntheticLambda0"
self.assertEqual(elements, self.signature_to_elements(signature))
def test_wildcard(self):
elements = [
"package:java",
"package:lang",
"wildcard:*",
("package", "java"),
("package", "lang"),
("wildcard", "*"),
]
signature = "java/lang/*"
self.assertEqual(elements, self.signature_to_elements(signature))
def test_recursive_wildcard(self):
elements = [
"package:java",
"package:lang",
"wildcard:**",
("package", "java"),
("package", "lang"),
("wildcard", "**"),
]
signature = "java/lang/**"
self.assertEqual(elements, self.signature_to_elements(signature))
def test_no_packages_wildcard(self):
elements = [
"wildcard:*",
("wildcard", "*"),
]
signature = "*"
self.assertEqual(elements, self.signature_to_elements(signature))
def test_no_packages_recursive_wildcard(self):
elements = [
"wildcard:**",
("wildcard", "**"),
]
signature = "**"
self.assertEqual(elements, self.signature_to_elements(signature))
@ -115,9 +115,9 @@ class TestSignatureToElements(unittest.TestCase):
def test_non_standard_class_name(self):
elements = [
"package:javax",
"package:crypto",
"class:extObjectInputStream",
("package", "javax"),
("package", "crypto"),
("class", "extObjectInputStream"),
]
signature = "Ljavax/crypto/extObjectInputStream"
self.assertEqual(elements, self.signature_to_elements(signature))