diff options
author | 2019-02-28 12:41:48 +0100 | |
---|---|---|
committer | 2019-02-28 12:46:23 +0100 | |
commit | 02e18ddf13307f276e6fb0a419728ac1141ff849 (patch) | |
tree | 206e9a7cbf8ce7012ccc34be64cda0304c33a84e /tools/apilint | |
parent | d9871b14df27308d2ca159bf7f4f516ec54e2d98 (diff) |
Apilint: report all implemented interfaces and fix false positives
Test: python apilint_test.py
Diffstat (limited to 'tools/apilint')
-rw-r--r-- | tools/apilint/apilint.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py index 643d377c11b6..52707c28286e 100644 --- a/tools/apilint/apilint.py +++ b/tools/apilint/apilint.py @@ -196,8 +196,10 @@ class Class(): if "implements" in raw: self.implements = raw[raw.index("implements")+1] + self.implements_all = [self.implements] else: self.implements = None + self.implements_all = [] else: raise ValueError("Unknown signature format: " + sig_format) @@ -364,12 +366,12 @@ class V2LineParser(object): self.parse_matching_paren("<", ">") extends = self.parse_extends() clazz.extends = extends[0] if extends else None - implements = self.parse_implements() - clazz.implements = implements[0] if implements else None + clazz.implements_all = self.parse_implements() # The checks assume that interfaces are always found in implements, which isn't true for # subinterfaces. - if not implements and "interface" in clazz.split: - clazz.implements = clazz.extends + if not clazz.implements_all and "interface" in clazz.split: + clazz.implements_all = [clazz.extends] + clazz.implements = clazz.implements_all[0] if clazz.implements_all else None self.parse_token("{") self.parse_eof() @@ -1249,6 +1251,7 @@ def verify_boolean(clazz): def verify_collections(clazz): """Verifies that collection types are interfaces.""" if clazz.fullname == "android.os.Bundle": return + if clazz.fullname == "android.os.Parcel": return bad = ["java.util.Vector", "java.util.LinkedList", "java.util.ArrayList", "java.util.Stack", "java.util.HashMap", "java.util.HashSet", "android.util.ArraySet", "android.util.ArrayMap"] @@ -1284,9 +1287,9 @@ def verify_exception(clazz): error(clazz, m, "S1", "Methods must not throw generic exceptions") if t in ["android.os.RemoteException"]: - if clazz.name == "android.content.ContentProviderClient": continue - if clazz.name == "android.os.Binder": continue - if clazz.name == "android.os.IBinder": continue + if clazz.fullname == "android.content.ContentProviderClient": continue + if clazz.fullname == "android.os.Binder": continue + if clazz.fullname == "android.os.IBinder": continue error(clazz, m, "FW9", "Methods calling into system server should rethrow RemoteException as RuntimeException") @@ -1653,8 +1656,8 @@ def verify_units(clazz): def verify_closable(clazz): """Verifies that classes are AutoClosable.""" - if clazz.implements == "java.lang.AutoCloseable": return - if clazz.implements == "java.io.Closeable": return + if "java.lang.AutoCloseable" in clazz.implements_all: return + if "java.io.Closeable" in clazz.implements_all: return for m in clazz.methods: if len(m.args) > 0: continue @@ -1853,6 +1856,9 @@ def verify_clone(clazz): def verify_pfd(clazz): """Verify that android APIs use PFD over FD.""" + if clazz.fullname == "android.os.FileUtils" or clazz.fullname == "android.system.Os": + return + examine = clazz.ctors + clazz.methods for m in examine: if m.typ == "java.io.FileDescriptor": |