Skip to content

Commit

Permalink
Consistently prefer "Refaster rule" over "Refaster template" (#286)
Browse files Browse the repository at this point in the history
As the former term references a class containing one or more `@BeforeTemplate`
methods, one or more `@Placeholder` methods and an optional `@AfterTemplate`, 
while the latter term more narrowly references a single `@BeforeTemplate` or 
`@AfterTemplate` method.
  • Loading branch information
rickie authored Oct 11, 2022
1 parent 7aef2cf commit 128e178
Show file tree
Hide file tree
Showing 213 changed files with 957 additions and 967 deletions.
2 changes: 1 addition & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ changelog:
labels:
- "ignore-changelog"
categories:
- title: ":rocket: New Error Prone checks and Refaster templates"
- title: ":rocket: New Error Prone checks and Refaster rules"
labels:
- "new feature"
- title: ":sparkles: Improvements"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ it:
<artifactId>error-prone-contrib</artifactId>
<version>${error-prone-support.version}</version>
</path>
<!-- Error Prone Support's Refaster templates. -->
<!-- Error Prone Support's Refaster rules. -->
<path>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>refaster-runner</artifactId>
Expand Down Expand Up @@ -122,7 +122,7 @@ $ mvn clean install
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] Example.java:[9,34] [tech.picnic.errorprone.refastertemplates.BigDecimalTemplates.BigDecimalZero]
[WARNING] Example.java:[9,34] [tech.picnic.errorprone.refasterrules.BigDecimalRules.BigDecimalZero]
Did you mean 'return BigDecimal.ZERO;'?
[WARNING] Example.java:[13,35] [IdentityConversion] This method invocation appears redundant; remove it or suppress this warning and add a comment explaining its purpose
(see https://error-prone.picnic.tech/bugpatterns/IdentityConversion)
Expand All @@ -136,12 +136,12 @@ Two things are kicking in here:

1. An Error Prone [`BugChecker`][error-prone-bugchecker] that flags unnecessary
[identity conversions][bug-checks-identity-conversion].
2. A [Refaster][refaster] template capable of
[rewriting][refaster-templates-bigdecimal] expressions of the form
2. A [Refaster][refaster] rule capable of
[rewriting][refaster-rules-bigdecimal] expressions of the form
`BigDecimal.valueOf(0)` and `new BigDecimal(0)` to `BigDecimal.ZERO`.

Be sure to check out all [bug checks][bug-checks] and [refaster
templates][refaster-templates].
rules][refaster-rules].

## 👷 Developing Error Prone Support

