diff options
author | Yigit Boyar <yboyar@google.com> | 2015-09-29 16:39:35 -0700 |
---|---|---|
committer | Yigit Boyar <yboyar@google.com> | 2015-09-29 16:39:35 -0700 |
commit | f01c66d7aaafd713de64b499c568f5870855dcd5 (patch) | |
tree | 22d9584470ad7098ca4bb6cbc33f216f6b8c4316 /compiler/src/main | |
parent | 99c02c7c337ea01ffa81ffde220babde2107e989 (diff) | |
download | data-binding-f01c66d7aaafd713de64b499c568f5870855dcd5.tar.gz |
Load full SDK table
When loading methods from the SDK, we would only load
methods that have since > Application.minApi. This
way, we would keep the hash very small. On the other
hand, this algorithm break if a newer API version adds
a method that has the same signature with a subclass.
This case happened when we added setForeground to
View at API 23 but it has been in FrameLayout since 1.
Bug:24509802
Change-Id: I7ac7ca5d1aac142a9afe8cd57ab9497dfb649650
Diffstat (limited to 'compiler/src/main')
-rw-r--r-- | compiler/src/main/java/android/databinding/tool/reflection/SdkUtil.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/src/main/java/android/databinding/tool/reflection/SdkUtil.java b/compiler/src/main/java/android/databinding/tool/reflection/SdkUtil.java index 4b5e09fc..e8c962ef 100644 --- a/compiler/src/main/java/android/databinding/tool/reflection/SdkUtil.java +++ b/compiler/src/main/java/android/databinding/tool/reflection/SdkUtil.java @@ -64,7 +64,7 @@ public class SdkUtil { int result = sApiChecker.getMinApi(classDesc, methodDesc); L.d("checking method api for %s, class:%s method:%s. result: %d", modelMethod.getName(), classDesc, methodDesc, result); - if (result > 1) { + if (result > 0) { return result; } declaringClass = declaringClass.getSuperclass(); @@ -74,7 +74,7 @@ public class SdkUtil { static class ApiChecker { - private Map<String, Integer> mFullLookup = new HashMap<String, Integer>(); + private Map<String, Integer> mFullLookup; private Document mDoc; @@ -103,6 +103,7 @@ public class SdkUtil { private void buildFullLookup() throws XPathExpressionException { NodeList allClasses = mDoc.getChildNodes().item(0).getChildNodes(); + mFullLookup = new HashMap<>(allClasses.getLength() * 4); for (int j = 0; j < allClasses.getLength(); j++) { Node node = allClasses.item(j); if (node.getNodeType() != Node.ELEMENT_NODE || !"class" @@ -122,16 +123,17 @@ public class SdkUtil { } int methodSince = getSince(child); int since = Math.max(classSince, methodSince); - if (since > SdkUtil.sMinSdk) { - String methodDesc = child.getAttributes().getNamedItem("name") - .getNodeValue(); - String key = cacheKey(classDesc, methodDesc); - mFullLookup.put(key, since); - } + String methodDesc = child.getAttributes().getNamedItem("name") + .getNodeValue(); + String key = cacheKey(classDesc, methodDesc); + mFullLookup.put(key, since); } } } + /** + * Returns 0 if we cannot find the API level for the method. + */ public int getMinApi(String classDesc, String methodOrFieldDesc) { if (mDoc == null || mXPath == null) { return 1; @@ -141,7 +143,7 @@ public class SdkUtil { } final String key = cacheKey(classDesc, methodOrFieldDesc); Integer since = mFullLookup.get(key); - return since == null ? 1 : since; + return since == null ? 0 : since; } private static String cacheKey(String classDesc, String methodOrFieldDesc) { |