Merge "Use Gradle instead of Ant" into ub-jack
diff --git a/jack/src/com/android/jack/ir/impl/JackIrBuilder.java b/jack/src/com/android/jack/ir/impl/JackIrBuilder.java
index 7bcf9f8..7b260d6 100644
--- a/jack/src/com/android/jack/ir/impl/JackIrBuilder.java
+++ b/jack/src/com/android/jack/ir/impl/JackIrBuilder.java
@@ -2054,19 +2054,7 @@
     public void endVisit(MessageSend x, BlockScope scope) {
       try {
         SourceInfo info = makeSourceInfo(x);
-        JMethod method;
-        if (x.actualReceiverType.isArrayType() && new String(x.selector).equals("clone")) {
-          // ECJ has replaced the clone prototype "jlo clone()" by "int[] clone()", temporarily
-          // replace int[] by jlo to be able to lookup the method.
-          TypeBinding savedReturnType = x.binding.returnType;
-          assert savedReturnType.isArrayType();
-          x.binding.returnType = scope.getJavaLangObject();
-          method = getTypeMap().get(x.binding);
-          x.binding.returnType = savedReturnType;
-        } else {
-          method = getTypeMap().get(x.binding);
-        }
-
+        JMethod method = getTypeMap().get(x.binding);
 
         List<JExpression> arguments = popCallArgs(info, x.arguments, x.binding);
         JExpression receiver = pop(x.receiver);
diff --git a/jack/src/com/android/jack/ir/impl/ReferenceMapper.java b/jack/src/com/android/jack/ir/impl/ReferenceMapper.java
index 169de64..adbae4d 100644
--- a/jack/src/com/android/jack/ir/impl/ReferenceMapper.java
+++ b/jack/src/com/android/jack/ir/impl/ReferenceMapper.java
@@ -111,6 +111,12 @@
   @Nonnull
   private final SourceInfoFactory sourceInfoFactory;
 
+  @CheckForNull
+  private ReferenceBinding ecjJlo = null;
+
+  @CheckForNull
+  private MethodBinding ecjJloCloneMth = null;
+
   public ReferenceMapper(@Nonnull JNodeLookup lookup,
       @Nonnull LookupEnvironment lookupEnvironment, @Nonnull SourceInfoFactory sourceInfoFactory) {
     this.lookup = lookup;
@@ -159,8 +165,28 @@
     return field;
   }
 
+  private boolean isCloneOfArray(@Nonnull MethodBinding binding) {
+    if (ecjJlo == null) {
+      ecjJlo = lookupEnvironment.getType(TypeConstants.JAVA_LANG_OBJECT);
+      assert ecjJlo != null;
+      MethodBinding[] methods = ecjJlo.getMethods("clone".toCharArray());
+      assert methods.length == 1;
+      ecjJloCloneMth = methods[0];
+    }
+
+    return binding.declaringClass.equals(ecjJlo) && new String(binding.selector).equals("clone")
+        && binding.returnType.isArrayType();
+  }
+
   @Nonnull
   public JMethod get(@Nonnull MethodBinding binding) throws JTypeLookupException {
+    if (isCloneOfArray(binding)) {
+      // ECJ has replaced the clone prototype "jlo clone()" by "int[] clone()", thus replace the
+      // binding by the binding of clone from jlo to be able to lookup the method.
+      binding = ecjJloCloneMth;
+      assert binding != null;
+    }
+
     binding = binding.original();
     SignatureKey key = new SignatureKey(binding);
     JMethod method = methods.get(key);