Expand Down Expand Up @@ -227,5 +227,5 @@ guidelines][contributing].
[pitest-maven]: https://pitest.org/quickstart/maven
[pr-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[refaster]: https://errorprone.info/docs/refaster
[refaster-templates-bigdecimal]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/BigDecimalTemplates.java
[refaster-templates]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/
[refaster-rules-bigdecimal]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java
[refaster-rules]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/
2 changes: 1 addition & 1 deletion error-prone-contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Refaster's expressiveness:
motivating example, see the two subtly different loop definitions in
`CollectionRemoveAllFromCollectionExpression`.
- Figure out why Refaster sometimes doesn't match the correct generic overload.
See the `AssertThatIterableHasOneComparableElementEqualTo` template for an
See the `AssertThatIterableHasOneComparableElementEqualTo` rule for an
example.

[autorefactor]: https://autorefactor.org
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* A {@link BugChecker} that flags AssertJ {@code isEqualTo(null)} checks for simplification.
*
* <p>This bug checker cannot be replaced with a simple Refaster template, as the Refaster approach
* <p>This bug checker cannot be replaced with a simple Refaster rule, as the Refaster approach
* would require that all overloads of {@link org.assertj.core.api.Assert#isEqualTo(Object)} (such
* as {@link org.assertj.core.api.AbstractStringAssert#isEqualTo(String)}) are explicitly
* enumerated. This bug checker generically matches all such current and future overloads.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/** A {@link BugChecker} that flags likely missing Refaster annotations. */
@AutoService(BugChecker.class)
@BugPattern(
summary = "The Refaster template contains a method without any Refaster annotations",
summary = "The Refaster rule contains a method without any Refaster annotations",
link = BUG_PATTERNS_BASE_URL + "MissingRefasterAnnotation",
linkType = CUSTOM,
severity = WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
/**
* A {@link BugChecker} that flags unnecessary {@link Refaster#anyOf(Object[])} usages.
*
* <p>Note that this logic can't be implemented as a Refaster template, as the {@link Refaster}
* class is treated specially.
* <p>Note that this logic can't be implemented as a Refaster rule, as the {@link Refaster} class is
* treated specially.
*/
@AutoService(BugChecker.class)
@BugPattern(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
@AutoService(BugChecker.class)
@BugPattern(
summary = "Refaster class and method definitions should specify a canonical set of modifiers",
link = BUG_PATTERNS_BASE_URL + "RefasterTemplateModifiers",
link = BUG_PATTERNS_BASE_URL + "RefasterRuleModifiers",
linkType = CUSTOM,
severity = SUGGESTION,
tags = STYLE)
public final class RefasterTemplateModifiers extends BugChecker
public final class RefasterRuleModifiers extends BugChecker
implements ClassTreeMatcher, MethodTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<Tree> BEFORE_TEMPLATE_METHOD = hasAnnotation(BeforeTemplate.class);
Expand Down Expand Up @@ -85,8 +85,8 @@ private static SuggestedFix suggestCanonicalModifiers(ClassTree tree, VisitorSta

if (!hasMatchingMember(tree, PLACEHOLDER_METHOD, state)) {
/*
* Templates without a `@Placeholder` method should be `final`. Note that Refaster enforces
* that `@Placeholder` methods are `abstract`, so templates _with_ such a method will
* Rules without a `@Placeholder` method should be `final`. Note that Refaster enforces
* that `@Placeholder` methods are `abstract`, so rules _with_ such a method will
* naturally be `abstract` and non-`final`.
*/
modifiersToAdd.add(Modifier.FINAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -11,17 +11,17 @@
import org.assertj.core.api.BigDecimalAssert;

/**
* Refaster templates related to AssertJ assertions over {@link BigDecimal}s.
* Refaster rules related to AssertJ assertions over {@link BigDecimal}s.
*
* <p>Note that, contrary to collections of Refaster templates for other {@link
* org.assertj.core.api.NumberAssert} subtypes, these templates do not rewrite to/from {@link
* <p>Note that, contrary to collections of Refaster rules for other {@link
* org.assertj.core.api.NumberAssert} subtypes, these rules do not rewrite to/from {@link
* BigDecimalAssert#isEqualTo(Object)} and {@link BigDecimalAssert#isNotEqualTo(Object)}. This is
* because {@link BigDecimal#equals(Object)} considers not only the numeric value of compared
* instances, but also their scale. As a result various seemingly straightforward transformations
* would actually subtly change the assertion's semantics.
*/
final class AssertJBigDecimalTemplates {
private AssertJBigDecimalTemplates() {}
final class AssertJBigDecimalRules {
private AssertJBigDecimalRules() {}

static final class AbstractBigDecimalAssertIsEqualByComparingTo {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -11,8 +11,8 @@

// XXX: If we add a rule that drops unnecessary `L` suffixes from literal longs, then the `0L`/`1L`
// cases below can go.
final class AssertJBigIntegerTemplates {
private AssertJBigIntegerTemplates() {}
final class AssertJBigIntegerRules {
private AssertJBigIntegerRules() {}

static final class AbstractBigIntegerAssertIsEqualTo {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -9,8 +9,8 @@
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import org.assertj.core.api.AbstractBooleanAssert;

final class AssertJBooleanTemplates {
private AssertJBooleanTemplates() {}
final class AssertJBooleanRules {
private AssertJBooleanRules() {}

static final class AbstractBooleanAssertIsEqualTo {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -8,8 +8,8 @@
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import org.assertj.core.api.AbstractByteAssert;

final class AssertJByteTemplates {
private AssertJByteTemplates() {}
final class AssertJByteRules {
private AssertJByteRules() {}

static final class AbstractByteAssertIsEqualTo {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -9,8 +9,8 @@
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import org.assertj.core.api.AbstractAssert;

final class AssertJCharSequenceTemplates {
private AssertJCharSequenceTemplates() {}
final class AssertJCharSequenceRules {
private AssertJCharSequenceRules() {}

static final class AssertThatCharSequenceIsEmpty {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -9,8 +9,8 @@
import org.assertj.core.api.AbstractComparableAssert;
import org.assertj.core.api.AbstractIntegerAssert;

final class AssertJComparableTemplates {
private AssertJComparableTemplates() {}
final class AssertJComparableRules {
private AssertJComparableRules() {}

static final class AssertThatIsEqualByComparingTo<T extends Comparable<? super T>> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -9,8 +9,8 @@
import org.assertj.core.api.AbstractDoubleAssert;
import org.assertj.core.data.Offset;

final class AssertJDoubleTemplates {
private AssertJDoubleTemplates() {}
final class AssertJDoubleRules {
private AssertJDoubleRules() {}

static final class AbstractDoubleAssertIsCloseToWithOffset {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import com.google.common.collect.Iterables;
import com.google.errorprone.refaster.Refaster;
Expand All @@ -7,8 +7,8 @@
import java.util.Collection;
import org.assertj.core.api.EnumerableAssert;

final class AssertJEnumerableTemplates {
private AssertJEnumerableTemplates() {}
final class AssertJEnumerableRules {
private AssertJEnumerableRules() {}

static final class EnumerableAssertIsEmpty<E> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -9,8 +9,8 @@
import org.assertj.core.api.AbstractFloatAssert;
import org.assertj.core.data.Offset;

final class AssertJFloatTemplates {
private AssertJFloatTemplates() {}
final class AssertJFloatRules {
private AssertJFloatRules() {}

static final class AbstractFloatAssertIsCloseToWithOffset {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -8,8 +8,8 @@
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import org.assertj.core.api.AbstractIntegerAssert;

final class AssertJIntegerTemplates {
private AssertJIntegerTemplates() {}
final class AssertJIntegerRules {
private AssertJIntegerRules() {}

static final class AbstractIntegerAssertIsEqualTo {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;
Expand All @@ -8,8 +8,8 @@
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import org.assertj.core.api.AbstractLongAssert;

final class AssertJLongTemplates {
private AssertJLongTemplates() {}
final class AssertJLongRules {
private AssertJLongRules() {}

static final class AbstractLongAssertIsEqualTo {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import com.google.common.collect.ImmutableMap;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import java.util.Map;
import org.assertj.core.api.AbstractMapAssert;

final class AssertJMapTemplates {
private AssertJMapTemplates() {}
final class AssertJMapRules {
private AssertJMapRules() {}

static final class AbstractMapAssertContainsExactlyInAnyOrderEntriesOf<K, V> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -21,8 +21,8 @@
import org.assertj.core.api.NumberAssert;
import tech.picnic.errorprone.refaster.matchers.IsCharacter;

final class AssertJNumberTemplates {
private AssertJNumberTemplates() {}
final class AssertJNumberRules {
private AssertJNumberRules() {}

static final class NumberAssertIsPositive {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -11,8 +11,8 @@
import org.assertj.core.api.AbstractStringAssert;
import org.assertj.core.api.ObjectAssert;

final class AssertJObjectTemplates {
private AssertJObjectTemplates() {}
final class AssertJObjectRules {
private AssertJObjectRules() {}

static final class AssertThatIsInstanceOf<S, T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -15,8 +15,8 @@
import org.assertj.core.api.ObjectAssert;
import org.assertj.core.api.OptionalAssert;

final class AssertJOptionalTemplates {
private AssertJOptionalTemplates() {}
final class AssertJOptionalRules {
private AssertJOptionalRules() {}

static final class AssertThatOptional<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.picnic.errorprone.refastertemplates;
package tech.picnic.errorprone.refasterrules;

import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,8 +10,8 @@
import org.assertj.core.api.AbstractBooleanAssert;
import org.assertj.core.api.AbstractDoubleAssert;

final class AssertJPrimitiveTemplates {
private AssertJPrimitiveTemplates() {}
final class AssertJPrimitiveRules {
private AssertJPrimitiveRules() {}

static final class AssertThatIsEqualTo {
@BeforeTemplate
Expand Down
Loading

0 comments on commit 128e178

Please sign in to comment.