Loosen desugaring constraints
And enable all desugaring by by default.
Loosening as defined in the discussion document:
- Skip desugaring of anything if the target method is defined in the
bootclasspath (i.e. API android.jar).
- Just warn about invokestatic, invokesuper and call to method handle
when the target class or interface is missing.
- Change handling of hierarchy:
- If all declared interfaces (and their super interfaces hierarchies)
of a class are known and the class has an implementation for all
default methods found in the declared interface of the class (even
those hidden in subinterfaces), skip default method desugaring for
the class.
- In any other case of missing element in the hierachy is reported as
a warning. missing interfaces are ignored, missing class cause the
subclasses to be ignored during default method desugaring.
Change-Id: I8d7043616bbfff26ac09a17a3e953a4a4e5aa4c8
diff --git a/src/test/examplesAndroidO/desugaringwithandroidjar25/DefaultMethodInAndroidJar25.java b/src/test/examplesAndroidO/desugaringwithandroidjar25/DefaultMethodInAndroidJar25.java
new file mode 100644
index 0000000..bec4e67
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithandroidjar25/DefaultMethodInAndroidJar25.java
@@ -0,0 +1,100 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithandroidjar25;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.function.Predicate;
+
+public class DefaultMethodInAndroidJar25 {
+ public static void main(String[] args) throws Exception {
+ ClassWithDefaultPlatformMethods.test();
+ }
+}
+
+class ClassWithDefaultPlatformMethods implements Collection<String> {
+ private final ArrayList<String> list =
+ new ArrayList<String>() {{
+ add("First");
+ add("Second");
+ }};
+
+ static void test() {
+ ClassWithDefaultPlatformMethods instance = new ClassWithDefaultPlatformMethods();
+ instance.forEach(x -> System.out.println("BEFORE: " + x));
+ instance.removeIf(x -> true);
+ instance.forEach(x -> System.out.println("AFTER: " + x));
+ }
+
+ @Override
+ public int size() {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public Iterator<String> iterator() {
+ return list.iterator();
+ }
+
+ @Override
+ public Object[] toArray() {
+ throw new AssertionError();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean add(String s) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return list.remove(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends String> c) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public void clear() {
+ throw new AssertionError();
+ }
+
+ @Override
+ public boolean removeIf(Predicate<? super String> filter) {
+ return Collection.super.removeIf(filter);
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithandroidjar25/StaticMethodInAndroidJar25.java b/src/test/examplesAndroidO/desugaringwithandroidjar25/StaticMethodInAndroidJar25.java
new file mode 100644
index 0000000..f07ea8f
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithandroidjar25/StaticMethodInAndroidJar25.java
@@ -0,0 +1,17 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package desugaringwithandroidjar25;
+
+import java.util.Comparator;
+
+public class StaticMethodInAndroidJar25 {
+ public static void main(String[] args) throws Exception {
+ Comparator<String> comparing =
+ Comparator.comparing(x -> x, String::compareTo);
+ System.out.println("'a' <> 'b' = " + comparing.compare("a", "b"));
+ System.out.println("'b' <> 'b' = " + comparing.compare("b", "b"));
+ System.out.println("'c' <> 'b' = " + comparing.compare("c", "b"));
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasslib1/A.java b/src/test/examplesAndroidO/desugaringwithmissingclasslib1/A.java
new file mode 100644
index 0000000..98504bd
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasslib1/A.java
@@ -0,0 +1,10 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasslib1;
+
+public interface A {
+ default String foo() {
+ return "A";
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasslib1/A2.java b/src/test/examplesAndroidO/desugaringwithmissingclasslib1/A2.java
new file mode 100644
index 0000000..ff42039
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasslib1/A2.java
@@ -0,0 +1,10 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasslib1;
+
+public interface A2 {
+ default String foo() {
+ return "A2";
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasslib2/B.java b/src/test/examplesAndroidO/desugaringwithmissingclasslib2/B.java
new file mode 100644
index 0000000..1ab424e
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasslib2/B.java
@@ -0,0 +1,13 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasslib2;
+
+import desugaringwithmissingclasslib1.A;
+
+public interface B extends A {
+ @Override
+ default String foo() {
+ return "B";
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasslib3/C.java b/src/test/examplesAndroidO/desugaringwithmissingclasslib3/C.java
new file mode 100644
index 0000000..029f9f4
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasslib3/C.java
@@ -0,0 +1,9 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasslib3;
+
+import desugaringwithmissingclasslib1.A;
+
+public class C implements A {
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasslib4/C2.java b/src/test/examplesAndroidO/desugaringwithmissingclasslib4/C2.java
new file mode 100644
index 0000000..b2aee3b
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasslib4/C2.java
@@ -0,0 +1,13 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasslib4;
+
+import desugaringwithmissingclasslib3.C;
+
+public class C2 extends C {
+ public String foo2() {
+ return "C2";
+ }
+}
+
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest1/ImplementMethodsWithDefault.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest1/ImplementMethodsWithDefault.java
new file mode 100644
index 0000000..5f3c1c2
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest1/ImplementMethodsWithDefault.java
@@ -0,0 +1,10 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest1;
+
+import desugaringwithmissingclasslib1.A;
+import desugaringwithmissingclasslib2.B;
+
+public class ImplementMethodsWithDefault implements A, B {
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest1/Main.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest1/Main.java
new file mode 100644
index 0000000..411a016
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest1/Main.java
@@ -0,0 +1,21 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest1;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ ImplementMethodsWithDefault instance = new ImplementMethodsWithDefault();
+ try {
+ String foo = instance.foo();
+ if (foo.equals("B")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest2/ImplementMethodsWithDefault.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest2/ImplementMethodsWithDefault.java
new file mode 100644
index 0000000..f2ef1b6
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest2/ImplementMethodsWithDefault.java
@@ -0,0 +1,10 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest2;
+
+import desugaringwithmissingclasslib2.B;
+import desugaringwithmissingclasslib3.C;
+
+public class ImplementMethodsWithDefault extends C implements B {
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest2/Main.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest2/Main.java
new file mode 100644
index 0000000..c42ac81
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest2/Main.java
@@ -0,0 +1,21 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest2;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ ImplementMethodsWithDefault instance = new ImplementMethodsWithDefault();
+ try {
+ String foo = instance.foo();
+ if (foo.equals("B")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest3/ImplementMethodsWithDefault.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest3/ImplementMethodsWithDefault.java
new file mode 100644
index 0000000..4826237
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest3/ImplementMethodsWithDefault.java
@@ -0,0 +1,18 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest3;
+
+import desugaringwithmissingclasslib2.B;
+import desugaringwithmissingclasslib3.C;
+
+public class ImplementMethodsWithDefault extends C implements B {
+ @Override
+ public String foo() {
+ return "ImplementMethodsWithDefault";
+ }
+
+ public String getB() {
+ return B.super.foo();
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest3/Main.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest3/Main.java
new file mode 100644
index 0000000..bde4d09
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest3/Main.java
@@ -0,0 +1,32 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest3;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ ImplementMethodsWithDefault instance = new ImplementMethodsWithDefault();
+ try {
+ String b = instance.getB();
+ if (b.equals("B")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + b);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ try {
+ String foo = instance.foo();
+ if (foo.equals("ImplementMethodsWithDefault")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest4/C2.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest4/C2.java
new file mode 100644
index 0000000..cea6324
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest4/C2.java
@@ -0,0 +1,13 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest4;
+
+import desugaringwithmissingclasslib3.C;
+
+public class C2 extends C {
+ public String foo2() {
+ return "C2";
+ }
+}
+
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest4/ImplementMethodsWithDefault.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest4/ImplementMethodsWithDefault.java
new file mode 100644
index 0000000..c62bc2c
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest4/ImplementMethodsWithDefault.java
@@ -0,0 +1,14 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest4;
+
+import desugaringwithmissingclasslib1.A;
+import desugaringwithmissingclasslib1.A2;
+
+public class ImplementMethodsWithDefault extends C2 implements A, A2 {
+ @Override
+ public String foo() {
+ return "ImplementMethodsWithDefault";
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest4/Main.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest4/Main.java
new file mode 100644
index 0000000..e439c5c
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest4/Main.java
@@ -0,0 +1,32 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest4;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ ImplementMethodsWithDefault instance = new ImplementMethodsWithDefault();
+ try {
+ String foo = instance.foo();
+ if (foo.equals("ImplementMethodsWithDefault")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ try {
+ String foo = instance.foo2();
+ if (foo.equals("C2")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest5/ImplementMethodsWithDefault.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest5/ImplementMethodsWithDefault.java
new file mode 100644
index 0000000..f8dfc3b
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest5/ImplementMethodsWithDefault.java
@@ -0,0 +1,15 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest5;
+
+import desugaringwithmissingclasslib1.A;
+import desugaringwithmissingclasslib1.A2;
+import desugaringwithmissingclasslib4.C2;
+
+public class ImplementMethodsWithDefault extends C2 implements A, A2 {
+ @Override
+ public String foo() {
+ return "ImplementMethodsWithDefault";
+ }
+}
diff --git a/src/test/examplesAndroidO/desugaringwithmissingclasstest5/Main.java b/src/test/examplesAndroidO/desugaringwithmissingclasstest5/Main.java
new file mode 100644
index 0000000..d1ee997
--- /dev/null
+++ b/src/test/examplesAndroidO/desugaringwithmissingclasstest5/Main.java
@@ -0,0 +1,32 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package desugaringwithmissingclasstest5;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ ImplementMethodsWithDefault instance = new ImplementMethodsWithDefault();
+ try {
+ String foo = instance.foo();
+ if (foo.equals("ImplementMethodsWithDefault")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ try {
+ String foo = instance.foo2();
+ if (foo.equals("C2")) {
+ System.out.println("OK");
+ } else {
+ System.out.println("NOT OK: " + foo);
+ }
+ } catch (Throwable t) {
+ System.out.println("NOT OK " + t.getClass() + " " + t.getMessage());
+ t.printStackTrace();
+ }
+ }
+}