Introduce IdentityConversionCheck

This commit is contained in:
Rick Ossendrijver
2022-01-04 11:35:59 +01:00
committed by Rick Ossendrijver
parent 72a8bf7e12
commit 0824a5254b
26 changed files with 338 additions and 157 deletions

View File

@@ -0,0 +1,91 @@
package tech.picnic.errorprone.bugpatterns;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.staticMethod;
import com.google.auto.service.AutoService;
import com.google.errorprone.BugPattern;
import com.google.errorprone.BugPattern.LinkType;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.errorprone.BugPattern.StandardTags;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.fixes.SuggestedFixes;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.util.ASTHelpers;
import com.google.errorprone.util.ASTHelpers.TargetType;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.code.Type;
import java.util.List;
/** A {@link BugChecker} that flags redundant identity conversions. */
@AutoService(BugChecker.class)
@BugPattern(
name = "IdentityConversion",
summary = "Avoid or clarify identity conversions",
linkType = LinkType.NONE,
severity = SeverityLevel.WARNING,
tags = StandardTags.SIMPLIFICATION)
public final class IdentityConversionCheck extends BugChecker
implements MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<ExpressionTree> IS_CONVERSION_METHOD =
anyOf(
staticMethod()
.onClassAny(
"com.google.common.collect.ImmutableBiMap",
"com.google.common.collect.ImmutableList",
"com.google.common.collect.ImmutableListMultimap",
"com.google.common.collect.ImmutableMap",
"com.google.common.collect.ImmutableMultimap",
"com.google.common.collect.ImmutableMultiset",
"com.google.common.collect.ImmutableRangeMap",
"com.google.common.collect.ImmutableRangeSet",
"com.google.common.collect.ImmutableSet",
"com.google.common.collect.ImmutableSetMultimap",
"com.google.common.collect.ImmutableTable")
.named("copyOf"),
staticMethod()
.onClassAny(
Byte.class.getName(),
Character.class.getName(),
Double.class.getName(),
Float.class.getName(),
Integer.class.getName(),
String.class.getName())
.named("valueOf"),
staticMethod().onClass("reactor.adapter.rxjava.RxJava2Adapter"),
staticMethod()
.onClass("reactor.core.publisher.Flux")
.namedAnyOf("concat", "firstWithSignal", "from", "merge"),
staticMethod().onClass("reactor.core.publisher.Mono").namedAnyOf("from", "fromDirect"));
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
List<? extends ExpressionTree> arguments = tree.getArguments();
if (arguments.size() != 1 || !IS_CONVERSION_METHOD.matches(tree, state)) {
return Description.NO_MATCH;
}
ExpressionTree sourceTree = arguments.get(0);
Type sourceType = ASTHelpers.getType(sourceTree);
TargetType targetType = ASTHelpers.targetType(state);
if (sourceType == null
|| targetType == null
|| !state.getTypes().isSubtype(sourceType, targetType.type())) {
return Description.NO_MATCH;
}
return buildDescription(tree)
.setMessage(
"This method invocation appears redundant; remove it or suppress this warning and "
+ "add an comment explaining its purpose")
.addFix(SuggestedFix.replace(tree, state.getSourceForNode(sourceTree)))
.addFix(SuggestedFixes.addSuppressWarnings(state, canonicalName()))
.build();
}
}

View File

@@ -177,9 +177,7 @@ final class AssortedTemplates {
@BeforeTemplate
boolean before(Collection<T> collection1, Collection<T> collection2) {
return Refaster.anyOf(
Collections.disjoint(ImmutableSet.copyOf(collection1), collection2),
Collections.disjoint(new HashSet<>(collection1), collection2),
Collections.disjoint(collection1, ImmutableSet.copyOf(collection2)),
Collections.disjoint(collection1, new HashSet<>(collection2)));
}

View File

@@ -272,17 +272,4 @@ final class ImmutableListMultimapTemplates {
return ImmutableListMultimap.copyOf(Multimaps.transformValues(multimap, transformation));
}
}
/** Don't unnecessarily copy an {@link ImmutableListMultimap}. */
static final class ImmutableListMultimapCopyOfImmutableListMultimap<K, V> {
@BeforeTemplate
ImmutableListMultimap<K, V> before(ImmutableListMultimap<K, V> multimap) {
return ImmutableListMultimap.copyOf(multimap);
}
@AfterTemplate
ImmutableListMultimap<K, V> after(ImmutableListMultimap<K, V> multimap) {
return multimap;
}
}
}

