Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Mar 12, 2023
1 parent 7eb1eaa commit 74a3a4d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
1 change: 1 addition & 0 deletions error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<dependency>
<groupId>${groupId.error-prone}</groupId>
<artifactId>error_prone_test_helpers</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,51 @@
import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChooser;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;
import com.google.errorprone.refaster.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;

/** Refaster rules related to BugChecker classes. */
/** Refaster rules related to {@link com.google.errorprone.bugpatterns.BugChecker} classes. */
@OnlineDocumentation
final class BugCheckerRules {
private BugCheckerRules() {}

/**
* Drop {@link BugCheckerRefactoringTestHelper#setFixChooser(FixChooser)} when set to the default
* {@link FixChoosers#FIRST}.
* Avoid calling {@link BugCheckerRefactoringTestHelper#setFixChooser(FixChooser)} with the
* default value of {@link FixChoosers#FIRST}.
*/
static final class SetFixChooserDefault {
static final class BugCheckerRefactoringTestHelperIdentity {
@BeforeTemplate
BugCheckerRefactoringTestHelper before(BugCheckerRefactoringTestHelper helper) {
return helper.setFixChooser(FixChoosers.FIRST);
return Refaster.anyOf(
helper.setFixChooser(FixChoosers.FIRST), helper.setImportOrder("static-first"));
}

@AfterTemplate
BugCheckerRefactoringTestHelper after(BugCheckerRefactoringTestHelper helper) {
return helper;
}
}

/**
* Prefer {@link BugCheckerRefactoringTestHelper.ExpectOutput#expectUnchanged()} over repeating
* the input.
*/
// XXX: This rule assumes that the full source code is specified as a single string, e.g. using a
// text block. Support for multi-line source code input would require a `BugChecker`
// implementation instead.
static final class BugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged {
@BeforeTemplate
BugCheckerRefactoringTestHelper before(
BugCheckerRefactoringTestHelper helper, String path, String source) {
return helper.addInputLines(path, source).addOutputLines(path, source);
}

@AfterTemplate
BugCheckerRefactoringTestHelper after(
BugCheckerRefactoringTestHelper helper, String path, String source) {
return helper.addInputLines(path, source).expectUnchanged();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;
import tech.picnic.errorprone.bugpatterns.StringCaseLocaleUsage;
import com.google.errorprone.bugpatterns.BugChecker;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;

final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase {
Expand All @@ -12,8 +12,18 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(FixChoosers.class);
}

BugCheckerRefactoringTestHelper testSetFixChooserDefault() {
return BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass())
.setFixChooser(FixChoosers.FIRST);
ImmutableSet<BugCheckerRefactoringTestHelper> testBugCheckerRefactoringTestHelperIdentity() {
return ImmutableSet.of(
BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())
.setFixChooser(FixChoosers.FIRST),
BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())
.setImportOrder("static-first"));
}

BugCheckerRefactoringTestHelper
testBugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged() {
return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())
.addInputLines("A.java", "class A {}")
.addOutputLines("A.java", "class A {}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;
import tech.picnic.errorprone.bugpatterns.StringCaseLocaleUsage;
import com.google.errorprone.bugpatterns.BugChecker;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;

final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase {
Expand All @@ -12,7 +12,16 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(FixChoosers.class);
}

BugCheckerRefactoringTestHelper testSetFixChooserDefault() {
return BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass());
ImmutableSet<BugCheckerRefactoringTestHelper> testBugCheckerRefactoringTestHelperIdentity() {
return ImmutableSet.of(
BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()),
BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()));
}

BugCheckerRefactoringTestHelper
testBugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged() {
return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())
.addInputLines("A.java", "class A {}")
.expectUnchanged();
}
}

0 comments on commit 74a3a4d

Please sign in to comment.