| // Copyright (c) 2019, 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 com.android.tools.r8.desugar.desugaredlibrary; |
| |
| import static com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification.DEFAULT_SPECIFICATIONS; |
| import static com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification.getJdk8Jdk11; |
| |
| import com.android.tools.r8.TestParameters; |
| import com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification; |
| import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification; |
| import com.android.tools.r8.utils.StringUtils; |
| import java.util.AbstractCollection; |
| import java.util.Collection; |
| import java.util.Collections; |
| import java.util.Iterator; |
| import java.util.List; |
| import java.util.function.Predicate; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.junit.runners.Parameterized; |
| import org.junit.runners.Parameterized.Parameters; |
| |
| @SuppressWarnings("ALL") |
| @RunWith(Parameterized.class) |
| public class MinimalInterfaceSuperTest extends DesugaredLibraryTestBase { |
| |
| private static final String EXPECTED_OUTPUT = StringUtils.lines("removeIf from Col1Itf"); |
| |
| private final TestParameters parameters; |
| private final LibraryDesugaringSpecification libraryDesugaringSpecification; |
| private final CompilationSpecification compilationSpecification; |
| |
| @Parameters(name = "{0}, spec: {1}, {2}") |
| public static List<Object[]> data() { |
| return buildParameters( |
| getTestParameters().withAllRuntimes().withAllApiLevels().build(), |
| getJdk8Jdk11(), |
| DEFAULT_SPECIFICATIONS); |
| } |
| |
| public MinimalInterfaceSuperTest( |
| TestParameters parameters, |
| LibraryDesugaringSpecification libraryDesugaringSpecification, |
| CompilationSpecification compilationSpecification) { |
| this.parameters = parameters; |
| this.libraryDesugaringSpecification = libraryDesugaringSpecification; |
| this.compilationSpecification = compilationSpecification; |
| } |
| |
| @Test |
| public void testMinimalInterfaceSuper() throws Exception { |
| if (parameters.isCfRuntime()) { |
| testForJvm() |
| .addInnerClasses(MinimalInterfaceSuperTest.class) |
| .run(parameters.getRuntime(), Main.class) |
| .assertSuccessWithOutput(EXPECTED_OUTPUT); |
| return; |
| } |
| testForDesugaredLibrary(parameters, libraryDesugaringSpecification, compilationSpecification) |
| .addInnerClasses(getClass()) |
| .addKeepMainRule(Main.class) |
| .run(parameters.getRuntime(), Main.class) |
| .assertSuccessWithOutput(EXPECTED_OUTPUT); |
| } |
| |
| static class Main { |
| public static void main(String[] args) { |
| Col1<Integer> ints1 = new Col1<>(); |
| ints1.removeIf(x -> x == 3); |
| } |
| } |
| |
| interface Col1Itf<E> extends Collection<E> { |
| @Override |
| default boolean removeIf(Predicate<? super E> filter) { |
| System.out.println("removeIf from Col1Itf"); |
| return Collection.super.removeIf(filter); |
| } |
| } |
| |
| static class Col1<E> extends AbstractCollection<E> implements Col1Itf<E> { |
| @Override |
| public Iterator<E> iterator() { |
| return Collections.emptyIterator(); |
| } |
| |
| @Override |
| public int size() { |
| return 0; |
| } |
| } |
| } |