View File

@@ -331,19 +331,6 @@ final class ImmutableMapTemplates {
}
}
/** Don't unnecessarily copy an {@link ImmutableMap}. */
static final class ImmutableMapCopyOfImmutableMap<K, V> {
@BeforeTemplate
ImmutableMap<K, V> before(ImmutableMap<K, V> map) {
return ImmutableMap.copyOf(map);
}
@AfterTemplate
ImmutableMap<K, V> after(ImmutableMap<K, V> map) {
return map;
}
}
// XXX: Add a template for this:
// Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf)
// ->

View File

@@ -101,17 +101,4 @@ final class ImmutableMultisetTemplates {
return stream.collect(toImmutableMultiset());
}
}
/** Don't unnecessarily copy an {@link ImmutableMultiset}. */
static final class ImmutableMultisetCopyOfImmutableMultiset<T> {
@BeforeTemplate
ImmutableMultiset<T> before(ImmutableMultiset<T> multiset) {
return ImmutableMultiset.copyOf(multiset);
}
@AfterTemplate
ImmutableMultiset<T> after(ImmutableMultiset<T> multiset) {
return multiset;
}
}
}

View File

@@ -215,17 +215,4 @@ final class ImmutableSetMultimapTemplates {
return ImmutableSetMultimap.copyOf(Multimaps.transformValues(multimap, transformation));
}
}
/** Don't unnecessarily copy an {@link ImmutableSetMultimap}. */
static final class ImmutableSetMultimapCopyOfImmutableSetMultimap<K, V> {
@BeforeTemplate
ImmutableSetMultimap<K, V> before(ImmutableSetMultimap<K, V> multimap) {
return ImmutableSetMultimap.copyOf(multimap);
}
@AfterTemplate
ImmutableSetMultimap<K, V> after(ImmutableSetMultimap<K, V> multimap) {
return multimap;
}
}
}

View File

@@ -126,19 +126,6 @@ final class ImmutableSetTemplates {
}
}
/** Don't unnecessarily copy an {@link ImmutableSet}. */
static final class ImmutableSetCopyOfImmutableSet<T> {
@BeforeTemplate
ImmutableSet<T> before(ImmutableSet<T> set) {
return ImmutableSet.copyOf(set);
}
@AfterTemplate
ImmutableSet<T> after(ImmutableSet<T> set) {
return set;
}
}
/** Prefer {@link SetView#immutableCopy()} over the more verbose alternative. */
static final class ImmutableSetCopyOfSetView<T> {
@BeforeTemplate

View File

@@ -203,19 +203,6 @@ final class ReactorTemplates {
}
}
/** Don't unnecessarily invoke {@link Flux#concat(Publisher)}. */
static final class FluxIdentity<T> {
@BeforeTemplate
Flux<T> before(Flux<T> flux) {
return Flux.concat(flux);
}
@AfterTemplate
Flux<T> after(Flux<T> flux) {
return flux;
}
}
/**
* Prefer a collection using {@link MoreCollectors#toOptional()} over more contrived alternatives.
*/

View File

@@ -41,11 +41,9 @@ final class RxJava2AdapterTemplates {
@BeforeTemplate
Publisher<T> before(Flowable<T> flowable) {
return Refaster.anyOf(
Flux.from(flowable),
flowable.compose(Flux::from),
flowable.to(Flux::from),
flowable.as(Flux::from),
RxJava2Adapter.flowableToFlux(flowable),
flowable.compose(RxJava2Adapter::flowableToFlux),
flowable.to(RxJava2Adapter::flowableToFlux));
}
@@ -67,7 +65,6 @@ final class RxJava2AdapterTemplates {
Flowable.fromPublisher(flux),
flux.transform(Flowable::fromPublisher),
flux.as(Flowable::fromPublisher),
RxJava2Adapter.fluxToFlowable(flux),
flux.transform(RxJava2Adapter::fluxToFlowable));
}
@@ -140,7 +137,6 @@ final class RxJava2AdapterTemplates {
Flowable.fromPublisher(mono),
mono.transform(Flowable::fromPublisher),
mono.as(Flowable::fromPublisher),
RxJava2Adapter.monoToFlowable(mono),
mono.transform(RxJava2Adapter::monoToFlowable));
}

