Merge "apilint: Allow parsing 3.0 signature files"
This commit is contained in:
@@ -223,6 +223,7 @@ class Package():
|
|||||||
class V2Tokenizer(object):
|
class V2Tokenizer(object):
|
||||||
__slots__ = ["raw"]
|
__slots__ = ["raw"]
|
||||||
|
|
||||||
|
SIGNATURE_PREFIX = "// Signature format: "
|
||||||
DELIMITER = re.compile(r'\s+|[()@<>;,={}/"!?]|\[\]|\.\.\.')
|
DELIMITER = re.compile(r'\s+|[()@<>;,={}/"!?]|\[\]|\.\.\.')
|
||||||
STRING_SPECIAL = re.compile(r'["\\]')
|
STRING_SPECIAL = re.compile(r'["\\]')
|
||||||
|
|
||||||
@@ -610,8 +611,12 @@ def _parse_stream_to_generator(f):
|
|||||||
else:
|
else:
|
||||||
blame = None
|
blame = None
|
||||||
|
|
||||||
if line == 1 and raw == "// Signature format: 2.0":
|
if line == 1 and raw.startswith("// Signature format: "):
|
||||||
sig_format = 2
|
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"):
|
elif raw.startswith("package"):
|
||||||
pkg = Package(line, raw, blame)
|
pkg = Package(line, raw, blame)
|
||||||
elif raw.startswith(" ") and raw.endswith("{"):
|
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'].ctors[0].split[0], 'ctor')
|
||||||
self.assertEquals(api['android.SomeEnum'].methods[0].split[0], 'method')
|
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):
|
class V2TokenizerTests(unittest.TestCase):
|
||||||
def _test(self, raw, expected):
|
def _test(self, raw, expected):
|
||||||
self.assertEquals(apilint.V2Tokenizer(raw).tokenize(), expected)
|
self.assertEquals(apilint.V2Tokenizer(raw).tokenize(), expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user