From cacc84b1fb35deff76971a7e69055e9a367f060a Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 4 Apr 2023 10:02:09 +0200 Subject: [PATCH] Suggestions --- .../errorprone/refasterrules/SuggestedFixRules.java | 13 +++++++++++++ .../refasterrules/SuggestedFixRulesTestInput.java | 4 ++++ .../refasterrules/SuggestedFixRulesTestOutput.java | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/SuggestedFixRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/SuggestedFixRules.java index f4f5d085523..3ce33426148 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/SuggestedFixRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/SuggestedFixRules.java @@ -90,4 +90,17 @@ SuggestedFix after(Tree tree, String postfix) { return SuggestedFix.postfixWith(tree, postfix); } } + + /** Prefer {@link SuggestedFix#delete(Tree)} over more contrived alternatives. */ + static final class SuggestedFixDelete { + @BeforeTemplate + SuggestedFix before(Tree tree) { + return SuggestedFix.builder().delete(tree).build(); + } + + @AfterTemplate + SuggestedFix after(Tree tree) { + return SuggestedFix.delete(tree); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestInput.java index 06fbfbf2625..9cda7968092 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestInput.java @@ -28,4 +28,8 @@ SuggestedFix testSuggestedFixPrefixWith() { SuggestedFix testSuggestedFixPostfixWith() { return SuggestedFix.builder().postfixWith(null, "foo").build(); } + + SuggestedFix testSuggestedFixDelete() { + return SuggestedFix.builder().delete((Tree) null).build(); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestOutput.java index 8f43ce1d81c..32cadb3b9ab 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestOutput.java @@ -1,5 +1,6 @@ package tech.picnic.errorprone.refasterrules; +import com.google.errorprone.fixes.SuggestedFix; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.Tree; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; @@ -28,4 +29,8 @@ SuggestedFix testSuggestedFixPrefixWith() { SuggestedFix testSuggestedFixPostfixWith() { return Suggestions.postfixWith(null, "foo"); } + + SuggestedFix testSuggestedFixDelete() { + return SuggestedFix.delete((Tree) null); + } }