View File

@@ -0,0 +1,234 @@
package tech.picnic.errorprone.bugpatterns;
import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
import org.junit.jupiter.api.Test;
final class IdentityConversionCheckTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(IdentityConversionCheck.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(IdentityConversionCheck.class, getClass());
@Test
void identification() {
compilationTestHelper
.addSourceLines(
"Foo.java",
"import com.google.common.collect.ImmutableBiMap;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableListMultimap;",
"import com.google.common.collect.ImmutableMap;",
"import com.google.common.collect.ImmutableMultimap;",
"import com.google.common.collect.ImmutableMultiset;",
"import com.google.common.collect.ImmutableRangeMap;",
"import com.google.common.collect.ImmutableRangeSet;",
"import com.google.common.collect.ImmutableSet;",
"import com.google.common.collect.ImmutableSetMultimap;",
"import com.google.common.collect.ImmutableTable;",
"import reactor.adapter.rxjava.RxJava2Adapter;",
"import reactor.core.publisher.Flux;",
"import reactor.core.publisher.Mono;",
"",
"public final class Foo {",
" public void foo() {",
" // BUG: Diagnostic contains:",
" Byte b1 = Byte.valueOf((Byte) Byte.MIN_VALUE);",
" Byte b2 = Byte.valueOf(Byte.MIN_VALUE);",
" byte b3 = Byte.valueOf((Byte) Byte.MIN_VALUE);",
" // BUG: Diagnostic contains:",
" byte b4 = Byte.valueOf(Byte.MIN_VALUE);",
"",
" // BUG: Diagnostic contains:",
" Character c1 = Character.valueOf((Character) 'a');",
" Character c2 = Character.valueOf('a');",
" char c3 = Character.valueOf((Character)'a');",
" // BUG: Diagnostic contains:",
" char c4 = Character.valueOf('a');",
"",
" // BUG: Diagnostic contains:",
" Integer int1 = Integer.valueOf((Integer) 1);",
" Integer int2 = Integer.valueOf(1);",
" int int3 = Integer.valueOf((Integer) 1);",
" // BUG: Diagnostic contains:",
" int int4 = Integer.valueOf(1);",
"",
" String s1 = String.valueOf(0);",
" // BUG: Diagnostic contains:",
" String s2 = String.valueOf(\"1\");",
"",
" // BUG: Diagnostic contains:",
" ImmutableBiMap<Object, Object> i2 = ImmutableBiMap.copyOf(ImmutableBiMap.of());",
" // BUG: Diagnostic contains:",
" ImmutableList<Object> i3 = ImmutableList.copyOf(ImmutableList.of());",
" // BUG: Diagnostic contains:",
" ImmutableListMultimap<Object, Object> i4 = ImmutableListMultimap.copyOf(ImmutableListMultimap.of());",
" // BUG: Diagnostic contains:",
" ImmutableMap<Object, Object> i5 = ImmutableMap.copyOf(ImmutableMap.of());",
" // BUG: Diagnostic contains:",
" ImmutableMultimap<Object, Object> i6 = ImmutableMultimap.copyOf(ImmutableMultimap.of());",
" // BUG: Diagnostic contains:",
" ImmutableMultiset<Object> i7 = ImmutableMultiset.copyOf(ImmutableMultiset.of());",
" // BUG: Diagnostic contains:",
" ImmutableRangeMap<String, Object> i8 = ImmutableRangeMap.copyOf(ImmutableRangeMap.of());",
" // BUG: Diagnostic contains:",
" ImmutableRangeSet<String> i9 = ImmutableRangeSet.copyOf(ImmutableRangeSet.of());",
" // BUG: Diagnostic contains:",
" ImmutableSet<Object> i10 = ImmutableSet.copyOf(ImmutableSet.of());",
" // BUG: Diagnostic contains:",
" ImmutableSetMultimap<Object, Object> i11 = ImmutableSetMultimap.copyOf(ImmutableSetMultimap.of());",
" // BUG: Diagnostic contains:",
" ImmutableTable<Object, Object, Object> i15 = ImmutableTable.copyOf(ImmutableTable.of());",
"",
" // BUG: Diagnostic contains:",
" Flux<Integer> f1 = Flux.just(1).flatMap(e -> RxJava2Adapter.fluxToFlowable(Flux.just(2)));",
" // BUG: Diagnostic contains:",
" Flux<Integer> f2 = Flux.concat(Flux.just(1));",
" // BUG: Diagnostic contains:",
" Flux<Integer> f3 = Flux.firstWithSignal(Flux.just(1));",
" // BUG: Diagnostic contains:",
" Flux<Integer> f4 = Flux.from(Flux.just(1));",
" // BUG: Diagnostic contains:",
" Flux<Integer> f5 = Flux.merge(Flux.just(1));",
"",
" // BUG: Diagnostic contains:",
" Mono<Integer> m1 = Mono.from(Mono.just(1));",
" // BUG: Diagnostic contains:",
" Mono<Integer> m2 = Mono.fromDirect(Mono.just(1));",
" }",
"}")
.doTest();
}
@Test
void replacementFirstSuggestedFix() {
refactoringTestHelper
.setFixChooser(FixChoosers.FIRST)
.addInputLines(
"Foo.java",
"import com.google.common.collect.ImmutableCollection;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableSet;",
"import java.util.Collection;",
"import java.util.ArrayList;",
"import org.reactivestreams.Publisher;",
"import reactor.adapter.rxjava.RxJava2Adapter;",
"import reactor.core.publisher.Flux;",
"import reactor.core.publisher.Mono;",
"",
"public final class Foo {",
" public void foo() {",
" ImmutableSet<Object> set1 = ImmutableSet.copyOf(ImmutableSet.of());",
" ImmutableSet<Object> set2 = ImmutableSet.copyOf(ImmutableList.of());",
"",
" ImmutableCollection<Integer> list1 = ImmutableList.copyOf(ImmutableList.of(1));",
" ImmutableCollection<Integer> list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));",
"",
" Collection<Integer> c1 = ImmutableSet.copyOf(ImmutableSet.of(1));",
" Collection<Integer> c2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));",
"",
" Flux<Integer> f1 = Flux.just(1).flatMap(e -> RxJava2Adapter.fluxToFlowable(Flux.just(2)));",
" Flux<Integer> f2 = Flux.concat(Flux.just(3));",
" Publisher<Integer> f3 = Flux.firstWithSignal(Flux.just(4));",
" Publisher<Integer> f4 = Flux.from(Flux.just(5));",
" Publisher<Integer> f5 = Flux.merge(Flux.just(6));",
"",
" Mono<Integer> m1 = Mono.from(Mono.just(7));",
" Publisher<Integer> m2 = Mono.fromDirect(Mono.just(8));",
"",
" bar(Flux.concat(Flux.just(9)));",
" bar(Mono.from(Mono.just(10)));",
" }",
"",
" void bar(Publisher<Integer> publisher) {}",
"}")
.addOutputLines(
"Foo.java",
"import com.google.common.collect.ImmutableCollection;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableSet;",
"import java.util.Collection;",
"import java.util.ArrayList;",
"import org.reactivestreams.Publisher;",
"import reactor.adapter.rxjava.RxJava2Adapter;",
"import reactor.core.publisher.Flux;",
"import reactor.core.publisher.Mono;",
"",
"public final class Foo {",
" public void foo() {",
" ImmutableSet<Object> set1 = ImmutableSet.of();",
" ImmutableSet<Object> set2 = ImmutableSet.copyOf(ImmutableList.of());",
"",
" ImmutableCollection<Integer> list1 = ImmutableList.of(1);",
" ImmutableCollection<Integer> list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));",
"",
" Collection<Integer> c1 = ImmutableSet.of(1);",
" Collection<Integer> c2 = new ArrayList<>(ImmutableList.of(1));",
"",
" Flux<Integer> f1 = Flux.just(1).flatMap(e -> Flux.just(2));",
" Flux<Integer> f2 = Flux.just(3);",
" Publisher<Integer> f3 = Flux.just(4);",
" Publisher<Integer> f4 = Flux.just(5);",
" Publisher<Integer> f5 = Flux.just(6);",
"",
" Mono<Integer> m1 = Mono.just(7);",
" Publisher<Integer> m2 = Mono.just(8);",
"",
" bar(Flux.just(9));",
" bar(Mono.just(10));",
" }",
"",
" void bar(Publisher<Integer> publisher) {}",
"}")
.doTest(TestMode.TEXT_MATCH);
}
@Test
void replacementSecondSuggestedFix() {
refactoringTestHelper
.setFixChooser(FixChoosers.SECOND)
.addInputLines(
"Foo.java",
"import com.google.common.collect.ImmutableCollection;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableSet;",
"import java.util.ArrayList;",
"import reactor.adapter.rxjava.RxJava2Adapter;",
"import reactor.core.publisher.Flux;",
"import reactor.core.publisher.Mono;",
"",
"public final class Foo {",
" public void foo() {",
" ImmutableSet<Object> set1 = ImmutableSet.copyOf(ImmutableSet.of());",
" ImmutableSet<Object> set2 = ImmutableSet.copyOf(ImmutableList.of());",
"",
" ImmutableCollection<Integer> list1 = ImmutableList.copyOf(ImmutableList.of(1));",
" ImmutableCollection<Integer> list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));",
" }",
"}")
.addOutputLines(
"Foo.java",
"import com.google.common.collect.ImmutableCollection;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableSet;",
"import java.util.ArrayList;",
"import reactor.adapter.rxjava.RxJava2Adapter;",
"import reactor.core.publisher.Flux;",
"import reactor.core.publisher.Mono;",
"",
"public final class Foo {",
" public void foo() {",
" @SuppressWarnings(\"IdentityConversion\")",
" ImmutableSet<Object> set1 = ImmutableSet.copyOf(ImmutableSet.of());",
" ImmutableSet<Object> set2 = ImmutableSet.copyOf(ImmutableList.of());",
"",
" @SuppressWarnings(\"IdentityConversion\")",
" ImmutableCollection<Integer> list1 = ImmutableList.copyOf(ImmutableList.of(1));",
" ImmutableCollection<Integer> list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));",
" }",
"}")
.doTest(TestMode.TEXT_MATCH);
}
}

