From 8316c1afa7ef0697fe4f5f620bf65b4b8b5ebcdf Mon Sep 17 00:00:00 2001 From: Ferdinand Swoboda Date: Tue, 14 Jun 2022 20:34:14 +0200 Subject: [PATCH] CORE-97 Revert redundant replacement tests --- ...MissingImmutableSortedSetDefaultCheck.java | 14 +- ...ingImmutableSortedSetDefaultCheckTest.java | 281 +----------------- 2 files changed, 5 insertions(+), 290 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheck.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheck.java index 243632226ed..cc547f06755 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheck.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheck.java @@ -18,7 +18,6 @@ import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; import org.immutables.value.Value.Immutable; @@ -63,16 +62,11 @@ public Description matchMethod(MethodTree tree, VisitorState state) { // The ImmutableSortedSet has no empty default -> add the `@Value.NaturalOrder` annotation or // provide a default implementation. return buildDescription(tree) + .setMessage( + "Methods returning an `ImmutableSortedSet` within an @Value.Immutable or @Value.Modifiable class " + + "should include additional deserialization information for absent sets. " + + "Alternatively, specify a default implementation.") .addFix(SuggestedFix.builder().prefixWith(tree, "@Value.NaturalOrder ").build()) - .addFix( - SuggestedFix.builder() - .replace( - ASTHelpers.getStartPosition(tree), ASTHelpers.getStartPosition(tree) + 8, "") - .replace( - state.getEndPosition(tree) - 1, - state.getEndPosition(tree), - "{ return ImmutableSortedSet.of(); }") - .build()) .build(); } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheckTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheckTest.java index dec6a045b82..2a146f1b12a 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheckTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingImmutableSortedSetDefaultCheckTest.java @@ -1,7 +1,5 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers.SECOND; - import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; @@ -98,7 +96,7 @@ void identification() { } @Test - void replacementInImmutableInterface() { + void replacement() { refactoringTestHelper .addInputLines( "A.java", @@ -108,15 +106,6 @@ void replacementInImmutableInterface() { "@Value.Immutable", "interface A {", " ImmutableSortedSet sortedSet();", - " default ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " default ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " ImmutableSortedSet defaultSortedSet3();", "}") .addOutputLines( "A.java", @@ -127,274 +116,6 @@ void replacementInImmutableInterface() { "interface A {", " @Value.NaturalOrder", " ImmutableSortedSet sortedSet();", - " default ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " default ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " ImmutableSortedSet defaultSortedSet3();", - "}") - .doTest(TestMode.TEXT_MATCH); - } - - @Test - void replacementInModifiableInterface() { - refactoringTestHelper - .addInputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Modifiable", - "interface B {", - " ImmutableSortedSet sortedSet();", - " default ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " default ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " ImmutableSortedSet defaultSortedSet3();", - "}") - .addOutputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Modifiable", - "interface B {", - " @Value.NaturalOrder", - " ImmutableSortedSet sortedSet();", - " default ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " default ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " ImmutableSortedSet defaultSortedSet3();", - "}") - .doTest(TestMode.TEXT_MATCH); - } - - @Test - void replacementInImmutableAbstractClass() { - refactoringTestHelper - .addInputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Immutable", - "abstract class C {", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .addOutputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Immutable", - "abstract class C {", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .doTest(TestMode.TEXT_MATCH); - } - - @Test - void replacementInModifiableAbstractClass() { - refactoringTestHelper - .addInputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Modifiable", - "abstract class D {", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .addOutputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Modifiable", - "abstract class D {", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .doTest(TestMode.TEXT_MATCH); - } - - @Test - void secondaryReplacementInModifiableInterface() { - refactoringTestHelper - .setFixChooser(SECOND) - .addInputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Modifiable", - "interface B {", - " ImmutableSortedSet sortedSet();", - " default ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " default ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " ImmutableSortedSet defaultSortedSet3();", - "}") - .addOutputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Modifiable", - "interface B {", - " default ImmutableSortedSet sortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " default ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " default ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " ImmutableSortedSet defaultSortedSet3();", - "}") - .doTest(TestMode.TEXT_MATCH); - } - - @Test - void secondaryReplacementInImmutableAbstractClass() { - refactoringTestHelper - .setFixChooser(SECOND) - .addInputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Immutable", - "abstract class C {", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .addOutputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "@Value.Immutable", - "abstract class C {", - " ImmutableSortedSet sortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .doTest(TestMode.TEXT_MATCH); - } - - @Test - void noReplacementInNormalClass() { - refactoringTestHelper - .addInputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "abstract class E {", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", - "}") - .addOutputLines( - "A.java", - "import org.immutables.value.Value;", - "import com.google.common.collect.ImmutableSortedSet;", - "", - "abstract class E {", - " abstract ImmutableSortedSet sortedSet();", - " ImmutableSortedSet defaultSortedSet() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.Default", - " ImmutableSortedSet defaultSortedSet2() {", - " return ImmutableSortedSet.of();", - " }", - " @Value.NaturalOrder", - " abstract ImmutableSortedSet defaultSortedSet3();", "}") .doTest(TestMode.TEXT_MATCH); }