summaryrefslogtreecommitdiff
path: root/tools/apilint
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2017-12-05 09:42:28 -0700
committerJeff Sharkey <jsharkey@android.com>2017-12-05 09:42:31 -0700
commitbedb3fcf1d2092cfd40c60e41a87b3e00c45b1fc (patch)
treed88a6fcbd14fc5348ff66b8ae3760e5a5f72567f /tools/apilint
parent4ab869e1e6f2eb472d34ae18a185ca52ddd98be1 (diff)
Executors instead of Handlers; collections.
New API council guidance is to have developers provide an Executor instead of a Handler for specifying where a callback should be dispatched. Recommend that raw arrays be switched to Collections<> instead. Disable overload checking, since it's far too noisy. Test: sanity-checked linter output Bug: 37893784, 34192159 Change-Id: Ifc9a69bfed1a1004c6604e12987a606d1d3fd6af
Diffstat (limited to 'tools/apilint')
-rw-r--r--tools/apilint/apilint.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py
index fd42033d839c..421e54558df4 100644
--- a/tools/apilint/apilint.py
+++ b/tools/apilint/apilint.py
@@ -940,11 +940,14 @@ def verify_callback_handlers(clazz):
for f in found.values():
takes_handler = False
+ takes_exec = False
for m in by_name[f.name]:
if "android.os.Handler" in m.args:
takes_handler = True
- if not takes_handler:
- warn(clazz, f, "L1", "Registration methods should have overload that accepts delivery Handler")
+ if "java.util.concurrent.Executor" in m.args:
+ takes_exec = True
+ if not takes_exec:
+ warn(clazz, f, "L1", "Registration methods should have overload that accepts delivery Executor")
def verify_context_first(clazz):
@@ -968,7 +971,7 @@ def verify_listener_last(clazz):
for a in m.args:
if a.endswith("Callback") or a.endswith("Callbacks") or a.endswith("Listener"):
found = True
- elif found and a != "android.os.Handler":
+ elif found and a != "android.os.Handler" and a != "java.util.concurrent.Executor":
warn(clazz, m, "M3", "Listeners should always be at end of argument list")
@@ -1218,6 +1221,18 @@ def verify_method_name_not_kotlin_operator(clazz):
unique_binary_op(m, m.name[:-6]) # Remove 'Assign' suffix
+def verify_collections_over_arrays(clazz):
+ """Warn that [] should be Collections."""
+
+ safe = ["java.lang.String[]","byte[]","short[]","int[]","long[]","float[]","double[]","boolean[]","char[]"]
+ for m in clazz.methods:
+ if m.typ.endswith("[]") and m.typ not in safe:
+ warn(clazz, m, None, "Method should return Collection<> (or subclass) instead of raw array")
+ for arg in m.args:
+ if arg.endswith("[]") and arg not in safe:
+ warn(clazz, m, None, "Method argument should be Collection<> (or subclass) instead of raw array")
+
+
def examine_clazz(clazz):
"""Find all style issues in the given class."""
@@ -1260,7 +1275,7 @@ def examine_clazz(clazz):
verify_manager(clazz)
verify_boxed(clazz)
verify_static_utils(clazz)
- verify_overload_args(clazz)
+ # verify_overload_args(clazz)
verify_callback_handlers(clazz)
verify_context_first(clazz)
verify_listener_last(clazz)
@@ -1274,6 +1289,7 @@ def examine_clazz(clazz):
verify_closable(clazz)
verify_member_name_not_kotlin_keyword(clazz)
verify_method_name_not_kotlin_operator(clazz)
+ verify_collections_over_arrays(clazz)
def examine_stream(stream):