View File

@@ -78,10 +78,8 @@ final class AssortedTemplatesTest implements RefasterTemplateTestCase {
ImmutableSet<Boolean> testDisjointCollections() {
return ImmutableSet.of(
Collections.disjoint(ImmutableSet.copyOf(ImmutableList.of(1)), ImmutableList.of(2)),
Collections.disjoint(new HashSet<>(ImmutableList.of(3)), ImmutableList.of(4)),
Collections.disjoint(ImmutableList.of(5), ImmutableSet.copyOf(ImmutableList.of(6))),
Collections.disjoint(ImmutableList.of(7), new HashSet<>(ImmutableList.of(8))));
Collections.disjoint(new HashSet<>(ImmutableList.of(1)), ImmutableList.of(2)),
Collections.disjoint(ImmutableList.of(3), new HashSet<>(ImmutableList.of(4))));
}
boolean testIterableIsEmpty() {

View File

@@ -81,9 +81,7 @@ final class AssortedTemplatesTest implements RefasterTemplateTestCase {
ImmutableSet<Boolean> testDisjointCollections() {
return ImmutableSet.of(
Collections.disjoint(ImmutableList.of(1), ImmutableList.of(2)),
Collections.disjoint(ImmutableList.of(3), ImmutableList.of(4)),
Collections.disjoint(ImmutableList.of(5), ImmutableList.of(6)),
Collections.disjoint(ImmutableList.of(7), ImmutableList.of(8)));
Collections.disjoint(ImmutableList.of(3), ImmutableList.of(4)));
}
boolean testIterableIsEmpty() {

View File

@@ -113,8 +113,4 @@ final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCa
flatteningToImmutableListMultimap(
Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact))));
}
ImmutableListMultimap<String, Integer> testImmutableListMultimapCopyOfImmutableListMultimap() {
return ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1));
}
}

