From f3aa90485fcb173efd2392444cbf24f14fdd79f3 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 11 Oct 2022 16:42:01 +0200 Subject: [PATCH] Make last files consistent with `refaster rules` --- .../errorprone/refaster/runner/Refaster.java | 2 +- .../refaster/runner/CodeTransformersTest.java | 10 +++---- .../errorprone/refaster/runner/FooRules.java | 30 +++++++++---------- .../refaster/runner/RefasterTest.java | 30 +++++++++---------- .../AnnotatedCompositeCodeTransformer.java | 2 +- .../refaster/annotation/Description.java | 4 +-- .../refaster/annotation/Severity.java | 4 +-- .../refaster/annotation/package-info.java | 4 +-- .../refaster/test/RefasterRuleCollection.java | 8 ++--- .../test/MatchInWrongMethodRules.java | 4 +-- 10 files changed, 48 insertions(+), 50 deletions(-) diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java index 75f41ee375e..ef3b70161f1 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java @@ -154,7 +154,7 @@ private static Optional toSeverityLevel(Severity severity) { *

The assigned severity is overridden only if this bug checker's severity was explicitly * configured. * - *

The original check name (i.e. the Refaster template name) is prepended to the {@link + *

The original check name (i.e. the Refaster rule name) is prepended to the {@link * Description}'s message. The replacement check name ("Refaster Rule", a name which includes a * space) is chosen such that it is guaranteed not to match any canonical bug checker name (as * that could cause {@link VisitorState#reportMatch(Description)}} to override the reported diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java index ba3898fdab5..66b3a082dd4 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java @@ -13,10 +13,10 @@ final class CodeTransformersTest { void getAllCodeTransformers() { assertThat(CodeTransformers.getAllCodeTransformers().keySet()) .containsExactlyInAnyOrder( - "FooTemplates$StringOfSizeZeroTemplate", - "FooTemplates$StringOfSizeZeroVerboseTemplate", - "FooTemplates$StringOfSizeOneTemplate", - "FooTemplates$ExtraGrouping$StringOfSizeTwoTemplate", - "FooTemplates$ExtraGrouping$StringOfSizeThreeTemplate"); + "FooRules$StringOfSizeZeroRule", + "FooRules$StringOfSizeZeroVerboseRule", + "FooRules$StringOfSizeOneRule", + "FooRules$ExtraGrouping$StringOfSizeTwoRule", + "FooRules$ExtraGrouping$StringOfSizeThreeRule"); } } diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java index a8921417704..df20e66eb75 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java @@ -10,12 +10,12 @@ import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; import tech.picnic.errorprone.refaster.annotation.Severity; -/** An example template collection used to test {@link CodeTransformers} and {@link Refaster}. */ +/** An example rule collection used to test {@link CodeTransformers} and {@link Refaster}. */ final class FooRules { private FooRules() {} - /** A simple template for testing purposes, lacking any custom annotations. */ - static final class StringOfSizeZeroTemplate { + /** A simple rule for testing purposes, lacking any custom annotations. */ + static final class StringOfSizeZeroRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 0; @@ -28,10 +28,10 @@ boolean after(String string) { } /** - * A simple template for testing purposes, matching the same set of expressions as {@link - * StringOfSizeZeroTemplate}, but producing a larger replacement string. + * A simple rule for testing purposes, matching the same set of expressions as {@link + * StringOfSizeZeroRule}, but producing a larger replacement string. */ - static final class StringOfSizeZeroVerboseTemplate { + static final class StringOfSizeZeroVerboseRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 0; @@ -43,11 +43,11 @@ boolean after(String string) { } } - /** A simple template for testing purposes, having several custom annotations. */ + /** A simple rule for testing purposes, having several custom annotations. */ @Description("A custom description about matching single-char strings") @OnlineDocumentation @Severity(WARNING) - static final class StringOfSizeOneTemplate { + static final class StringOfSizeOneRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 1; @@ -59,17 +59,15 @@ boolean after(String string) { } } - /** - * A nested class with annotations that are inherited by the Refaster templates contained in it. - */ + /** A nested class with annotations that are inherited by the Refaster rules contained in it. */ @Description("A custom subgroup description") - @OnlineDocumentation("https://example.com/template/${topLevelClassName}#${nestedClassName}") + @OnlineDocumentation("https://example.com/rule/${topLevelClassName}#${nestedClassName}") @Severity(ERROR) static final class ExtraGrouping { private ExtraGrouping() {} - /** A simple template for testing purposes, inheriting custom annotations. */ - static final class StringOfSizeTwoTemplate { + /** A simple rule for testing purposes, inheriting custom annotations. */ + static final class StringOfSizeTwoRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 2; @@ -81,11 +79,11 @@ boolean after(String string) { } } - /** A simple template for testing purposes, overriding custom annotations. */ + /** A simple rule for testing purposes, overriding custom annotations. */ @Description("A custom description about matching three-char strings") @OnlineDocumentation("https://example.com/custom") @Severity(SUGGESTION) - static final class StringOfSizeThreeTemplate { + static final class StringOfSizeThreeRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 3; diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java index 2c84a4f9545..8ec4e5122ce 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java @@ -29,25 +29,25 @@ final class RefasterTest { CompilationTestHelper.newInstance(Refaster.class, getClass()) .matchAllDiagnostics() .expectErrorMessage( - "StringOfSizeZeroTemplate", + "StringOfSizeZeroRule", containsPattern( - "\\[Refaster Rule\\] FooTemplates\\.StringOfSizeZeroTemplate: Refactoring opportunity\\s+.+\\s+")) + "\\[Refaster Rule\\] FooRules\\.StringOfSizeZeroRule: Refactoring opportunity\\s+.+\\s+")) .expectErrorMessage( - "StringOfSizeOneTemplate", + "StringOfSizeOneRule", containsPattern( - "\\[Refaster Rule\\] FooTemplates\\.StringOfSizeOneTemplate: " + "\\[Refaster Rule\\] FooRules\\.StringOfSizeOneRule: " + "A custom description about matching single-char strings\\s+.+\\s+" - + "\\(see https://error-prone.picnic.tech/refasterrules/FooTemplates#StringOfSizeOneTemplate\\)")) + + "\\(see https://error-prone.picnic.tech/refasterrules/FooRules#StringOfSizeOneRule\\)")) .expectErrorMessage( - "StringOfSizeTwoTemplate", + "StringOfSizeTwoRule", containsPattern( - "\\[Refaster Rule\\] FooTemplates\\.ExtraGrouping\\.StringOfSizeTwoTemplate: " + "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeTwoRule: " + "A custom subgroup description\\s+.+\\s+" - + "\\(see https://example.com/template/FooTemplates#ExtraGrouping.StringOfSizeTwoTemplate\\)")) + + "\\(see https://example.com/rule/FooRules#ExtraGrouping.StringOfSizeTwoRule\\)")) .expectErrorMessage( - "StringOfSizeThreeTemplate", + "StringOfSizeThreeRule", containsPattern( - "\\[Refaster Rule\\] FooTemplates\\.ExtraGrouping\\.StringOfSizeThreeTemplate: " + "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeThreeRule: " + "A custom description about matching three-char strings\\s+.+\\s+" + "\\(see https://example.com/custom\\)")); private final BugCheckerRefactoringTestHelper refactoringTestHelper = @@ -55,7 +55,7 @@ final class RefasterTest { private final BugCheckerRefactoringTestHelper restrictedRefactoringTestHelper = BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()) .setArgs( - "-XepOpt:Refaster:NamePattern=.*\\$(StringOfSizeZeroVerboseTemplate|StringOfSizeTwoTemplate)$"); + "-XepOpt:Refaster:NamePattern=.*\\$(StringOfSizeZeroVerboseRule|StringOfSizeTwoRule)$"); @Test void identification() { @@ -64,13 +64,13 @@ void identification() { "A.java", "class A {", " void m() {", - " // BUG: Diagnostic matches: StringOfSizeZeroTemplate", + " // BUG: Diagnostic matches: StringOfSizeZeroRule", " boolean b1 = \"foo\".toCharArray().length == 0;", - " // BUG: Diagnostic matches: StringOfSizeOneTemplate", + " // BUG: Diagnostic matches: StringOfSizeOneRule", " boolean b2 = \"bar\".toCharArray().length == 1;", - " // BUG: Diagnostic matches: StringOfSizeTwoTemplate", + " // BUG: Diagnostic matches: StringOfSizeTwoRule", " boolean b3 = \"baz\".toCharArray().length == 2;", - " // BUG: Diagnostic matches: StringOfSizeThreeTemplate", + " // BUG: Diagnostic matches: StringOfSizeThreeRule", " boolean b4 = \"qux\".toCharArray().length == 3;", " }", "}") diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java index 1d2871f9b32..e43f0ea4c55 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java @@ -96,7 +96,7 @@ private String getShortCheckName(String fullCheckName) { String prefix = packageName() + '.'; checkState( fullCheckName.startsWith(prefix), - "Refaster template class '%s' is not located in package '%s'", + "Refaster rule class '%s' is not located in package '%s'", fullCheckName, packageName()); diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java index bb2ecc1b9f6..84af8a57274 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java @@ -6,7 +6,7 @@ import java.lang.annotation.Target; /** - * Describes the intent of a Refaster template or group of Refaster templates. + * Describes the intent of a Refaster rule or group of Refaster rules. * *

Annotations on nested classes override the description associated with any enclosing class. */ @@ -14,7 +14,7 @@ @Retention(RetentionPolicy.SOURCE) public @interface Description { /** - * A description of the annotated Refaster template(s). + * A description of the annotated Refaster rule(s). * * @return A non-{@code null} string. */ diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java index bb493fda042..afa5a6c6e13 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java @@ -7,7 +7,7 @@ import java.lang.annotation.Target; /** - * Describes the severity of a Refaster template or group of Refaster templates. + * Describes the severity of a Refaster rule or group of Refaster rules. * *

The default severity is the severity assigned to the {@code Refaster} bug checker, which may * be controlled explicitly by running Error Prone with e.g. {@code -Xep:Refaster:WARN}. Annotations @@ -17,7 +17,7 @@ @Retention(RetentionPolicy.SOURCE) public @interface Severity { /** - * The expected severity of any match of the annotated Refaster template(s). + * The expected severity of any match of the annotated Refaster rule(s). * * @return An Error Prone severity level. */ diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java index 7178ba1cb92..53e8e88739b 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java @@ -1,6 +1,6 @@ /** - * A collection of annotations that can be placed on Refaster template classes and Refaster template - * collection classes, thus influencing the way in which associated template matches are reported in + * A collection of annotations that can be placed on Refaster rule classes and Refaster rule + * collection classes, thus influencing the way in which associated rule matches are reported in * non-patch mode. */ @com.google.errorprone.annotations.CheckReturnValue diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index 7f380a60e45..daf2d525135 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -175,11 +175,11 @@ private static ImmutableRangeMap indexRuleMatches( ImmutableRangeMap.Builder ruleMatches = ImmutableRangeMap.builder(); for (Description description : matches) { - String templateName = extractRefasterTemplateName(description); + String ruleName = extractRefasterRuleName(description); Set replacements = Iterables.getOnlyElement(description.fixes).getReplacements(endPositions); for (Replacement replacement : replacements) { - ruleMatches.put(replacement.range(), templateName); + ruleMatches.put(replacement.range(), ruleName); } } @@ -226,10 +226,10 @@ private void reportViolations( state.reportMatch(describeMatch(tree, fixWithComment)); } - private static String extractRefasterTemplateName(Description description) { + private static String extractRefasterRuleName(Description description) { String message = description.getRawMessage(); int index = message.indexOf(':'); - checkState(index >= 0, "Failed to extract Refaster template name from string '%s'", message); + checkState(index >= 0, "Failed to extract Refaster rule name from string '%s'", message); return getSubstringAfterFinalDelimiter('.', message.substring(0, index)); } diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodRules.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodRules.java index ee47a66737c..b8fccf5cdf9 100644 --- a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodRules.java +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodRules.java @@ -6,8 +6,8 @@ /** Refaster rule collection to validate reporting of a match occurring in an unexpected place. */ @OnlineDocumentation -final class MatchInWrongMethodTemplates { - private MatchInWrongMethodTemplates() {} +final class MatchInWrongMethodRules { + private MatchInWrongMethodRules() {} static final class StringIsEmpty { @BeforeTemplate