Merge "apilint: Allow parsing 3.0 signature files"
am: 34b11c92b3
Change-Id: I0cc45b11f079c7a0d383b49e74d55658a8915d71
This commit is contained in:
@@ -223,6 +223,7 @@ class Package():
|
||||
class V2Tokenizer(object):
|
||||
__slots__ = ["raw"]
|
||||
|
||||
SIGNATURE_PREFIX = "// Signature format: "
|
||||
DELIMITER = re.compile(r'\s+|[()@<>;,={}/"!?]|\[\]|\.\.\.')
|
||||
STRING_SPECIAL = re.compile(r'["\\]')
|
||||
|
||||
@@ -610,8 +611,12 @@ def _parse_stream_to_generator(f):
|
||||
else:
|
||||
blame = None
|
||||
|
||||
if line == 1 and raw == "// Signature format: 2.0":
|
||||
sig_format = 2
|
||||
if line == 1 and raw.startswith("// Signature format: "):
|
||||
sig_format_string = raw[len(V2Tokenizer.SIGNATURE_PREFIX):]
|
||||
if sig_format_string in ["2.0", "3.0"]:
|
||||
sig_format = 2
|
||||
else:
|
||||
raise ValueError("Unknown format: %s" % (sig_format_string,))
|
||||
elif raw.startswith("package"):
|
||||
pkg = Package(line, raw, blame)
|
||||
elif raw.startswith(" ") and raw.endswith("{"):
|
||||
|
||||
@@ -164,6 +164,23 @@ package android {
|
||||
self.assertEquals(api['android.SomeEnum'].ctors[0].split[0], 'ctor')
|
||||
self.assertEquals(api['android.SomeEnum'].methods[0].split[0], 'method')
|
||||
|
||||
class ParseV3Stream(unittest.TestCase):
|
||||
def test_field_kinds(self):
|
||||
api = apilint._parse_stream("""
|
||||
// Signature format: 3.0
|
||||
package a {
|
||||
|
||||
public final class ContextKt {
|
||||
method public static inline <reified T> T! getSystemService(android.content.Context);
|
||||
method public static inline void withStyledAttributes(android.content.Context, android.util.AttributeSet? set = null, int[] attrs, @AttrRes int defStyleAttr = 0, @StyleRes int defStyleRes = 0, kotlin.jvm.functions.Function1<? super android.content.res.TypedArray,kotlin.Unit> block);
|
||||
}
|
||||
}
|
||||
""".strip().split('\n'))
|
||||
self.assertEquals(api['a.ContextKt'].methods[0].name, 'getSystemService')
|
||||
self.assertEquals(api['a.ContextKt'].methods[0].split[:4], ['method', 'public', 'static', 'inline'])
|
||||
self.assertEquals(api['a.ContextKt'].methods[1].name, 'withStyledAttributes')
|
||||
self.assertEquals(api['a.ContextKt'].methods[1].split[:4], ['method', 'public', 'static', 'inline'])
|
||||
|
||||
class V2TokenizerTests(unittest.TestCase):
|
||||
def _test(self, raw, expected):
|
||||
self.assertEquals(apilint.V2Tokenizer(raw).tokenize(), expected)
|
||||
|
||||
Reference in New Issue
Block a user