View File

@@ -89,8 +89,4 @@ final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCa
ImmutableListMultimap.copyOf(
Multimaps.transformValues(TreeMultimap.<String, Long>create(), Math::toIntExact)));
}
ImmutableListMultimap<String, Integer> testImmutableListMultimapCopyOfImmutableListMultimap() {
return ImmutableListMultimap.of("foo", 1);
}
}

View File

@@ -104,8 +104,4 @@ final class ImmutableMapTemplatesTest implements RefasterTemplateTestCase {
ImmutableMap.of("bar", 2L).keySet(),
k -> Math.toIntExact(ImmutableMap.of("bar", 2L).get(k))));
}
ImmutableMap<String, Integer> testImmutableMapCopyOfImmutableMap() {
return ImmutableMap.copyOf(ImmutableMap.of("foo", 1));
}
}

View File

@@ -87,8 +87,4 @@ final class ImmutableMapTemplatesTest implements RefasterTemplateTestCase {
ImmutableMap.copyOf(
Maps.transformValues(ImmutableMap.of("bar", 2L), v -> Math.toIntExact(v))));
}
ImmutableMap<String, Integer> testImmutableMapCopyOfImmutableMap() {
return ImmutableMap.of("foo", 1);
}
}

View File

@@ -44,8 +44,4 @@ final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase {
ImmutableMultiset.copyOf(Stream.of(1).iterator()),
Stream.of(2).collect(collectingAndThen(toList(), ImmutableMultiset::copyOf)));
}
ImmutableMultiset<Integer> testImmutableMultisetCopyOfImmutableMultiset() {
return ImmutableMultiset.copyOf(ImmutableMultiset.of(1, 2));
}
}

