From fc13e8938762ec7709282ca95f8f3e13ff51d24e Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Thu, 25 Jul 2019 20:24:46 -0700 Subject: [PATCH] Support nested arrays and VarArgs in Type. --- apilint/src/main/resources/apilint.py | 10 ++++++++-- .../apilint_test/test-built-in-types-allowed.txt | 12 ++++++++++++ apilint/src/test/resources/apilint_test/tests.json | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 apilint/src/test/resources/apilint_test/test-built-in-types-allowed.txt diff --git a/apilint/src/main/resources/apilint.py b/apilint/src/main/resources/apilint.py index 619c007..eb37bbf 100644 --- a/apilint/src/main/resources/apilint.py +++ b/apilint/src/main/resources/apilint.py @@ -240,12 +240,18 @@ def __init__(self, clazz, source, raw, location, blame, imports): else: self.generics = [] + self.is_array = False + self.is_var_arg = False if raw.endswith("[]"): - self.name = self.resolve(raw[:-2], imports) + while raw.endswith("[]"): + raw = raw[:-2] + self.name = self.resolve(raw, imports) self.is_array = True + elif raw.endswith("..."): + self.name = self.resolve(raw[:-3], imports) + self.is_var_arg = True else: self.name = self.resolve(raw, imports) - self.is_array = False def resolve(self, name, imports): # Never resolve primitive types diff --git a/apilint/src/test/resources/apilint_test/test-built-in-types-allowed.txt b/apilint/src/test/resources/apilint_test/test-built-in-types-allowed.txt new file mode 100644 index 0000000..47b65ab --- /dev/null +++ b/apilint/src/test/resources/apilint_test/test-built-in-types-allowed.txt @@ -0,0 +1,12 @@ +package test { + public class TestClass { + method public long testLong(); + method public int testInt(); + method public void testIntParam(int); + method public void testIntParamVarArg(int...); + method public long[] testLongArray(); + method public long[][] testLongArrayArray(); + method public long[][][] testLongArrayArrayArray(); + } +} + diff --git a/apilint/src/test/resources/apilint_test/tests.json b/apilint/src/test/resources/apilint_test/tests.json index 462af8c..ccc538a 100644 --- a/apilint/src/test/resources/apilint_test/tests.json +++ b/apilint/src/test/resources/apilint_test/tests.json @@ -80,6 +80,12 @@ "check_compat": false, "filter": "GV", "allowed_packages": ["test"] + },{ + "test": "test-built-in-types-allowed", + "expected": "SUCCESS", + "check_compat": false, + "filter": "GV7", + "allowed_packages": ["test"] },{ "test": "test-fields-only-class", "expected": "API_ERROR",