diff options
author | George Mount <mount@google.com> | 2018-01-09 10:18:41 -0800 |
---|---|---|
committer | George Mount <mount@google.com> | 2018-01-09 17:31:11 -0800 |
commit | 7cc79d3b3119b32ded177d93ea86bef8d8065020 (patch) | |
tree | 57ee1ca6eb324ddd5af0f62c03dbed9632d5d2db /compiler/src/main/java/android/databinding | |
parent | 28efa96610b913ce5b30cc36ed33dbf1b62f3f66 (diff) | |
download | data-binding-7cc79d3b3119b32ded177d93ea86bef8d8065020.tar.gz |
Default to unwrapping ObservableFields for Object method params
Bug: 70367050
ObservableFields were only unwrapped when it couldn't be assigned
to the target type of the method parameter. When the parameter type
is Object the ObservableField matched and that isn't what the
developer wants.
Test: ran TestApp tests
Change-Id: I300c8a009575fb219c4f1a615e194fb743d7c46d
Diffstat (limited to 'compiler/src/main/java/android/databinding')
-rw-r--r-- | compiler/src/main/java/android/databinding/tool/expr/Expr.java | 8 | ||||
-rw-r--r-- | compiler/src/main/java/android/databinding/tool/reflection/ModelMethod.java | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/compiler/src/main/java/android/databinding/tool/expr/Expr.java b/compiler/src/main/java/android/databinding/tool/expr/Expr.java index 4a3dd324..d1798443 100644 --- a/compiler/src/main/java/android/databinding/tool/expr/Expr.java +++ b/compiler/src/main/java/android/databinding/tool/expr/Expr.java @@ -897,8 +897,7 @@ abstract public class Expr implements VersionProvider, LocationScopeProvider { Expr expr = child; String simpleGetterName; while ((simpleGetterName = expr.getResolvedType().getObservableGetterName()) != null - && (type == null || (!type.isAssignableFrom(expr.getResolvedType()) - && !ModelMethod.isImplicitConversion(expr.getResolvedType(), type)))) { + && shouldUnwrap(type, expr.getResolvedType())) { unwrapped = mModel.methodCall(expr, simpleGetterName, Collections.EMPTY_LIST); if (unwrapped == this) { L.w(ErrorMessages.OBSERVABLE_FIELD_GET, this); @@ -914,6 +913,11 @@ abstract public class Expr implements VersionProvider, LocationScopeProvider { } } + private static boolean shouldUnwrap(ModelClass from, ModelClass to) { + return (to == null || to.isObject() || !to.isAssignableFrom(from)) + && !ModelMethod.isImplicitConversion(from, to); + } + /** * Called after experiment model is sealed to avoid NPE problems caused by boxed primitives. */ diff --git a/compiler/src/main/java/android/databinding/tool/reflection/ModelMethod.java b/compiler/src/main/java/android/databinding/tool/reflection/ModelMethod.java index b83ad214..f8c57a0f 100644 --- a/compiler/src/main/java/android/databinding/tool/reflection/ModelMethod.java +++ b/compiler/src/main/java/android/databinding/tool/reflection/ModelMethod.java @@ -212,7 +212,10 @@ public abstract class ModelMethod { } public static boolean isImplicitConversion(ModelClass from, ModelClass to) { - if (from != null && to != null && from.isPrimitive() && to.isPrimitive()) { + if (from == null || to == null) { + return false; + } + if (from.isPrimitive() && to.isPrimitive()) { if (from.isBoolean() || to.isBoolean() || to.isChar()) { return false; } @@ -222,7 +225,7 @@ public abstract class ModelMethod { } else { ModelClass unboxedFrom = from.unbox(); ModelClass unboxedTo = to.unbox(); - if (unboxedFrom != from || unboxedTo != to) { + if (!from.equals(unboxedFrom) || !to.equals(unboxedTo)) { return isImplicitConversion(unboxedFrom, unboxedTo); } } |