View File

@@ -41,8 +41,4 @@ final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase {
return ImmutableSet.of(
Stream.of(1).collect(toImmutableMultiset()), Stream.of(2).collect(toImmutableMultiset()));
}
ImmutableMultiset<Integer> testImmutableMultisetCopyOfImmutableMultiset() {
return ImmutableMultiset.of(1, 2);
}
}

View File

@@ -91,8 +91,4 @@ final class ImmutableSetMultimapTemplatesTest implements RefasterTemplateTestCas
flatteningToImmutableSetMultimap(
Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact))));
}
ImmutableSetMultimap<String, Integer> testImmutableSetMultimapCopyOfImmutableSetMultimap() {
return ImmutableSetMultimap.copyOf(ImmutableSetMultimap.of("foo", 1));
}
}

View File

@@ -72,8 +72,4 @@ final class ImmutableSetMultimapTemplatesTest implements RefasterTemplateTestCas
ImmutableSetMultimap.copyOf(
Multimaps.transformValues(TreeMultimap.<String, Long>create(), Math::toIntExact)));
}
ImmutableSetMultimap<String, Integer> testImmutableSetMultimapCopyOfImmutableSetMultimap() {
return ImmutableSetMultimap.of("foo", 1);
}
}

View File

@@ -59,10 +59,6 @@ final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase {
Stream.of(4).collect(collectingAndThen(toSet(), ImmutableSet::copyOf)));
}
ImmutableSet<Integer> testImmutableSetCopyOfImmutableSet() {
return ImmutableSet.copyOf(ImmutableSet.of(1, 2));
}
ImmutableSet<Integer> testImmutableSetCopyOfSetView() {
return ImmutableSet.copyOf(Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)));
}

View File

@@ -58,10 +58,6 @@ final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase {
Stream.of(4).collect(toImmutableSet()));
}
ImmutableSet<Integer> testImmutableSetCopyOfImmutableSet() {
return ImmutableSet.of(1, 2);
}
ImmutableSet<Integer> testImmutableSetCopyOfSetView() {
return Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
}

View File

