Update ecj to 4.7M3

Bug: 28577597

Change-Id: Iabfd8c97f3f8139655852ea1ab1ebdbde73acf6d
diff --git a/build.xml b/build.xml
index 02a46dc..051cc32 100644
--- a/build.xml
+++ b/build.xml
@@ -1358,7 +1358,7 @@
 
   <target name="ecj">
     <mkdir dir="${ecj.dist.dir}"/>
-    <copy file="${ecj.dir}/ecj-4.6M4.jar" tofile="${ecj.dist.dir}/${ecj.libname}"/>
+    <copy file="${ecj.dir}/ecj-4.7M3.jar" tofile="${ecj.dist.dir}/${ecj.libname}"/>
   </target>
 
 
diff --git a/ecj/Android.mk b/ecj/Android.mk
index 1a01ba7..8d1baa7 100644
--- a/ecj/Android.mk
+++ b/ecj/Android.mk
@@ -19,6 +19,6 @@
 LOCAL_MODULE_TAGS := optional
 
 LOCAL_PREBUILT_JAVA_LIBRARIES := \
-	ecj-jack:ecj-4.6M4$(COMMON_JAVA_PACKAGE_SUFFIX)
+	ecj-jack:ecj-4.7M3$(COMMON_JAVA_PACKAGE_SUFFIX)
 
 include $(BUILD_HOST_PREBUILT)
diff --git a/ecj/README.android b/ecj/README.android
index 1506c9d..c92a7b5 100644
--- a/ecj/README.android
+++ b/ecj/README.android
@@ -1,5 +1,5 @@
-URL: http://download.eclipse.org/eclipse/downloads/drops4/S-4.6M4-201512092300/
-Tag: I20151209-2300, jdt 4.6M4, ecj version 3.12.0
+URL: http://download.eclipse.org/eclipse/downloads/drops4/S-4.7M3-201610270700/
+Tag: I20161027-0700, ecj version 3.13.0 (v20161020-2113)
 License: EPL 1
 Description: An incremental Java compiler.
 Local Modifications: None.
diff --git a/ecj/ecj-4.6M4.jar b/ecj/ecj-4.6M4.jar
deleted file mode 100644
index 56d696c..0000000
--- a/ecj/ecj-4.6M4.jar
+++ /dev/null
Binary files differ
diff --git a/ecj/ecj-4.7M3.jar b/ecj/ecj-4.7M3.jar
new file mode 100644
index 0000000..8b16e12
--- /dev/null
+++ b/ecj/ecj-4.7M3.jar
Binary files differ
diff --git a/jack-tests/tests/com/android/jack/java8/DefaultMethodTest.java b/jack-tests/tests/com/android/jack/java8/DefaultMethodTest.java
index c0f1b02..b3c0d6a 100644
--- a/jack-tests/tests/com/android/jack/java8/DefaultMethodTest.java
+++ b/jack-tests/tests/com/android/jack/java8/DefaultMethodTest.java
@@ -518,15 +518,7 @@
   @Test
   @Runtime(from=RuntimeVersion.N)
   public void testDefaultMethod018() throws Exception {
-    new RuntimeTestHelper(DEFAULTMETHOD018)
-    .addProperty(
-        Options.ANDROID_MIN_API_LEVEL.getName(),
-        String.valueOf(AndroidApiLevel.ReleasedLevel.N.getLevel()))
-    .setSourceLevel(SourceLevel.JAVA_8)
-    .addIgnoredCandidateToolchain(JackApiV01.class)
-    // This test must be exclude from the Jill tool-chain because, there is a different behavior than with Jack
-    .addIgnoredCandidateToolchain(JillBasedToolchain.class)
-    .compileAndRunTest();
+    run(DEFAULTMETHOD018);
   }
 
   @Test
diff --git a/jack-tests/tests/com/android/jack/java8/defaultmethod/test018/jack/Tests.java b/jack-tests/tests/com/android/jack/java8/defaultmethod/test018/jack/Tests.java
index 13859cf..5ab5cbe 100644
--- a/jack-tests/tests/com/android/jack/java8/defaultmethod/test018/jack/Tests.java
+++ b/jack-tests/tests/com/android/jack/java8/defaultmethod/test018/jack/Tests.java
@@ -27,6 +27,6 @@
   @Test
   public void test001() throws Exception {
     Lambda l = new Lambda();
-    Assert.assertEquals("default : String", l.testLambdaRedefiningADefault());
+    Assert.assertEquals("lambda : String", l.testLambdaRedefiningADefault());
   }
 }
