apilint: Fix API lint issues

Fixes a bug where only the name instead of the fully qualified name was
considered when looking for a class, which lead to faulty results for inner
classes.

Test: python tools/apilint/apilint_test.py
Change-Id: Ib015669ed3faef21d2bdd16f1e27bc55c8669d70
(cherry picked from commit 2c5cacfd36128f43f5fab4f0665acf69ac049a44)
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py
index b5a990e..1eec218 100644
--- a/tools/apilint/apilint.py
+++ b/tools/apilint/apilint.py
@@ -267,6 +267,18 @@
                         raise TypeError("send() must be followed by next(), not send()")
 
 
+def _retry_iterator(it):
+    """Wraps an iterator, such that calling send(True) on it will redeliver the same element"""
+    for e in it:
+        while True:
+            retry = yield e
+            if not retry:
+                break
+            # send() was called, asking us to redeliver clazz on next(). Still need to yield
+            # a dummy value to the send() first though.
+            if (yield "Returning clazz on next()"):
+                raise TypeError("send() must be followed by next(), not send()")
+
 def _parse_to_matching_class(classes, needle):
     """Takes a classes generator and parses it until it returns the class we're looking for
 
@@ -276,8 +288,8 @@
         if clazz.pkg.name < needle.pkg.name:
             # We haven't reached the right package yet
             continue
-        if clazz.name < needle.name:
-            # We haven't reached the right class yet
+        if clazz.pkg.name == needle.pkg.name and clazz.fullname < needle.fullname:
+            # We're in the right package, but not the right class yet
             continue
         if clazz.fullname == needle.fullname:
             return clazz