From d2bbee3ed9953598d3e75ff5bd381a2616b8693d Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 8 Apr 2022 13:28:12 +0200 Subject: [PATCH] Introduce `IdentityConversionCheck` (#27) And remove any Refaster templates it subsumes. --- .../bugpatterns/IdentityConversionCheck.java | 111 +++++++ .../AssertJByteTemplates.java | 11 +- .../AssertJDoubleTemplates.java | 11 +- .../AssertJFloatTemplates.java | 12 +- .../AssertJIntegerTemplates.java | 12 +- .../AssertJLongTemplates.java | 12 +- .../AssertJShortTemplates.java | 11 +- .../ImmutableListMultimapTemplates.java | 13 - .../ImmutableMapTemplates.java | 13 - .../ImmutableMultisetTemplates.java | 13 - .../ImmutableSetMultimapTemplates.java | 13 - .../ImmutableSetTemplates.java | 13 - .../refastertemplates/ReactorTemplates.java | 13 - .../RxJava2AdapterTemplates.java | 4 - .../IdentityConversionCheckTest.java | 308 ++++++++++++++++++ .../AssertJByteTemplatesTestInput.java | 10 +- .../AssertJByteTemplatesTestOutput.java | 12 +- .../AssertJDoubleTemplatesTestInput.java | 11 +- .../AssertJDoubleTemplatesTestOutput.java | 14 +- .../AssertJFloatTemplatesTestInput.java | 11 +- .../AssertJFloatTemplatesTestOutput.java | 14 +- .../AssertJIntegerTemplatesTestInput.java | 12 +- .../AssertJIntegerTemplatesTestOutput.java | 14 +- .../AssertJLongTemplatesTestInput.java | 11 +- .../AssertJLongTemplatesTestOutput.java | 14 +- .../AssertJShortTemplatesTestInput.java | 10 +- .../AssertJShortTemplatesTestOutput.java | 9 +- ...mutableListMultimapTemplatesTestInput.java | 4 - ...utableListMultimapTemplatesTestOutput.java | 4 - .../ImmutableMapTemplatesTestInput.java | 4 - .../ImmutableMapTemplatesTestOutput.java | 4 - .../ImmutableMultisetTemplatesTestInput.java | 4 - .../ImmutableMultisetTemplatesTestOutput.java | 4 - ...mmutableSetMultimapTemplatesTestInput.java | 4 - ...mutableSetMultimapTemplatesTestOutput.java | 4 - .../ImmutableSetTemplatesTestInput.java | 4 - .../ImmutableSetTemplatesTestOutput.java | 4 - .../ReactorTemplatesTestInput.java | 4 - .../ReactorTemplatesTestOutput.java | 4 - .../RxJava2AdapterTemplatesTestInput.java | 18 +- .../RxJava2AdapterTemplatesTestOutput.java | 10 +- 41 files changed, 464 insertions(+), 324 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheck.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheckTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheck.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheck.java new file mode 100644 index 0000000000..9fb3587dcc --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheck.java @@ -0,0 +1,111 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.errorprone.BugPattern.LinkType.NONE; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; +import static com.google.errorprone.matchers.Matchers.anyOf; +import static com.google.errorprone.matchers.Matchers.staticMethod; +import static com.google.errorprone.suppliers.Suppliers.OBJECT_TYPE; + +import com.google.auto.service.AutoService; +import com.google.common.primitives.Primitives; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.bugpatterns.TypesWithUndefinedEquality; +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 com.sun.tools.javac.code.Types; +import java.util.Arrays; +import java.util.List; + +/** A {@link BugChecker} that flags redundant identity conversions. */ +// XXX: Consider detecting cases where a flagged expression is passed to a method, and where removal +// of the identify conversion would cause a different method overload to be selected. Depending on +// the target method such a modification may change the code's semantics or performance. +@AutoService(BugChecker.class) +@BugPattern( + name = "IdentityConversion", + summary = "Avoid or clarify identity conversions", + linkType = NONE, + severity = WARNING, + tags = SIMPLIFICATION) +public final class IdentityConversionCheck extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher 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( + Primitives.allWrapperTypes().stream() + .map(Class::getName) + .collect(toImmutableSet())) + .named("valueOf"), + staticMethod().onClass(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 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); + Type resultType = ASTHelpers.getType(tree); + TargetType targetType = ASTHelpers.targetType(state); + if (sourceType == null || resultType == null || targetType == null) { + return Description.NO_MATCH; + } + + if (!state.getTypes().isSameType(sourceType, resultType) + && !isConvertibleWithWellDefinedEquality(sourceType, targetType.type(), state)) { + return Description.NO_MATCH; + } + + return buildDescription(tree) + .setMessage( + "This method invocation appears redundant; remove it or suppress this warning and " + + "add a comment explaining its purpose") + .addFix(SuggestedFix.replace(tree, Util.treeToString(sourceTree, state))) + .addFix(SuggestedFixes.addSuppressWarnings(state, canonicalName())) + .build(); + } + + private static boolean isConvertibleWithWellDefinedEquality( + Type sourceType, Type targetType, VisitorState state) { + Types types = state.getTypes(); + return !types.isSameType(targetType, OBJECT_TYPE.get(state)) + && types.isConvertible(sourceType, targetType) + && Arrays.stream(TypesWithUndefinedEquality.values()) + .noneMatch(b -> b.matchesType(sourceType, state) || b.matchesType(targetType, state)); + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java index 97f86e6331..220e3001e7 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java @@ -15,11 +15,7 @@ static final class AbstractByteAssertIsEqualTo { @BeforeTemplate AbstractByteAssert before(AbstractByteAssert byteAssert, byte n) { return Refaster.anyOf( - byteAssert.isCloseTo(n, offset((byte) 0)), - byteAssert.isCloseTo(Byte.valueOf(n), offset((byte) 0)), - byteAssert.isCloseTo(n, withPercentage(0)), - byteAssert.isCloseTo(Byte.valueOf(n), withPercentage(0)), - byteAssert.isEqualTo(Byte.valueOf(n))); + byteAssert.isCloseTo(n, offset((byte) 0)), byteAssert.isCloseTo(n, withPercentage(0))); } @AfterTemplate @@ -33,10 +29,7 @@ static final class AbstractByteAssertIsNotEqualTo { AbstractByteAssert before(AbstractByteAssert byteAssert, byte n) { return Refaster.anyOf( byteAssert.isNotCloseTo(n, offset((byte) 0)), - byteAssert.isNotCloseTo(Byte.valueOf(n), offset((byte) 0)), - byteAssert.isNotCloseTo(n, withPercentage(0)), - byteAssert.isNotCloseTo(Byte.valueOf(n), withPercentage(0)), - byteAssert.isNotEqualTo(Byte.valueOf(n))); + byteAssert.isNotCloseTo(n, withPercentage(0))); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java index b158aad75f..44dc57b014 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java @@ -36,11 +36,7 @@ static final class AbstractDoubleAssertIsEqualTo { @BeforeTemplate AbstractDoubleAssert before(AbstractDoubleAssert doubleAssert, double n) { return Refaster.anyOf( - doubleAssert.isCloseTo(n, offset(0.0)), - doubleAssert.isCloseTo(Double.valueOf(n), offset(0.0)), - doubleAssert.isCloseTo(n, withPercentage(0.0)), - doubleAssert.isCloseTo(Double.valueOf(n), withPercentage(0.0)), - doubleAssert.isEqualTo(Double.valueOf(n))); + doubleAssert.isCloseTo(n, offset(0.0)), doubleAssert.isCloseTo(n, withPercentage(0.0))); } @AfterTemplate @@ -54,10 +50,7 @@ static final class AbstractDoubleAssertIsNotEqualTo { AbstractDoubleAssert before(AbstractDoubleAssert doubleAssert, double n) { return Refaster.anyOf( doubleAssert.isNotCloseTo(n, offset(0.0)), - doubleAssert.isNotCloseTo(Double.valueOf(n), offset(0.0)), - doubleAssert.isNotCloseTo(n, withPercentage(0.0)), - doubleAssert.isNotCloseTo(Double.valueOf(n), withPercentage(0.0)), - doubleAssert.isNotEqualTo(Double.valueOf(n))); + doubleAssert.isNotCloseTo(n, withPercentage(0.0))); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java index 059e2667d8..6de54b99cb 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java @@ -36,11 +36,7 @@ static final class AbstractFloatAssertIsEqualTo { @BeforeTemplate AbstractFloatAssert before(AbstractFloatAssert floatAssert, float n) { return Refaster.anyOf( - floatAssert.isCloseTo(n, offset(0F)), - floatAssert.isCloseTo(Float.valueOf(n), offset(0F)), - floatAssert.isCloseTo(n, withPercentage(0)), - floatAssert.isCloseTo(Float.valueOf(n), withPercentage(0)), - floatAssert.isEqualTo(Float.valueOf(n))); + floatAssert.isCloseTo(n, offset(0F)), floatAssert.isCloseTo(n, withPercentage(0))); } @AfterTemplate @@ -53,11 +49,7 @@ static final class AbstractFloatAssertIsNotEqualTo { @BeforeTemplate AbstractFloatAssert before(AbstractFloatAssert floatAssert, float n) { return Refaster.anyOf( - floatAssert.isNotCloseTo(n, offset(0F)), - floatAssert.isNotCloseTo(Float.valueOf(n), offset(0F)), - floatAssert.isNotCloseTo(n, withPercentage(0)), - floatAssert.isNotCloseTo(Float.valueOf(n), withPercentage(0)), - floatAssert.isNotEqualTo(Float.valueOf(n))); + floatAssert.isNotCloseTo(n, offset(0F)), floatAssert.isNotCloseTo(n, withPercentage(0))); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java index f8ee52c6a7..f46ac40564 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java @@ -15,11 +15,7 @@ static final class AbstractIntegerAssertIsEqualTo { @BeforeTemplate AbstractIntegerAssert before(AbstractIntegerAssert intAssert, int n) { return Refaster.anyOf( - intAssert.isCloseTo(n, offset(0)), - intAssert.isCloseTo(Integer.valueOf(n), offset(0)), - intAssert.isCloseTo(n, withPercentage(0)), - intAssert.isCloseTo(Integer.valueOf(n), withPercentage(0)), - intAssert.isEqualTo(Integer.valueOf(n))); + intAssert.isCloseTo(n, offset(0)), intAssert.isCloseTo(n, withPercentage(0))); } @AfterTemplate @@ -32,11 +28,7 @@ static final class AbstractIntegerAssertIsNotEqualTo { @BeforeTemplate AbstractIntegerAssert before(AbstractIntegerAssert intAssert, int n) { return Refaster.anyOf( - intAssert.isNotCloseTo(n, offset(0)), - intAssert.isNotCloseTo(Integer.valueOf(n), offset(0)), - intAssert.isNotCloseTo(n, withPercentage(0)), - intAssert.isNotCloseTo(Integer.valueOf(n), withPercentage(0)), - intAssert.isNotEqualTo(Integer.valueOf(n))); + intAssert.isNotCloseTo(n, offset(0)), intAssert.isNotCloseTo(n, withPercentage(0))); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java index 9e6de98b74..e992886dff 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java @@ -15,11 +15,7 @@ static final class AbstractLongAssertIsEqualTo { @BeforeTemplate AbstractLongAssert before(AbstractLongAssert longAssert, long n) { return Refaster.anyOf( - longAssert.isCloseTo(n, offset(0L)), - longAssert.isCloseTo(Long.valueOf(n), offset(0L)), - longAssert.isCloseTo(n, withPercentage(0)), - longAssert.isCloseTo(Long.valueOf(n), withPercentage(0)), - longAssert.isEqualTo(Long.valueOf(n))); + longAssert.isCloseTo(n, offset(0L)), longAssert.isCloseTo(n, withPercentage(0))); } @AfterTemplate @@ -32,11 +28,7 @@ static final class AbstractLongAssertIsNotEqualTo { @BeforeTemplate AbstractLongAssert before(AbstractLongAssert longAssert, long n) { return Refaster.anyOf( - longAssert.isNotCloseTo(n, offset(0L)), - longAssert.isNotCloseTo(Long.valueOf(n), offset(0L)), - longAssert.isNotCloseTo(n, withPercentage(0)), - longAssert.isNotCloseTo(Long.valueOf(n), withPercentage(0)), - longAssert.isNotEqualTo(Long.valueOf(n))); + longAssert.isNotCloseTo(n, offset(0L)), longAssert.isNotCloseTo(n, withPercentage(0))); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java index dd71b89961..017f897b93 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java @@ -15,11 +15,7 @@ static final class AbstractShortAssertIsEqualTo { @BeforeTemplate AbstractShortAssert before(AbstractShortAssert shortAssert, short n) { return Refaster.anyOf( - shortAssert.isCloseTo(n, offset((short) 0)), - shortAssert.isCloseTo(Short.valueOf(n), offset((short) 0)), - shortAssert.isCloseTo(n, withPercentage(0)), - shortAssert.isCloseTo(Short.valueOf(n), withPercentage(0)), - shortAssert.isEqualTo(Short.valueOf(n))); + shortAssert.isCloseTo(n, offset((short) 0)), shortAssert.isCloseTo(n, withPercentage(0))); } @AfterTemplate @@ -33,10 +29,7 @@ static final class AbstractShortAssertIsNotEqualTo { AbstractShortAssert before(AbstractShortAssert shortAssert, short n) { return Refaster.anyOf( shortAssert.isNotCloseTo(n, offset((short) 0)), - shortAssert.isNotCloseTo(Short.valueOf(n), offset((short) 0)), - shortAssert.isNotCloseTo(n, withPercentage(0)), - shortAssert.isNotCloseTo(Short.valueOf(n), withPercentage(0)), - shortAssert.isNotEqualTo(Short.valueOf(n))); + shortAssert.isNotCloseTo(n, withPercentage(0))); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java index 43b1c04c21..61b39db642 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java @@ -272,17 +272,4 @@ ImmutableListMultimap after( return ImmutableListMultimap.copyOf(Multimaps.transformValues(multimap, transformation)); } } - - /** Don't unnecessarily copy an {@link ImmutableListMultimap}. */ - static final class ImmutableListMultimapCopyOfImmutableListMultimap { - @BeforeTemplate - ImmutableListMultimap before(ImmutableListMultimap multimap) { - return ImmutableListMultimap.copyOf(multimap); - } - - @AfterTemplate - ImmutableListMultimap after(ImmutableListMultimap multimap) { - return multimap; - } - } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java index 03f0690988..9c307a8e3a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java @@ -242,19 +242,6 @@ ImmutableMap after(Map map) { } } - /** Don't unnecessarily copy an {@link ImmutableMap}. */ - static final class ImmutableMapCopyOfImmutableMap { - @BeforeTemplate - ImmutableMap before(ImmutableMap map) { - return ImmutableMap.copyOf(map); - } - - @AfterTemplate - ImmutableMap after(ImmutableMap map) { - return map; - } - } - // XXX: Add a template for this: // Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf) // -> diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java index 4f7aa4aa92..adb6a0f5e3 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java @@ -101,17 +101,4 @@ ImmutableMultiset after(Stream stream) { return stream.collect(toImmutableMultiset()); } } - - /** Don't unnecessarily copy an {@link ImmutableMultiset}. */ - static final class ImmutableMultisetCopyOfImmutableMultiset { - @BeforeTemplate - ImmutableMultiset before(ImmutableMultiset multiset) { - return ImmutableMultiset.copyOf(multiset); - } - - @AfterTemplate - ImmutableMultiset after(ImmutableMultiset multiset) { - return multiset; - } - } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java index d851cbaeb8..01f4b5488f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java @@ -215,17 +215,4 @@ ImmutableSetMultimap after( return ImmutableSetMultimap.copyOf(Multimaps.transformValues(multimap, transformation)); } } - - /** Don't unnecessarily copy an {@link ImmutableSetMultimap}. */ - static final class ImmutableSetMultimapCopyOfImmutableSetMultimap { - @BeforeTemplate - ImmutableSetMultimap before(ImmutableSetMultimap multimap) { - return ImmutableSetMultimap.copyOf(multimap); - } - - @AfterTemplate - ImmutableSetMultimap after(ImmutableSetMultimap multimap) { - return multimap; - } - } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java index 077bddf428..f2391b9cd5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java @@ -126,19 +126,6 @@ ImmutableSet after(Stream stream) { } } - /** Don't unnecessarily copy an {@link ImmutableSet}. */ - static final class ImmutableSetCopyOfImmutableSet { - @BeforeTemplate - ImmutableSet before(ImmutableSet set) { - return ImmutableSet.copyOf(set); - } - - @AfterTemplate - ImmutableSet after(ImmutableSet set) { - return set; - } - } - /** Prefer {@link SetView#immutableCopy()} over the more verbose alternative. */ static final class ImmutableSetCopyOfSetView { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java index 3f93e629fd..74143680cb 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java @@ -203,19 +203,6 @@ Flux after(Mono mono) { } } - /** Don't unnecessarily invoke {@link Flux#concat(Publisher)}. */ - static final class FluxIdentity { - @BeforeTemplate - Flux before(Flux flux) { - return Flux.concat(flux); - } - - @AfterTemplate - Flux after(Flux flux) { - return flux; - } - } - /** * Prefer a collection using {@link MoreCollectors#toOptional()} over more contrived alternatives. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java index 6dfac5f109..566248f74f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java @@ -41,11 +41,9 @@ static final class FlowableToFlux { @BeforeTemplate Publisher before(Flowable 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 @@ Publisher before(Flux flux) { Flowable.fromPublisher(flux), flux.transform(Flowable::fromPublisher), flux.as(Flowable::fromPublisher), - RxJava2Adapter.fluxToFlowable(flux), flux.transform(RxJava2Adapter::fluxToFlowable)); } @@ -140,7 +137,6 @@ Publisher before(Mono mono) { Flowable.fromPublisher(mono), mono.transform(Flowable::fromPublisher), mono.as(Flowable::fromPublisher), - RxJava2Adapter.monoToFlowable(mono), mono.transform(RxJava2Adapter::monoToFlowable)); } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheckTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheckTest.java new file mode 100644 index 0000000000..f71546197c --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionCheckTest.java @@ -0,0 +1,308 @@ +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:", + " Boolean b1 = Boolean.valueOf(Boolean.FALSE);", + " // BUG: Diagnostic contains:", + " Boolean b2 = Boolean.valueOf(false);", + " // BUG: Diagnostic contains:", + " boolean b3 = Boolean.valueOf(Boolean.FALSE);", + " // BUG: Diagnostic contains:", + " boolean b4 = Boolean.valueOf(false);", + "", + " // BUG: Diagnostic contains:", + " Byte byte1 = Byte.valueOf((Byte) Byte.MIN_VALUE);", + " // BUG: Diagnostic contains:", + " Byte byte2 = Byte.valueOf(Byte.MIN_VALUE);", + " // BUG: Diagnostic contains:", + " byte byte3 = Byte.valueOf((Byte) Byte.MIN_VALUE);", + " // BUG: Diagnostic contains:", + " byte byte4 = Byte.valueOf(Byte.MIN_VALUE);", + "", + " // BUG: Diagnostic contains:", + " Character c1 = Character.valueOf((Character) 'a');", + " // BUG: Diagnostic contains:", + " Character c2 = Character.valueOf('a');", + " // BUG: Diagnostic contains:", + " char c3 = Character.valueOf((Character) 'a');", + " // BUG: Diagnostic contains:", + " char c4 = Character.valueOf('a');", + "", + " // BUG: Diagnostic contains:", + " Double d1 = Double.valueOf((Double) 0.0);", + " // BUG: Diagnostic contains:", + " Double d2 = Double.valueOf(0.0);", + " // BUG: Diagnostic contains:", + " double d3 = Double.valueOf((Double) 0.0);", + " // BUG: Diagnostic contains:", + " double d4 = Double.valueOf(0.0);", + "", + " // BUG: Diagnostic contains:", + " Float f1 = Float.valueOf((Float) 0.0F);", + " // BUG: Diagnostic contains:", + " Float f2 = Float.valueOf(0.0F);", + " // BUG: Diagnostic contains:", + " float f3 = Float.valueOf((Float) 0.0F);", + " // BUG: Diagnostic contains:", + " float f4 = Float.valueOf(0.0F);", + "", + " // BUG: Diagnostic contains:", + " Integer i1 = Integer.valueOf((Integer) 1);", + " // BUG: Diagnostic contains:", + " Integer i2 = Integer.valueOf(1);", + " // BUG: Diagnostic contains:", + " int i3 = Integer.valueOf((Integer) 1);", + " // BUG: Diagnostic contains:", + " int i4 = Integer.valueOf(1);", + "", + " // BUG: Diagnostic contains:", + " Long l1 = Long.valueOf((Long) 1L);", + " // BUG: Diagnostic contains:", + " Long l2 = Long.valueOf(1L);", + " // BUG: Diagnostic contains:", + " long l3 = Long.valueOf((Long) 1L);", + " // BUG: Diagnostic contains:", + " long l4 = Long.valueOf(1L);", + "", + " Long l5 = Long.valueOf((Integer) 1);", + " Long l6 = Long.valueOf(1);", + " // BUG: Diagnostic contains:", + " long l7 = Long.valueOf((Integer) 1);", + " // BUG: Diagnostic contains:", + " long l8 = Long.valueOf(1);", + "", + " // BUG: Diagnostic contains:", + " Short s1 = Short.valueOf((Short) Short.MIN_VALUE);", + " // BUG: Diagnostic contains:", + " Short s2 = Short.valueOf(Short.MIN_VALUE);", + " // BUG: Diagnostic contains:", + " short s3 = Short.valueOf((Short) Short.MIN_VALUE);", + " // BUG: Diagnostic contains:", + " short s4 = Short.valueOf(Short.MIN_VALUE);", + "", + " String str1 = String.valueOf(0);", + " // BUG: Diagnostic contains:", + " String str2 = String.valueOf(\"1\");", + "", + " // BUG: Diagnostic contains:", + " ImmutableBiMap o1 = ImmutableBiMap.copyOf(ImmutableBiMap.of());", + " // BUG: Diagnostic contains:", + " ImmutableList o2 = ImmutableList.copyOf(ImmutableList.of());", + " // BUG: Diagnostic contains:", + " ImmutableListMultimap o3 = ImmutableListMultimap.copyOf(ImmutableListMultimap.of());", + " // BUG: Diagnostic contains:", + " ImmutableMap o4 = ImmutableMap.copyOf(ImmutableMap.of());", + " // BUG: Diagnostic contains:", + " ImmutableMultimap o5 = ImmutableMultimap.copyOf(ImmutableMultimap.of());", + " // BUG: Diagnostic contains:", + " ImmutableMultiset o6 = ImmutableMultiset.copyOf(ImmutableMultiset.of());", + " // BUG: Diagnostic contains:", + " ImmutableRangeMap o7 = ImmutableRangeMap.copyOf(ImmutableRangeMap.of());", + " // BUG: Diagnostic contains:", + " ImmutableRangeSet o8 = ImmutableRangeSet.copyOf(ImmutableRangeSet.of());", + " // BUG: Diagnostic contains:", + " ImmutableSet o9 = ImmutableSet.copyOf(ImmutableSet.of());", + " // BUG: Diagnostic contains:", + " ImmutableSetMultimap o10 = ImmutableSetMultimap.copyOf(ImmutableSetMultimap.of());", + " // BUG: Diagnostic contains:", + " ImmutableTable o11 = ImmutableTable.copyOf(ImmutableTable.of());", + "", + " // BUG: Diagnostic contains:", + " Flux flux1 = Flux.just(1).flatMap(e -> RxJava2Adapter.fluxToFlowable(Flux.just(2)));", + " // BUG: Diagnostic contains:", + " Flux flux2 = Flux.concat(Flux.just(1));", + " // BUG: Diagnostic contains:", + " Flux flux3 = Flux.firstWithSignal(Flux.just(1));", + " // BUG: Diagnostic contains:", + " Flux flux4 = Flux.from(Flux.just(1));", + " // BUG: Diagnostic contains:", + " Flux flux5 = Flux.merge(Flux.just(1));", + "", + " // BUG: Diagnostic contains:", + " Mono m1 = Mono.from(Mono.just(1));", + " // BUG: Diagnostic contains:", + " Mono m2 = Mono.fromDirect(Mono.just(1));", + " }", + "}") + .doTest(); + } + + @Test + void replacementFirstSuggestedFix() { + refactoringTestHelper + .setFixChooser(FixChoosers.FIRST) + .addInputLines( + "Foo.java", + "import static org.mockito.Mockito.when;", + "", + "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 set1 = ImmutableSet.copyOf(ImmutableSet.of());", + " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", + "", + " ImmutableCollection list1 = ImmutableList.copyOf(ImmutableList.of(1));", + " ImmutableCollection list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));", + "", + " Collection c1 = ImmutableSet.copyOf(ImmutableSet.of(1));", + " Collection c2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));", + "", + " Flux f1 = Flux.just(1).flatMap(e -> RxJava2Adapter.fluxToFlowable(Flux.just(2)));", + " Flux f2 = Flux.concat(Flux.just(3));", + " Publisher f3 = Flux.firstWithSignal(Flux.just(4));", + " Publisher f4 = Flux.from(Flux.just(5));", + " Publisher f5 = Flux.merge(Flux.just(6));", + "", + " Mono m1 = Mono.from(Mono.just(7));", + " Publisher m2 = Mono.fromDirect(Mono.just(8));", + "", + " bar(Flux.concat(Flux.just(9)));", + " bar(Mono.from(Mono.just(10)));", + "", + " Object o1 = ImmutableSet.copyOf(ImmutableList.of());", + " Object o2 = ImmutableSet.copyOf(ImmutableSet.of());", + "", + " when(\"foo\".contains(\"f\"))", + " .thenAnswer(inv-> ImmutableSet.copyOf(ImmutableList.of(1)));", + " }", + "", + " void bar(Publisher publisher) {}", + "}") + .addOutputLines( + "Foo.java", + "import static org.mockito.Mockito.when;", + "", + "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 set1 = ImmutableSet.of();", + " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", + "", + " ImmutableCollection list1 = ImmutableList.of(1);", + " ImmutableCollection list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));", + "", + " Collection c1 = ImmutableSet.of(1);", + " Collection c2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));", + "", + " Flux f1 = Flux.just(1).flatMap(e -> Flux.just(2));", + " Flux f2 = Flux.just(3);", + " Publisher f3 = Flux.just(4);", + " Publisher f4 = Flux.just(5);", + " Publisher f5 = Flux.just(6);", + "", + " Mono m1 = Mono.just(7);", + " Publisher m2 = Mono.just(8);", + "", + " bar(Flux.just(9));", + " bar(Mono.just(10));", + "", + " Object o1 = ImmutableSet.copyOf(ImmutableList.of());", + " Object o2 = ImmutableSet.of();", + "", + " when(\"foo\".contains(\"f\"))", + " .thenAnswer(inv-> ImmutableSet.copyOf(ImmutableList.of(1)));", + " }", + "", + " void bar(Publisher 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 set1 = ImmutableSet.copyOf(ImmutableSet.of());", + " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", + "", + " ImmutableCollection list1 = ImmutableList.copyOf(ImmutableList.of(1));", + " ImmutableCollection 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 set1 = ImmutableSet.copyOf(ImmutableSet.of());", + " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", + "", + " @SuppressWarnings(\"IdentityConversion\")", + " ImmutableCollection list1 = ImmutableList.copyOf(ImmutableList.of(1));", + " ImmutableCollection list2 = ImmutableList.copyOf(new ArrayList<>(ImmutableList.of(1)));", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestInput.java index 8700b72dc6..c1ecb9e63f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestInput.java @@ -16,19 +16,13 @@ public ImmutableSet elidedTypesAndStaticImports() { ImmutableSet> testAbstractByteAssertIsEqualTo() { return ImmutableSet.of( assertThat((byte) 0).isCloseTo((byte) 1, offset((byte) 0)), - assertThat((byte) 0).isCloseTo(Byte.valueOf((byte) 1), offset((byte) 0)), - assertThat((byte) 0).isCloseTo((byte) 1, withPercentage(0)), - assertThat((byte) 0).isCloseTo(Byte.valueOf((byte) 1), withPercentage(0)), - assertThat((byte) 0).isEqualTo(Byte.valueOf((byte) 1))); + assertThat((byte) 0).isCloseTo((byte) 1, withPercentage(0))); } ImmutableSet> testAbstractByteAssertIsNotEqualTo() { return ImmutableSet.of( assertThat((byte) 0).isNotCloseTo((byte) 1, offset((byte) 0)), - assertThat((byte) 0).isNotCloseTo(Byte.valueOf((byte) 1), offset((byte) 0)), - assertThat((byte) 0).isNotCloseTo((byte) 1, withPercentage(0)), - assertThat((byte) 0).isNotCloseTo(Byte.valueOf((byte) 1), withPercentage(0)), - assertThat((byte) 0).isNotEqualTo(Byte.valueOf((byte) 1))); + assertThat((byte) 0).isNotCloseTo((byte) 1, withPercentage(0))); } AbstractByteAssert testAbstractByteAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestOutput.java index 1b15b188b0..b8d588df51 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJByteTemplatesTestOutput.java @@ -15,20 +15,12 @@ public ImmutableSet elidedTypesAndStaticImports() { ImmutableSet> testAbstractByteAssertIsEqualTo() { return ImmutableSet.of( - assertThat((byte) 0).isEqualTo((byte) 1), - assertThat((byte) 0).isEqualTo((byte) 1), - assertThat((byte) 0).isEqualTo((byte) 1), - assertThat((byte) 0).isEqualTo((byte) 1), - assertThat((byte) 0).isEqualTo((byte) 1)); + assertThat((byte) 0).isEqualTo((byte) 1), assertThat((byte) 0).isEqualTo((byte) 1)); } ImmutableSet> testAbstractByteAssertIsNotEqualTo() { return ImmutableSet.of( - assertThat((byte) 0).isNotEqualTo((byte) 1), - assertThat((byte) 0).isNotEqualTo((byte) 1), - assertThat((byte) 0).isNotEqualTo((byte) 1), - assertThat((byte) 0).isNotEqualTo((byte) 1), - assertThat((byte) 0).isNotEqualTo((byte) 1)); + assertThat((byte) 0).isNotEqualTo((byte) 1), assertThat((byte) 0).isNotEqualTo((byte) 1)); } AbstractByteAssert testAbstractByteAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestInput.java index ba53ad9efb..488c0649f2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestInput.java @@ -21,20 +21,13 @@ ImmutableSet> testAbstractDoubleAssertIsCloseToWithOffse ImmutableSet> testAbstractDoubleAssertIsEqualTo() { return ImmutableSet.of( - assertThat(0.0).isCloseTo(1, offset(0.0)), - assertThat(0.0).isCloseTo(Double.valueOf(1), offset(0.0)), - assertThat(0.0).isCloseTo(1, withPercentage(0)), - assertThat(0.0).isCloseTo(Double.valueOf(1), withPercentage(0)), - assertThat(0.0).isEqualTo(Double.valueOf(1))); + assertThat(0.0).isCloseTo(1, offset(0.0)), assertThat(0.0).isCloseTo(1, withPercentage(0))); } ImmutableSet> testAbstractDoubleAssertIsNotEqualTo() { return ImmutableSet.of( assertThat(0.0).isNotCloseTo(1, offset(0.0)), - assertThat(0.0).isNotCloseTo(Double.valueOf(1), offset(0.0)), - assertThat(0.0).isNotCloseTo(1, withPercentage(0)), - assertThat(0.0).isNotCloseTo(Double.valueOf(1), withPercentage(0)), - assertThat(0.0).isNotEqualTo(Double.valueOf(1))); + assertThat(0.0).isNotCloseTo(1, withPercentage(0))); } AbstractDoubleAssert testAbstractDoubleAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestOutput.java index 8aa85ab1c3..cb10589890 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJDoubleTemplatesTestOutput.java @@ -20,21 +20,11 @@ ImmutableSet> testAbstractDoubleAssertIsCloseToWithOffse } ImmutableSet> testAbstractDoubleAssertIsEqualTo() { - return ImmutableSet.of( - assertThat(0.0).isEqualTo(1), - assertThat(0.0).isEqualTo(1), - assertThat(0.0).isEqualTo(1), - assertThat(0.0).isEqualTo(1), - assertThat(0.0).isEqualTo(1)); + return ImmutableSet.of(assertThat(0.0).isEqualTo(1), assertThat(0.0).isEqualTo(1)); } ImmutableSet> testAbstractDoubleAssertIsNotEqualTo() { - return ImmutableSet.of( - assertThat(0.0).isNotEqualTo(1), - assertThat(0.0).isNotEqualTo(1), - assertThat(0.0).isNotEqualTo(1), - assertThat(0.0).isNotEqualTo(1), - assertThat(0.0).isNotEqualTo(1)); + return ImmutableSet.of(assertThat(0.0).isNotEqualTo(1), assertThat(0.0).isNotEqualTo(1)); } AbstractDoubleAssert testAbstractDoubleAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestInput.java index a8c90148db..946687ea21 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestInput.java @@ -21,20 +21,13 @@ ImmutableSet> testAbstractFloatAssertIsCloseToWithOffset( ImmutableSet> testAbstractFloatAssertIsEqualTo() { return ImmutableSet.of( - assertThat(0F).isCloseTo(1, offset(0F)), - assertThat(0F).isCloseTo(Float.valueOf(1), offset(0F)), - assertThat(0F).isCloseTo(1, withPercentage(0)), - assertThat(0F).isCloseTo(Float.valueOf(1), withPercentage(0)), - assertThat(0F).isEqualTo(Float.valueOf(1))); + assertThat(0F).isCloseTo(1, offset(0F)), assertThat(0F).isCloseTo(1, withPercentage(0))); } ImmutableSet> testAbstractFloatAssertIsNotEqualTo() { return ImmutableSet.of( assertThat(0F).isNotCloseTo(1, offset(0F)), - assertThat(0F).isNotCloseTo(Float.valueOf(1), offset(0F)), - assertThat(0F).isNotCloseTo(1, withPercentage(0)), - assertThat(0F).isNotCloseTo(Float.valueOf(1), withPercentage(0)), - assertThat(0F).isNotEqualTo(Float.valueOf(1))); + assertThat(0F).isNotCloseTo(1, withPercentage(0))); } AbstractFloatAssert testAbstractFloatAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestOutput.java index 16f3956cdd..9ff83b5dae 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJFloatTemplatesTestOutput.java @@ -20,21 +20,11 @@ ImmutableSet> testAbstractFloatAssertIsCloseToWithOffset( } ImmutableSet> testAbstractFloatAssertIsEqualTo() { - return ImmutableSet.of( - assertThat(0F).isEqualTo(1), - assertThat(0F).isEqualTo(1), - assertThat(0F).isEqualTo(1), - assertThat(0F).isEqualTo(1), - assertThat(0F).isEqualTo(1)); + return ImmutableSet.of(assertThat(0F).isEqualTo(1), assertThat(0F).isEqualTo(1)); } ImmutableSet> testAbstractFloatAssertIsNotEqualTo() { - return ImmutableSet.of( - assertThat(0F).isNotEqualTo(1), - assertThat(0F).isNotEqualTo(1), - assertThat(0F).isNotEqualTo(1), - assertThat(0F).isNotEqualTo(1), - assertThat(0F).isNotEqualTo(1)); + return ImmutableSet.of(assertThat(0F).isNotEqualTo(1), assertThat(0F).isNotEqualTo(1)); } AbstractFloatAssert testAbstractFloatAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestInput.java index 14826ee3af..2850166d30 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestInput.java @@ -15,20 +15,12 @@ public ImmutableSet elidedTypesAndStaticImports() { ImmutableSet> testAbstractIntegerAssertIsEqualTo() { return ImmutableSet.of( - assertThat(0).isCloseTo(1, offset(0)), - assertThat(0).isCloseTo(Integer.valueOf(1), offset(0)), - assertThat(0).isCloseTo(1, withPercentage(0)), - assertThat(0).isCloseTo(Integer.valueOf(1), withPercentage(0)), - assertThat(0).isEqualTo(Integer.valueOf(1))); + assertThat(0).isCloseTo(1, offset(0)), assertThat(0).isCloseTo(1, withPercentage(0))); } ImmutableSet> testAbstractIntegerAssertIsNotEqualTo() { return ImmutableSet.of( - assertThat(0).isNotCloseTo(1, offset(0)), - assertThat(0).isNotCloseTo(Integer.valueOf(1), offset(0)), - assertThat(0).isNotCloseTo(1, withPercentage(0)), - assertThat(0).isNotCloseTo(Integer.valueOf(1), withPercentage(0)), - assertThat(0).isNotEqualTo(Integer.valueOf(1))); + assertThat(0).isNotCloseTo(1, offset(0)), assertThat(0).isNotCloseTo(1, withPercentage(0))); } AbstractIntegerAssert testAbstractIntegerAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestOutput.java index 557e6f9a42..c937ae8cef 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJIntegerTemplatesTestOutput.java @@ -14,21 +14,11 @@ public ImmutableSet elidedTypesAndStaticImports() { } ImmutableSet> testAbstractIntegerAssertIsEqualTo() { - return ImmutableSet.of( - assertThat(0).isEqualTo(1), - assertThat(0).isEqualTo(1), - assertThat(0).isEqualTo(1), - assertThat(0).isEqualTo(1), - assertThat(0).isEqualTo(1)); + return ImmutableSet.of(assertThat(0).isEqualTo(1), assertThat(0).isEqualTo(1)); } ImmutableSet> testAbstractIntegerAssertIsNotEqualTo() { - return ImmutableSet.of( - assertThat(0).isNotEqualTo(1), - assertThat(0).isNotEqualTo(1), - assertThat(0).isNotEqualTo(1), - assertThat(0).isNotEqualTo(1), - assertThat(0).isNotEqualTo(1)); + return ImmutableSet.of(assertThat(0).isNotEqualTo(1), assertThat(0).isNotEqualTo(1)); } AbstractIntegerAssert testAbstractIntegerAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestInput.java index dcd5b23636..da40158edc 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestInput.java @@ -15,20 +15,13 @@ public ImmutableSet elidedTypesAndStaticImports() { ImmutableSet> testAbstractLongAssertIsEqualTo() { return ImmutableSet.of( - assertThat(0L).isCloseTo(1, offset(0L)), - assertThat(0L).isCloseTo(Long.valueOf(1), offset(0L)), - assertThat(0L).isCloseTo(1, withPercentage(0)), - assertThat(0L).isCloseTo(Long.valueOf(1), withPercentage(0)), - assertThat(0L).isEqualTo(Long.valueOf(1))); + assertThat(0L).isCloseTo(1, offset(0L)), assertThat(0L).isCloseTo(1, withPercentage(0))); } ImmutableSet> testAbstractLongAssertIsNotEqualTo() { return ImmutableSet.of( assertThat(0L).isNotCloseTo(1, offset(0L)), - assertThat(0L).isNotCloseTo(Long.valueOf(1), offset(0L)), - assertThat(0L).isNotCloseTo(1, withPercentage(0)), - assertThat(0L).isNotCloseTo(Long.valueOf(1), withPercentage(0)), - assertThat(0L).isNotEqualTo(Long.valueOf(1))); + assertThat(0L).isNotCloseTo(1, withPercentage(0))); } AbstractLongAssert testAbstractLongAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestOutput.java index e237425ef0..d9549d8f6d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJLongTemplatesTestOutput.java @@ -14,21 +14,11 @@ public ImmutableSet elidedTypesAndStaticImports() { } ImmutableSet> testAbstractLongAssertIsEqualTo() { - return ImmutableSet.of( - assertThat(0L).isEqualTo(1), - assertThat(0L).isEqualTo(1), - assertThat(0L).isEqualTo(1), - assertThat(0L).isEqualTo(1), - assertThat(0L).isEqualTo(1)); + return ImmutableSet.of(assertThat(0L).isEqualTo(1), assertThat(0L).isEqualTo(1)); } ImmutableSet> testAbstractLongAssertIsNotEqualTo() { - return ImmutableSet.of( - assertThat(0L).isNotEqualTo(1), - assertThat(0L).isNotEqualTo(1), - assertThat(0L).isNotEqualTo(1), - assertThat(0L).isNotEqualTo(1), - assertThat(0L).isNotEqualTo(1)); + return ImmutableSet.of(assertThat(0L).isNotEqualTo(1), assertThat(0L).isNotEqualTo(1)); } AbstractLongAssert testAbstractLongAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestInput.java index 65e5847207..b111d842e2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestInput.java @@ -16,19 +16,13 @@ public ImmutableSet elidedTypesAndStaticImports() { ImmutableSet> testAbstractShortAssertIsEqualTo() { return ImmutableSet.of( assertThat((short) 0).isCloseTo((short) 1, offset((short) 0)), - assertThat((short) 0).isCloseTo(Short.valueOf((short) 1), offset((short) 0)), - assertThat((short) 0).isCloseTo((short) 1, withPercentage(0)), - assertThat((short) 0).isCloseTo(Short.valueOf((short) 1), withPercentage(0)), - assertThat((short) 0).isEqualTo(Short.valueOf((short) 1))); + assertThat((short) 0).isCloseTo((short) 1, withPercentage(0))); } ImmutableSet> testAbstractShortAssertIsNotEqualTo() { return ImmutableSet.of( assertThat((short) 0).isNotCloseTo((short) 1, offset((short) 0)), - assertThat((short) 0).isNotCloseTo(Short.valueOf((short) 1), offset((short) 0)), - assertThat((short) 0).isNotCloseTo((short) 1, withPercentage(0)), - assertThat((short) 0).isNotCloseTo(Short.valueOf((short) 1), withPercentage(0)), - assertThat((short) 0).isNotEqualTo(Short.valueOf((short) 1))); + assertThat((short) 0).isNotCloseTo((short) 1, withPercentage(0))); } AbstractShortAssert testAbstractShortAssertIsZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestOutput.java index 138e79eb7f..db7174fd10 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJShortTemplatesTestOutput.java @@ -15,18 +15,11 @@ public ImmutableSet elidedTypesAndStaticImports() { ImmutableSet> testAbstractShortAssertIsEqualTo() { return ImmutableSet.of( - assertThat((short) 0).isEqualTo((short) 1), - assertThat((short) 0).isEqualTo((short) 1), - assertThat((short) 0).isEqualTo((short) 1), - assertThat((short) 0).isEqualTo((short) 1), - assertThat((short) 0).isEqualTo((short) 1)); + assertThat((short) 0).isEqualTo((short) 1), assertThat((short) 0).isEqualTo((short) 1)); } ImmutableSet> testAbstractShortAssertIsNotEqualTo() { return ImmutableSet.of( - assertThat((short) 0).isNotEqualTo((short) 1), - assertThat((short) 0).isNotEqualTo((short) 1), - assertThat((short) 0).isNotEqualTo((short) 1), assertThat((short) 0).isNotEqualTo((short) 1), assertThat((short) 0).isNotEqualTo((short) 1)); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java index 5c92c169fd..cc9f374094 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java @@ -113,8 +113,4 @@ ImmutableListMultimap testTransformMultimapValuesToImmutableLis flatteningToImmutableListMultimap( Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact)))); } - - ImmutableListMultimap testImmutableListMultimapCopyOfImmutableListMultimap() { - return ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java index f9ccde87e5..a1825c9070 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java @@ -89,8 +89,4 @@ ImmutableListMultimap testTransformMultimapValuesToImmutableLis ImmutableListMultimap.copyOf( Multimaps.transformValues(TreeMultimap.create(), Math::toIntExact))); } - - ImmutableListMultimap testImmutableListMultimapCopyOfImmutableListMultimap() { - return ImmutableListMultimap.of("foo", 1); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestInput.java index 24b3dccb85..d119cd9763 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestInput.java @@ -86,8 +86,4 @@ ImmutableSet> testTransformMapValuesToImmutableMap ImmutableMap.of("bar", 2L).keySet(), k -> Math.toIntExact(ImmutableMap.of("bar", 2L).get(k)))); } - - ImmutableMap testImmutableMapCopyOfImmutableMap() { - return ImmutableMap.copyOf(ImmutableMap.of("foo", 1)); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestOutput.java index dce623468a..e1638de70e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMapTemplatesTestOutput.java @@ -72,8 +72,4 @@ ImmutableSet> testTransformMapValuesToImmutableMap ImmutableMap.copyOf( Maps.transformValues(ImmutableMap.of("bar", 2L), v -> Math.toIntExact(v)))); } - - ImmutableMap testImmutableMapCopyOfImmutableMap() { - return ImmutableMap.of("foo", 1); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestInput.java index d48a3b67ad..eb08577f52 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestInput.java @@ -44,8 +44,4 @@ ImmutableSet> testStreamToImmutableMultiset() { ImmutableMultiset.copyOf(Stream.of(1).iterator()), Stream.of(2).collect(collectingAndThen(toList(), ImmutableMultiset::copyOf))); } - - ImmutableMultiset testImmutableMultisetCopyOfImmutableMultiset() { - return ImmutableMultiset.copyOf(ImmutableMultiset.of(1, 2)); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestOutput.java index 143f268caa..56da87e4be 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableMultisetTemplatesTestOutput.java @@ -41,8 +41,4 @@ ImmutableSet> testStreamToImmutableMultiset() { return ImmutableSet.of( Stream.of(1).collect(toImmutableMultiset()), Stream.of(2).collect(toImmutableMultiset())); } - - ImmutableMultiset testImmutableMultisetCopyOfImmutableMultiset() { - return ImmutableMultiset.of(1, 2); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestInput.java index 779541d5c3..270166011e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestInput.java @@ -91,8 +91,4 @@ ImmutableSetMultimap testTransformMultimapValuesToImmutableSetM flatteningToImmutableSetMultimap( Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact)))); } - - ImmutableSetMultimap testImmutableSetMultimapCopyOfImmutableSetMultimap() { - return ImmutableSetMultimap.copyOf(ImmutableSetMultimap.of("foo", 1)); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestOutput.java index a40daadd0d..bf3360c5d4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetMultimapTemplatesTestOutput.java @@ -72,8 +72,4 @@ ImmutableSetMultimap testTransformMultimapValuesToImmutableSetM ImmutableSetMultimap.copyOf( Multimaps.transformValues(TreeMultimap.create(), Math::toIntExact))); } - - ImmutableSetMultimap testImmutableSetMultimapCopyOfImmutableSetMultimap() { - return ImmutableSetMultimap.of("foo", 1); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestInput.java index d8d9c7cd2c..4fd3650179 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestInput.java @@ -59,10 +59,6 @@ ImmutableSet> testStreamToImmutableSet() { Stream.of(4).collect(collectingAndThen(toSet(), ImmutableSet::copyOf))); } - ImmutableSet testImmutableSetCopyOfImmutableSet() { - return ImmutableSet.copyOf(ImmutableSet.of(1, 2)); - } - ImmutableSet testImmutableSetCopyOfSetView() { return ImmutableSet.copyOf(Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2))); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestOutput.java index a8d8334b0e..b23aac8871 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableSetTemplatesTestOutput.java @@ -58,10 +58,6 @@ ImmutableSet> testStreamToImmutableSet() { Stream.of(4).collect(toImmutableSet())); } - ImmutableSet testImmutableSetCopyOfImmutableSet() { - return ImmutableSet.of(1, 2); - } - ImmutableSet testImmutableSetCopyOfSetView() { return Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java index add57fb20c..1b37353ff5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java @@ -63,10 +63,6 @@ Flux testMonoFlux() { return Flux.concat(Mono.just("foo")); } - Flux testFluxIdentity() { - return Flux.concat(Flux.just("foo")); - } - ImmutableSet>> testMonoCollectToOptional() { return ImmutableSet.of( Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java index 3dcff32c5f..31cb488593 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java @@ -63,10 +63,6 @@ Flux testMonoFlux() { return Mono.just("foo").flux(); } - Flux testFluxIdentity() { - return Flux.just("foo"); - } - ImmutableSet>> testMonoCollectToOptional() { return ImmutableSet.of( Mono.just("foo").flux().collect(toOptional()), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestInput.java index fcc5e889b0..55c824c20a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestInput.java @@ -25,13 +25,11 @@ ImmutableSet> testFlowableToFlux() { // 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).>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).>to(RxJava2Adapter::flowableToFlux))); } ImmutableSet> testFluxToFlowable() { @@ -39,8 +37,7 @@ ImmutableSet> testFluxToFlowable() { 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> testFluxToObservable() { @@ -68,8 +65,7 @@ ImmutableSet> testMonoToFlowable() { 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 testMonoToMaybe() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestOutput.java index 49fec4d182..8c38f368b4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/RxJava2AdapterTemplatesTestOutput.java @@ -29,9 +29,7 @@ ImmutableSet> testFlowableToFlux() { 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> testFluxToFlowable() { @@ -39,8 +37,7 @@ ImmutableSet> testFluxToFlowable() { 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> testFluxToObservable() { @@ -68,8 +65,7 @@ ImmutableSet> testMonoToFlowable() { 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 testMonoToMaybe() {