OSDN Git Service

Apilint: lint for URL/URI
authorAdrian Roos <roosa@google.com>
Thu, 28 Feb 2019 11:45:00 +0000 (12:45 +0100)
committerAdrian Roos <roosa@google.com>
Tue, 5 Mar 2019 16:57:56 +0000 (17:57 +0100)
Test: python apilint_test.py
Change-Id: Iebe3b48df7ed69e0b5f5ff372b72f68ca9f8efec

tools/apilint/apilint.py

index 52707c2..ddfee62 100644 (file)
@@ -1262,6 +1262,19 @@ def verify_collections(clazz):
             if arg in bad:
                 error(clazz, m, "CL2", "Argument is concrete collection; must be higher-level interface")
 
+def verify_uris(clazz):
+    bad = ["java.net.URL", "java.net.URI", "android.net.URL"]
+
+    for f in clazz.fields:
+        if f.typ in bad:
+            error(clazz, f, None, "Field must be android.net.Uri instead of " + f.typ)
+
+    for m in clazz.methods + clazz.ctors:
+        if m.typ in bad:
+            error(clazz, m, None, "Must return android.net.Uri instead of " + m.typ)
+        for arg in m.args:
+            if arg in bad:
+                error(clazz, m, None, "Argument must take android.net.Uri instead of " + arg)
 
 def verify_flags(clazz):
     """Verifies that flags are non-overlapping."""
@@ -1982,6 +1995,7 @@ def examine_clazz(clazz):
     verify_layering(clazz)
     verify_boolean(clazz)
     verify_collections(clazz)
+    verify_uris(clazz)
     verify_flags(clazz)
     verify_exception(clazz)
     if not ALLOW_GOOGLE: verify_google(clazz)