@@ -63,10 +63,6 @@ final class ReactorTemplatesTest implements RefasterTemplateTestCase {
return Flux.concat(Mono.just("foo"));
}
Flux<String> testFluxIdentity() {
return Flux.concat(Flux.just("foo"));
}
ImmutableSet<Mono<Optional<String>>> testMonoCollectToOptional() {
return ImmutableSet.of(
Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()),

View File

@@ -63,10 +63,6 @@ final class ReactorTemplatesTest implements RefasterTemplateTestCase {
return Mono.just("foo").flux();
}
Flux<String> testFluxIdentity() {
return Flux.just("foo");
}
ImmutableSet<Mono<Optional<String>>> testMonoCollectToOptional() {
return ImmutableSet.of(
Mono.just("foo").flux().collect(toOptional()),

View File

@@ -25,13 +25,11 @@ final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase {
// seventh parameter onwards.
return ImmutableSet.copyOf(
Arrays.asList(
Flux.from(Flowable.just(1)),
Flowable.just(2).compose(Flux::from),
Flowable.just(3).to(Flux::from),
Flowable.just(4).as(Flux::from),
RxJava2Adapter.flowableToFlux(Flowable.just(5)),
Flowable.just(6).compose(RxJava2Adapter::flowableToFlux),
Flowable.just(7).<Publisher<Integer>>to(RxJava2Adapter::flowableToFlux)));
Flowable.just(1).compose(Flux::from),
Flowable.just(2).to(Flux::from),
Flowable.just(3).as(Flux::from),
Flowable.just(4).compose(RxJava2Adapter::flowableToFlux),
Flowable.just(5).<Publisher<Integer>>to(RxJava2Adapter::flowableToFlux)));
}
ImmutableSet<Publisher<String>> testFluxToFlowable() {
@@ -39,8 +37,7 @@ final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase {
Flowable.fromPublisher(Flux.just("foo")),
Flux.just("bar").transform(Flowable::fromPublisher),
Flux.just("baz").as(Flowable::fromPublisher),
RxJava2Adapter.fluxToFlowable(Flux.just("qux")),
Flux.just("quux").transform(RxJava2Adapter::fluxToFlowable));
Flux.just("qux").transform(RxJava2Adapter::fluxToFlowable));
}
ImmutableSet<Observable<Integer>> testFluxToObservable() {
@@ -68,8 +65,7 @@ final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase {
Flowable.fromPublisher(Mono.just(1)),
Mono.just(2).transform(Flowable::fromPublisher),
Mono.just(3).as(Flowable::fromPublisher),
RxJava2Adapter.monoToFlowable(Mono.just(4)),
Mono.just(5).transform(RxJava2Adapter::monoToFlowable));
Mono.just(4).transform(RxJava2Adapter::monoToFlowable));
}
Maybe<String> testMonoToMaybe() {

View File

@@ -29,9 +29,7 @@ final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase {
Flowable.just(2).as(RxJava2Adapter::flowableToFlux),
Flowable.just(3).as(RxJava2Adapter::flowableToFlux),
Flowable.just(4).as(RxJava2Adapter::flowableToFlux),
Flowable.just(5).as(RxJava2Adapter::flowableToFlux),
Flowable.just(6).as(RxJava2Adapter::flowableToFlux),
Flowable.just(7).as(RxJava2Adapter::flowableToFlux)));
Flowable.just(5).as(RxJava2Adapter::flowableToFlux)));
}
ImmutableSet<Publisher<String>> testFluxToFlowable() {
@@ -39,8 +37,7 @@ final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase {
Flux.just("foo").as(RxJava2Adapter::fluxToFlowable),
Flux.just("bar").as(RxJava2Adapter::fluxToFlowable),
Flux.just("baz").as(RxJava2Adapter::fluxToFlowable),
Flux.just("qux").as(RxJava2Adapter::fluxToFlowable),
Flux.just("quux").as(RxJava2Adapter::fluxToFlowable));
Flux.just("qux").as(RxJava2Adapter::fluxToFlowable));
}
ImmutableSet<Observable<Integer>> testFluxToObservable() {
@@ -68,8 +65,7 @@ final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase {
Mono.just(1).as(RxJava2Adapter::monoToFlowable),
Mono.just(2).as(RxJava2Adapter::monoToFlowable),
Mono.just(3).as(RxJava2Adapter::monoToFlowable),
Mono.just(4).as(RxJava2Adapter::monoToFlowable),
Mono.just(5).as(RxJava2Adapter::monoToFlowable));
Mono.just(4).as(RxJava2Adapter::monoToFlowable));
}
Maybe<String> testMonoToMaybe() {