diff --git a/jack-tests/tests/com/android/jack/optimizations/modifiers/ModifiersTighteningTests.java b/jack-tests/tests/com/android/jack/optimizations/modifiers/ModifiersTighteningTests.java
index 0281d32..a8aa298 100644
--- a/jack-tests/tests/com/android/jack/optimizations/modifiers/ModifiersTighteningTests.java
+++ b/jack-tests/tests/com/android/jack/optimizations/modifiers/ModifiersTighteningTests.java
@@ -140,13 +140,7 @@
     mBase.update("g(Ljava/lang/String;)Ljava/util/AbstractList;", isFinal);
     mBase.update("g(Ljava/lang/String;)Ljava/util/ArrayList;", isFinal);
 
-    // NOTE: the legacy compiler create this method in 'D2' as well,
-    //       thus this one is not marked as final in 'D1'.
-    if (!usingLegacyCompiler()) {
-      mD1.update("foo()Ljava/lang/Object;", isFinal);
-    } else {
-      mD2.insert("foo()Ljava/lang/Object;", isFinal);
-    }
+    mD2.insert("foo()Ljava/lang/Object;", isFinal);
 
     mD2.update("bar()Ljava/lang/Object;", isFinal);
     mD2.update("foo()Lcom/android/jack/optimizations/modifiers/test002/jack/Base;", isFinal);
diff --git a/jack/src/com/android/jack/ecj/loader/jast/JAstBinaryType.java b/jack/src/com/android/jack/ecj/loader/jast/JAstBinaryType.java
index 3080330..d7f4497 100644
--- a/jack/src/com/android/jack/ecj/loader/jast/JAstBinaryType.java
+++ b/jack/src/com/android/jack/ecj/loader/jast/JAstBinaryType.java
@@ -43,6 +43,7 @@
 import org.eclipse.jdt.internal.compiler.env.IBinaryType;
 import org.eclipse.jdt.internal.compiler.env.IBinaryTypeAnnotation;
 import org.eclipse.jdt.internal.compiler.env.ITypeAnnotationWalker;
+import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus;
 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
 import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
 
@@ -459,4 +460,9 @@
     // Jack does not support ecj external annotation file
     return walker;
   }
+
+  @Override
+  public ExternalAnnotationStatus getExternalAnnotationStatus() {
+    return ExternalAnnotationStatus.FROM_SOURCE;
+  }
 }
diff --git a/jack/src/com/android/jack/frontend/java/JAstBuilder.java b/jack/src/com/android/jack/frontend/java/JAstBuilder.java
index 6e25731..8cbd908 100644
--- a/jack/src/com/android/jack/frontend/java/JAstBuilder.java
+++ b/jack/src/com/android/jack/frontend/java/JAstBuilder.java
@@ -260,19 +260,19 @@
   }
 
   @Override
-  public void compile(ICompilationUnit[] sourceUnits) {
+  protected void backupAptProblems() {
+    resetJack = true;
+    super.backupAptProblems();
+  }
+
+  @Override
+  public void reset() {
+    super.reset();
     if (resetJack) {
       session.reset();
       astBuilder = new JackIrBuilder(lookupEnvironment, session);
       resetJack = false;
     }
-    super.compile(sourceUnits);
-  }
-
-  @Override
-  public void reset() {
-    resetJack = true;
-    super.reset();
   }
 
   public void finishCompilation() {
diff --git a/jack/src/com/android/jack/ir/impl/JackIrBuilder.java b/jack/src/com/android/jack/ir/impl/JackIrBuilder.java
index 88f88b6..09fd238 100644
--- a/jack/src/com/android/jack/ir/impl/JackIrBuilder.java
+++ b/jack/src/com/android/jack/ir/impl/JackIrBuilder.java
@@ -2047,7 +2047,19 @@
     public void endVisit(MessageSend x, BlockScope scope) {
       try {
         SourceInfo info = makeSourceInfo(x);
-        JMethod method = getTypeMap().get(x.binding);
+        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);
+        }
+
 
         List<JExpression> arguments = popCallArgs(info, x.arguments, x.binding);
         JExpression receiver = pop(x.receiver);