Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0681b26d authored by Adrian Roos's avatar Adrian Roos Committed by android-build-merger
Browse files

Merge "apilint: correctly parse enum_constant" am: d8b95307

am: 26ccde4b

Change-Id: I36cc62620029d7a4387705fad441be24f5532673
parents 4678ef6b 26ccde4b
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -297,6 +297,7 @@ class V2Tokenizer(object):
class V2LineParser(object):
    __slots__ = ["tokenized", "current", "len"]

    FIELD_KINDS = ("field", "property", "enum_constant")
    MODIFIERS = set("public protected internal private abstract default static final transient volatile synchronized native operator sealed strictfp infix inline suspend vararg".split())
    JAVA_LANG_TYPES = set("AbstractMethodError AbstractStringBuilder Appendable ArithmeticException ArrayIndexOutOfBoundsException ArrayStoreException AssertionError AutoCloseable Boolean BootstrapMethodError Byte Character CharSequence Class ClassCastException ClassCircularityError ClassFormatError ClassLoader ClassNotFoundException Cloneable CloneNotSupportedException Comparable Compiler Deprecated Double Enum EnumConstantNotPresentException Error Exception ExceptionInInitializerError Float FunctionalInterface IllegalAccessError IllegalAccessException IllegalArgumentException IllegalMonitorStateException IllegalStateException IllegalThreadStateException IncompatibleClassChangeError IndexOutOfBoundsException InheritableThreadLocal InstantiationError InstantiationException Integer InternalError InterruptedException Iterable LinkageError Long Math NegativeArraySizeException NoClassDefFoundError NoSuchFieldError NoSuchFieldException NoSuchMethodError NoSuchMethodException NullPointerException Number NumberFormatException Object OutOfMemoryError Override Package package-info.java Process ProcessBuilder ProcessEnvironment ProcessImpl Readable ReflectiveOperationException Runnable Runtime RuntimeException RuntimePermission SafeVarargs SecurityException SecurityManager Short StackOverflowError StackTraceElement StrictMath String StringBuffer StringBuilder StringIndexOutOfBoundsException SuppressWarnings System Thread ThreadDeath ThreadGroup ThreadLocal Throwable TypeNotPresentException UNIXProcess UnknownError UnsatisfiedLinkError UnsupportedClassVersionError UnsupportedOperationException VerifyError VirtualMachineError Void".split())

@@ -355,7 +356,7 @@ class V2LineParser(object):
        self.parse_eof()

    def parse_into_field(self, field):
        kind = self.parse_one_of("field", "property")
        kind = self.parse_one_of(*V2LineParser.FIELD_KINDS)
        field.split = [kind]
        annotations = self.parse_annotations()
        if "@Deprecated" in annotations:
@@ -591,6 +592,14 @@ def _parse_stream_to_generator(f):
    sig_format = 1

    re_blame = re.compile("^([a-z0-9]{7,}) \(<([^>]+)>.+?\) (.+?)$")

    field_prefixes = map(lambda kind: "    %s" % (kind,), V2LineParser.FIELD_KINDS)
    def startsWithFieldPrefix(raw):
        for prefix in field_prefixes:
            if raw.startswith(prefix):
                return True
        return False

    for raw in f:
        line += 1
        raw = raw.rstrip()
@@ -611,7 +620,7 @@ def _parse_stream_to_generator(f):
            clazz.ctors.append(Method(clazz, line, raw, blame, sig_format=sig_format))
        elif raw.startswith("    method"):
            clazz.methods.append(Method(clazz, line, raw, blame, sig_format=sig_format))
        elif raw.startswith("    field") or raw.startswith("    property"):
        elif startsWithFieldPrefix(raw):
            clazz.fields.append(Field(clazz, line, raw, blame, sig_format=sig_format))
        elif raw.startswith("  }") and clazz:
            yield clazz
+25 −0
Original line number Diff line number Diff line
@@ -143,6 +143,27 @@ class BaseFileTests(unittest.TestCase):
                                      out_classes_with_base=classes_with_base)
        self.assertEquals(map(lambda x: x.fullname, classes_with_base), ["android.app.WallpaperColors"])

class ParseV2Stream(unittest.TestCase):
    def test_field_kinds(self):
        api = apilint._parse_stream("""
// Signature format: 2.0
package android {
  public enum SomeEnum {
    enum_constant public static final android.SomeEnum ENUM_CONST;
    field public static final int FIELD_CONST;
    property public final int someProperty;
    ctor public SomeEnum();
    method public Object? getObject();
  }
}
        """.strip().split('\n'))

        self.assertEquals(api['android.SomeEnum'].fields[0].split[0], 'enum_constant')
        self.assertEquals(api['android.SomeEnum'].fields[1].split[0], 'field')
        self.assertEquals(api['android.SomeEnum'].fields[2].split[0], 'property')
        self.assertEquals(api['android.SomeEnum'].ctors[0].split[0], 'ctor')
        self.assertEquals(api['android.SomeEnum'].methods[0].split[0], 'method')

class V2TokenizerTests(unittest.TestCase):
    def _test(self, raw, expected):
        self.assertEquals(apilint.V2Tokenizer(raw).tokenize(), expected)
@@ -211,6 +232,10 @@ class V2ParserTests(unittest.TestCase):
        self.assertEquals('Interface', cls.implements)
        self.assertEquals('pkg.Some.Name', cls.fullname)

    def test_enum(self):
        cls = self._cls("public enum Some.Name {")
        self._field("enum_constant public static final android.ValueType COLOR;")

    def test_interface(self):
        cls = self._cls("@Deprecated @IntRange(from=1, to=2) public interface Some.Name extends Interface<Class> {")
        self.assertTrue('deprecated' in cls.split)