diff options
Diffstat (limited to 'test/java/com')
20 files changed, 360 insertions, 16 deletions
diff --git a/test/java/com/google/devtools/build/android/desugar/DefaultMethodClassFixerTest.java b/test/java/com/google/devtools/build/android/desugar/DefaultMethodClassFixerTest.java index cdc3263..c74febb 100644 --- a/test/java/com/google/devtools/build/android/desugar/DefaultMethodClassFixerTest.java +++ b/test/java/com/google/devtools/build/android/desugar/DefaultMethodClassFixerTest.java @@ -98,7 +98,12 @@ public class DefaultMethodClassFixerTest { private byte[] desugar(ClassReader reader) { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); DefaultMethodClassFixer fixer = - new DefaultMethodClassFixer(writer, classpathReader, bootclassPath, classLoader); + new DefaultMethodClassFixer( + writer, + classpathReader, + DependencyCollector.NoWriteCollectors.FAIL_ON_MISSING, + bootclassPath, + classLoader); reader.accept(fixer, 0); return writer.toByteArray(); } diff --git a/test/java/com/google/devtools/build/android/desugar/DesugarJava8FunctionalTest.java b/test/java/com/google/devtools/build/android/desugar/DesugarJava8FunctionalTest.java index 8321d75..20e6028 100644 --- a/test/java/com/google/devtools/build/android/desugar/DesugarJava8FunctionalTest.java +++ b/test/java/com/google/devtools/build/android/desugar/DesugarJava8FunctionalTest.java @@ -23,6 +23,9 @@ import com.google.devtools.build.android.desugar.testdata.java8.ConcreteDefaultI import com.google.devtools.build.android.desugar.testdata.java8.ConcreteOverridesDefaultWithLambda; import com.google.devtools.build.android.desugar.testdata.java8.DefaultInterfaceMethodWithStaticInitializer; import com.google.devtools.build.android.desugar.testdata.java8.DefaultInterfaceWithBridges; +import com.google.devtools.build.android.desugar.testdata.java8.DefaultMethodFromSeparateJava8Target; +import com.google.devtools.build.android.desugar.testdata.java8.DefaultMethodFromSeparateJava8TargetOverridden; +import com.google.devtools.build.android.desugar.testdata.java8.DefaultMethodTransitivelyFromSeparateJava8Target; import com.google.devtools.build.android.desugar.testdata.java8.FunctionWithDefaultMethod; import com.google.devtools.build.android.desugar.testdata.java8.FunctionalInterfaceWithInitializerAndDefaultMethods; import com.google.devtools.build.android.desugar.testdata.java8.GenericDefaultInterfaceWithLambda; @@ -111,6 +114,12 @@ public class DesugarJava8FunctionalTest extends DesugarFunctionalTest { } @Test + public void testBootclasspathMethodInvocations() { + InterfaceMethod concrete = new InterfaceMethod.Concrete(); + assertThat(concrete.defaultInvokingBootclasspathMethods("Larry")).isEqualTo("Larry"); + } + + @Test public void testStaticMethodsInInterface_explicitAndLambdaBody() { List<Long> result = FunctionWithDefaultMethod.DoubleInts.add(ImmutableList.of(7, 39, 8), 3); assertThat(result).containsExactly(10L, 42L, 11L).inOrder(); @@ -394,4 +403,16 @@ public class DesugarJava8FunctionalTest extends DesugarFunctionalTest { .getExpectedInitializationOrder()); } } + + /** + * Tests that default methods on the classpath are correctly handled. We'll also verify the + * metadata that's emitted for this case to make sure the binary-wide double-check for correct + * desugaring of default and static interface methods keeps working (b/65645388). + */ + @Test + public void testDefaultMethodsInSeparateTarget() { + assertThat(new DefaultMethodFromSeparateJava8Target().dflt()).isEqualTo("dflt"); + assertThat(new DefaultMethodTransitivelyFromSeparateJava8Target().dflt()).isEqualTo("dflt"); + assertThat(new DefaultMethodFromSeparateJava8TargetOverridden().dflt()).isEqualTo("override"); + } } diff --git a/test/java/com/google/devtools/build/android/desugar/Java7CompatibilityTest.java b/test/java/com/google/devtools/build/android/desugar/Java7CompatibilityTest.java index b8c8b54..2eab943 100644 --- a/test/java/com/google/devtools/build/android/desugar/Java7CompatibilityTest.java +++ b/test/java/com/google/devtools/build/android/desugar/Java7CompatibilityTest.java @@ -31,7 +31,7 @@ public class Java7CompatibilityTest { public void testJava7CompatibleInterface() throws Exception { ClassReader reader = new ClassReader(ExtendsDefault.class.getName()); ClassTester tester = new ClassTester(); - reader.accept(new Java7Compatibility(tester, null), 0); + reader.accept(new Java7Compatibility(tester, null, null), 0); assertThat(tester.version).isEqualTo(Opcodes.V1_7); assertThat(tester.bridgeMethods).isEqualTo(0); // make sure we strip bridge methods assertThat(tester.clinitMethods).isEqualTo(1); // make sure we don't strip <clinit> @@ -41,7 +41,7 @@ public class Java7CompatibilityTest { public void testDefaultMethodFails() throws Exception { ClassReader reader = new ClassReader(WithDefault.class.getName()); try { - reader.accept(new Java7Compatibility(null, null), 0); + reader.accept(new Java7Compatibility(null, null, null), 0); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessageThat().contains("getVersion()I"); @@ -56,7 +56,7 @@ public class Java7CompatibilityTest { public void testConcreteClassRedeclaresBridges() throws Exception { ClassReader reader = new ClassReader(Impl.class.getName()); ClassTester tester = new ClassTester(); - reader.accept(new Java7Compatibility(tester, null), 0); + reader.accept(new Java7Compatibility(tester, null, null), 0); assertThat(tester.version).isEqualTo(Opcodes.V1_7); assertThat(tester.bridgeMethods).isEqualTo(2); } diff --git a/test/java/com/google/devtools/build/android/desugar/class_with_lambdas_in_implemented_interface_disassembled_golden.txt b/test/java/com/google/devtools/build/android/desugar/class_with_lambdas_in_implemented_interface_disassembled_golden.txt index 48a8632..73a563a 100644 --- a/test/java/com/google/devtools/build/android/desugar/class_with_lambdas_in_implemented_interface_disassembled_golden.txt +++ b/test/java/com/google/devtools/build/android/desugar/class_with_lambdas_in_implemented_interface_disassembled_golden.txt @@ -2,6 +2,7 @@ Compiled from "InterfaceMethod.java" public class com.google.devtools.build.android.desugar.testdata.java8.InterfaceMethod$Concrete implements com.google.devtools.build.android.desugar.testdata.java8.InterfaceMethod { public com.google.devtools.build.android.desugar.testdata.java8.InterfaceMethod$Concrete(); public java.util.List defaultMethodReference(java.util.List); + public java.lang.String defaultInvokingBootclasspathMethods(java.lang.String); public java.util.List staticMethodReference(java.util.List); public java.util.List lambdaCallsDefaultMethod(java.util.List); public boolean startsWithS(java.lang.String); diff --git a/test/java/com/google/devtools/build/android/desugar/dependencies/MetadataCollectorTest.java b/test/java/com/google/devtools/build/android/desugar/dependencies/MetadataCollectorTest.java new file mode 100644 index 0000000..e99abc4 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/dependencies/MetadataCollectorTest.java @@ -0,0 +1,113 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.dependencies; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.android.desugar.proto.DesugarDeps.Dependency; +import com.google.devtools.build.android.desugar.proto.DesugarDeps.DesugarDepsInfo; +import com.google.devtools.build.android.desugar.proto.DesugarDeps.InterfaceDetails; +import com.google.devtools.build.android.desugar.proto.DesugarDeps.InterfaceWithCompanion; +import com.google.devtools.build.android.desugar.proto.DesugarDeps.Type; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link MetadataCollector}. */ +@RunWith(JUnit4.class) +public class MetadataCollectorTest { + + @Test + public void testEmptyAvoidsOutput() { + assertThat(new MetadataCollector(false).toByteArray()).isNull(); + } + + @Test + public void testAssumeCompanionClass() throws Exception { + MetadataCollector collector = new MetadataCollector(false); + collector.assumeCompanionClass("a", "b$$CC"); + collector.assumeCompanionClass("b", "b$$CC"); + collector.assumeCompanionClass("a", "a$$CC"); + + DesugarDepsInfo info = extractProto(collector); + assertThat(info.getAssumePresentList()) + .containsExactly( + Dependency.newBuilder().setOrigin(wrapType("a")).setTarget(wrapType("b$$CC")).build(), + Dependency.newBuilder().setOrigin(wrapType("b")).setTarget(wrapType("b$$CC")).build(), + Dependency.newBuilder().setOrigin(wrapType("a")).setTarget(wrapType("a$$CC")).build()); + } + + @Test + public void testMissingImplementedInterface() throws Exception { + MetadataCollector collector = new MetadataCollector(true); + collector.missingImplementedInterface("a", "b"); + collector.missingImplementedInterface("a", "c"); + collector.missingImplementedInterface("c", "b"); + + DesugarDepsInfo info = extractProto(collector); + assertThat(info.getMissingInterfaceList()) + .containsExactly( + Dependency.newBuilder().setOrigin(wrapType("a")).setTarget(wrapType("b")).build(), + Dependency.newBuilder().setOrigin(wrapType("a")).setTarget(wrapType("c")).build(), + Dependency.newBuilder().setOrigin(wrapType("c")).setTarget(wrapType("b")).build()); + } + + @Test + public void testRecordExtendedInterfaces() throws Exception { + MetadataCollector collector = new MetadataCollector(false); + collector.recordExtendedInterfaces("a", "b", "c"); + collector.recordExtendedInterfaces("b"); + collector.recordExtendedInterfaces("c", "d"); + + DesugarDepsInfo info = extractProto(collector); + assertThat(info.getInterfaceWithSupertypesList()) + .containsExactly( + InterfaceDetails.newBuilder() + .setOrigin(wrapType("a")) + .addAllExtendedInterface(ImmutableList.of(wrapType("b"), wrapType("c"))) + .build(), + InterfaceDetails.newBuilder() + .setOrigin(wrapType("c")) + .addAllExtendedInterface(ImmutableList.of(wrapType("d"))) + .build()); + } + + @Test + public void testRecordDefaultMethods() throws Exception { + MetadataCollector collector = new MetadataCollector(false); + collector.recordDefaultMethods("a", 0); + collector.recordDefaultMethods("b", 1); + + DesugarDepsInfo info = extractProto(collector); + assertThat(info.getInterfaceWithCompanionList()) + .containsExactly( + InterfaceWithCompanion.newBuilder() + .setOrigin(wrapType("a")) + .setNumDefaultMethods(0) + .build(), + InterfaceWithCompanion.newBuilder() + .setOrigin(wrapType("b")) + .setNumDefaultMethods(1) + .build()); + } + + private static Type wrapType(String name) { + return Type.newBuilder().setBinaryName(name).build(); + } + + private DesugarDepsInfo extractProto(MetadataCollector collector) throws Exception { + return DesugarDepsInfo.parseFrom(collector.toByteArray()); + } +} diff --git a/test/java/com/google/devtools/build/android/desugar/desugar_deps_consistency_test.sh b/test/java/com/google/devtools/build/android/desugar/desugar_deps_consistency_test.sh new file mode 100755 index 0000000..e8e7e23 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/desugar_deps_consistency_test.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eu + +out="$(mktemp)" +if ! "devtools/blaze/singlejar/singlejar" --output "${out}" --check_desugar_deps --sources "$@"; then + rm "${out}" + case "$0" in + *_fail_test) echo "Singlejar failed as expected!"; exit 0;; + esac + echo "Singlejar unexpectedly failed" + exit 1 +fi + +case "$0" in + *_fail_test) rm "${out}"; echo "Singlejar unexpectedly succeeded :("; exit 1;; +esac + +if third_party/java/jdk/jar/jar tf "${out}" | grep 'desugar_deps'; then + rm "${out}" + echo "Singlejar output unexpectedly contains desugaring metadata" + exit 2 +fi # else grep didn't find anything -> pass +rm "${out}" +exit 0 diff --git a/test/java/com/google/devtools/build/android/desugar/interface_with_desugared_method_bodies_disassembled_golden.txt b/test/java/com/google/devtools/build/android/desugar/interface_with_desugared_method_bodies_disassembled_golden.txt index 828cee4..2d993a6 100644 --- a/test/java/com/google/devtools/build/android/desugar/interface_with_desugared_method_bodies_disassembled_golden.txt +++ b/test/java/com/google/devtools/build/android/desugar/interface_with_desugared_method_bodies_disassembled_golden.txt @@ -1,6 +1,7 @@ Compiled from "InterfaceMethod.java" public interface com.google.devtools.build.android.desugar.testdata.java8.InterfaceMethod { public abstract java.util.List<java.lang.String> defaultMethodReference(java.util.List<java.lang.String>); + public abstract java.lang.String defaultInvokingBootclasspathMethods(java.lang.String); public abstract java.util.List<java.lang.String> staticMethodReference(java.util.List<java.lang.String>); public abstract java.util.List<java.lang.String> lambdaCallsDefaultMethod(java.util.List<java.lang.String>); public abstract boolean startsWithS(java.lang.String); diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/InterfaceWithLambda.java b/test/java/com/google/devtools/build/android/desugar/testdata/InterfaceWithLambda.java index 47d8ab6..420ac15 100644 --- a/test/java/com/google/devtools/build/android/desugar/testdata/InterfaceWithLambda.java +++ b/test/java/com/google/devtools/build/android/desugar/testdata/InterfaceWithLambda.java @@ -14,12 +14,14 @@ package com.google.devtools.build.android.desugar.testdata; import com.google.common.collect.ImmutableList; +import java.util.List; +import java.util.stream.Collectors; public interface InterfaceWithLambda { String ZERO = String.valueOf(0); - ImmutableList<String> DIGITS = + List<String> DIGITS = ImmutableList.of(0, 1) .stream() .map(i -> i == 0 ? ZERO : String.valueOf(i)) - .collect(ImmutableList.toImmutableList()); + .collect(Collectors.toList()); } diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/b68049457/StaticInterfaceMethod.java b/test/java/com/google/devtools/build/android/desugar/testdata/b68049457/StaticInterfaceMethod.java new file mode 100644 index 0000000..7815a73 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/b68049457/StaticInterfaceMethod.java @@ -0,0 +1,21 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.b68049457; + +/** Interface declaring a static method for regression test for b/68049457. */ +public interface StaticInterfaceMethod { + static String never() { + throw new IllegalStateException("can't get here"); + } +} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/b68049457/StaticInterfaceMethodCaller.java b/test/java/com/google/devtools/build/android/desugar/testdata/b68049457/StaticInterfaceMethodCaller.java new file mode 100644 index 0000000..f961d96 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/b68049457/StaticInterfaceMethodCaller.java @@ -0,0 +1,21 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.b68049457; + +/** Class calling static interface method for regression test for b/68049457. */ +public class StaticInterfaceMethodCaller { + public String callIt() { + return StaticInterfaceMethod.never(); + } +} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteDefaultInterfaceWithLambda.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteDefaultInterfaceWithLambda.java index 0d9f70a..30a5200 100644 --- a/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteDefaultInterfaceWithLambda.java +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteDefaultInterfaceWithLambda.java @@ -14,15 +14,17 @@ package com.google.devtools.build.android.desugar.testdata.java8; import com.google.common.collect.ImmutableList; +import java.util.List; +import java.util.stream.Collectors; public class ConcreteDefaultInterfaceWithLambda implements DefaultInterfaceWithLambda { static final String ONE = String.valueOf(1); @Override - public ImmutableList<String> digits() { + public List<String> digits() { return ImmutableList.of(0, 2) .stream() .map(i -> i == 0 ? ONE : String.valueOf(i)) - .collect(ImmutableList.toImmutableList()); + .collect(Collectors.toList()); } } diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteOverridesDefaultWithLambda.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteOverridesDefaultWithLambda.java index cdcc5e9..5998f41 100644 --- a/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteOverridesDefaultWithLambda.java +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/ConcreteOverridesDefaultWithLambda.java @@ -14,24 +14,26 @@ package com.google.devtools.build.android.desugar.testdata.java8; import com.google.common.collect.ImmutableList; +import java.util.List; +import java.util.stream.Collectors; public class ConcreteOverridesDefaultWithLambda implements DefaultInterfaceWithLambda { static final String TWO = String.valueOf(2); static final String THREE = String.valueOf(3); @Override - public ImmutableList<String> defaultWithLambda() { + public List<String> defaultWithLambda() { return ImmutableList.of(0, 3) .stream() .map(i -> i == 0 ? TWO : String.valueOf(i)) - .collect(ImmutableList.toImmutableList()); + .collect(Collectors.toList()); } @Override - public ImmutableList<String> digits() { + public List<String> digits() { return ImmutableList.of(0, 4) .stream() .map(i -> i == 0 ? THREE : String.valueOf(i)) - .collect(ImmutableList.toImmutableList()); + .collect(Collectors.toList()); } } diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceWithLambda.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceWithLambda.java index e97cae9..ce5fca7 100644 --- a/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceWithLambda.java +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceWithLambda.java @@ -14,20 +14,22 @@ package com.google.devtools.build.android.desugar.testdata.java8; import com.google.common.collect.ImmutableList; +import java.util.List; +import java.util.stream.Collectors; public interface DefaultInterfaceWithLambda { String ZERO = String.valueOf(0); - public default ImmutableList<String> defaultWithLambda() { + public default List<String> defaultWithLambda() { return ImmutableList.of(0, 1) .stream() .map(i -> i == 0 ? ZERO : String.valueOf(i)) - .collect(ImmutableList.toImmutableList()); + .collect(Collectors.toList()); } - public default ImmutableList<String> defaultCallsInterfaceMethod() { + public default List<String> defaultCallsInterfaceMethod() { return digits(); } - public ImmutableList<String> digits(); + public List<String> digits(); } diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8Target.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8Target.java new file mode 100644 index 0000000..e0e8703 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8Target.java @@ -0,0 +1,20 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.java8; + +import com.google.devtools.build.android.desugar.testdata.separate8.SeparateInterfaceWithDefaultMethod; + +/** Test class that inherits default method defined in separate target for testing b/65645388. */ +public class DefaultMethodFromSeparateJava8Target + implements SeparateInterfaceWithDefaultMethod {} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8TargetOverridden.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8TargetOverridden.java new file mode 100644 index 0000000..1613f8e --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8TargetOverridden.java @@ -0,0 +1,25 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.java8; + +import com.google.devtools.build.android.desugar.testdata.separate8.SeparateInterfaceThatInheritsDefaultMethod; + +/** Test class that overrides default method defined in separate target for testing b/65645388. */ +public class DefaultMethodFromSeparateJava8TargetOverridden + implements SeparateInterfaceThatInheritsDefaultMethod { + @Override + public String dflt() { + return "override"; + } +} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodTransitivelyFromSeparateJava8Target.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodTransitivelyFromSeparateJava8Target.java new file mode 100644 index 0000000..693eaf7 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodTransitivelyFromSeparateJava8Target.java @@ -0,0 +1,23 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.java8; + +import com.google.devtools.build.android.desugar.testdata.separate8.SeparateInterfaceThatInheritsDefaultMethod; + +/** + * Test class that transitively inherits default method defined in separate target for testing + * b/65645388. + */ +public class DefaultMethodTransitivelyFromSeparateJava8Target + implements SeparateInterfaceThatInheritsDefaultMethod {} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/java8/InterfaceMethod.java b/test/java/com/google/devtools/build/android/desugar/testdata/java8/InterfaceMethod.java index 622e6e5..ae2b6e1 100644 --- a/test/java/com/google/devtools/build/android/desugar/testdata/java8/InterfaceMethod.java +++ b/test/java/com/google/devtools/build/android/desugar/testdata/java8/InterfaceMethod.java @@ -15,6 +15,7 @@ package com.google.devtools.build.android.desugar.testdata.java8; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Desugar test input interface that declares lambdas and method references in default and static @@ -25,6 +26,10 @@ public interface InterfaceMethod { return names.stream().filter(this::startsWithS).collect(Collectors.toList()); } + public default String defaultInvokingBootclasspathMethods(String expectedValue) { + return Stream.of(expectedValue).findFirst().orElse("unexpected"); + } + public default List<String> staticMethodReference(List<String> names) { return names.stream().filter(InterfaceMethod::startsWithA).collect(Collectors.toList()); } diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/separate8/SeparateInterfaceThatInheritsDefaultMethod.java b/test/java/com/google/devtools/build/android/desugar/testdata/separate8/SeparateInterfaceThatInheritsDefaultMethod.java new file mode 100644 index 0000000..400a6f1 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/separate8/SeparateInterfaceThatInheritsDefaultMethod.java @@ -0,0 +1,18 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.separate8; + +/** Interface that inherits default method in separate compilation target for testing b/65645388. */ +public interface SeparateInterfaceThatInheritsDefaultMethod + extends SeparateInterfaceWithDefaultMethod {} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata/separate8/SeparateInterfaceWithDefaultMethod.java b/test/java/com/google/devtools/build/android/desugar/testdata/separate8/SeparateInterfaceWithDefaultMethod.java new file mode 100644 index 0000000..b3c04c8 --- /dev/null +++ b/test/java/com/google/devtools/build/android/desugar/testdata/separate8/SeparateInterfaceWithDefaultMethod.java @@ -0,0 +1,21 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.testdata.separate8; + +/** Interface with default method in separate compilation target for testing b/65645388. */ +public interface SeparateInterfaceWithDefaultMethod { + default String dflt() { + return "dflt"; + } +} diff --git a/test/java/com/google/devtools/build/android/desugar/testdata_desugared_java8_jar_toc_golden.txt b/test/java/com/google/devtools/build/android/desugar/testdata_desugared_java8_jar_toc_golden.txt index 8664932..907edd0 100644 --- a/test/java/com/google/devtools/build/android/desugar/testdata_desugared_java8_jar_toc_golden.txt +++ b/test/java/com/google/devtools/build/android/desugar/testdata_desugared_java8_jar_toc_golden.txt @@ -56,6 +56,9 @@ com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceMethodW com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceMethodWithStaticInitializer.class com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceWithBridges.class com/google/devtools/build/android/desugar/testdata/java8/DefaultInterfaceWithLambda.class +com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8Target.class +com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodFromSeparateJava8TargetOverridden.class +com/google/devtools/build/android/desugar/testdata/java8/DefaultMethodTransitivelyFromSeparateJava8Target.class com/google/devtools/build/android/desugar/testdata/java8/FunctionWithDefaultMethod$DoubleInts.class com/google/devtools/build/android/desugar/testdata/java8/FunctionWithDefaultMethod$DoubleInts2.class com/google/devtools/build/android/desugar/testdata/java8/FunctionWithDefaultMethod.class |