Skip to content

Commit

Permalink
Set an order for the bugpatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Nov 9, 2023
1 parent 5e4f425 commit ca4f7e5
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 45 deletions.
9 changes: 0 additions & 9 deletions workshop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ navigate to a check's associated test class to drop the class-level `@Disabled`
annotation. Upon initial execution the tests will fail; the goal is to get then
to pass.

It is recommended (but not required) to solve the assignments in the following
order:

* `AssertJIsNullMethod.java`
* `DropMockitoEq.java`
* `JUnitTestMethodDeclaration.java`
* `DropAutowiredConstructorAnnotation.java`
* `DeleteIdentityConversion.java`

Some utility classes that you can use:

* `com.google.errorprone.util.ASTHelpers`: contains many common operations on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
summary = "Empty method can likely be deleted",
severity = WARNING,
tags = SIMPLIFICATION)
public final class DeleteEmptyMethod extends BugChecker implements MethodTreeMatcher {
public final class Assignment0DeleteEmptyMethod extends BugChecker implements MethodTreeMatcher {
private static final long serialVersionUID = 1L;

/** Instantiates a new {@link DeleteEmptyMethod} instance. */
public DeleteEmptyMethod() {}
/** Instantiates a new {@link Assignment0DeleteEmptyMethod} instance. */
public Assignment0DeleteEmptyMethod() {}

@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
summary = "Prefer `.isNull()` over `.isEqualTo(null)`",
severity = SUGGESTION,
tags = SIMPLIFICATION)
public final class AssertJIsNullMethod extends BugChecker implements MethodInvocationTreeMatcher {
public final class Assignment1AssertJIsNullMethod extends BugChecker implements MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<MethodInvocationTree> ASSERT_IS_EQUAL_TO_NULL =
allOf(
instanceMethod().onDescendantOf("org.assertj.core.api.Assert").named("isEqualTo"),
argumentCount(1),
argument(0, nullLiteral()));

/** Instantiates a new {@link AssertJIsNullMethod} instance. */
public AssertJIsNullMethod() {}
/** Instantiates a new {@link Assignment1AssertJIsNullMethod} instance. */
public Assignment1AssertJIsNullMethod() {}

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
summary = "Don't unnecessarily use Mockito's `eq(...)`",
severity = SUGGESTION,
tags = SIMPLIFICATION)
public final class DropMockitoEq extends BugChecker implements MethodInvocationTreeMatcher {
public final class Assignment2DropMockitoEq extends BugChecker implements MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<ExpressionTree> MOCKITO_EQ_METHOD =
staticMethod().onClass("org.mockito.ArgumentMatchers").named("eq");

/** Instantiates a new {@link DropMockitoEq} instance. */
public DropMockitoEq() {}
/** Instantiates a new {@link Assignment2DropMockitoEq} instance. */
public Assignment2DropMockitoEq() {}

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
summary = "Omit `@Autowired` on a class' sole constructor, as it is redundant",
severity = SUGGESTION,
tags = SIMPLIFICATION)
public final class DropAutowiredConstructorAnnotation extends BugChecker
public final class Assignment3DropAutowiredConstructorAnnotation extends BugChecker
implements ClassTreeMatcher {
private static final long serialVersionUID = 1L;
private static final MultiMatcher<Tree, AnnotationTree> AUTOWIRED_ANNOTATION =
annotations(AT_LEAST_ONE, isType("org.springframework.beans.factory.annotation.Autowired"));

/** Instantiates a new {@link DropAutowiredConstructorAnnotation} instance. */
public DropAutowiredConstructorAnnotation() {}
/** Instantiates a new {@link Assignment3DropAutowiredConstructorAnnotation} instance. */
public Assignment3DropAutowiredConstructorAnnotation() {}

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"UnusedMethod",
"UnusedVariable"
} /* This check is yet to be implemented as part of the demo. */)
public final class JUnitTestMethodDeclaration extends BugChecker implements MethodTreeMatcher {
public final class Assignment4JUnitTestMethodDeclaration extends BugChecker implements MethodTreeMatcher {
private static final long serialVersionUID = 1L;
private static final ImmutableSet<Modifier> ILLEGAL_MODIFIERS =
Sets.immutableEnumSet(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC);
private static final MultiMatcher<MethodTree, AnnotationTree> TEST_METHOD =
annotations(AT_LEAST_ONE, anyOf(isType("org.junit.jupiter.api.Test")));

/** Instantiates a new {@link JUnitTestMethodDeclaration} instance. */
public JUnitTestMethodDeclaration() {}
/** Instantiates a new {@link Assignment4JUnitTestMethodDeclaration} instance. */
public Assignment4JUnitTestMethodDeclaration() {}

@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
summary = "Avoid or clarify identity conversions",
severity = WARNING,
tags = SIMPLIFICATION)
public final class DeleteIdentityConversion extends BugChecker
public final class Assignment5DeleteIdentityConversion extends BugChecker
implements MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<ExpressionTree> IS_CONVERSION_METHOD =
Expand Down Expand Up @@ -60,8 +60,8 @@ public final class DeleteIdentityConversion extends BugChecker
.onClass("com.google.errorprone.matchers.Matchers")
.namedAnyOf("allOf", "anyOf"));

/** Instantiates a new {@link DeleteIdentityConversion} instance. */
public DeleteIdentityConversion() {}
/** Instantiates a new {@link Assignment5DeleteIdentityConversion} instance. */
public Assignment5DeleteIdentityConversion() {}

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.jupiter.api.Test;

@Disabled("Enable this when implementing the BugChecker.")
final class DeleteEmptyMethodTest {
final class Assignment0Assignment0DeleteEmptyMethodTest {
@Test
void identification() {
CompilationTestHelper.newInstance(DeleteEmptyMethod.class, getClass())
CompilationTestHelper.newInstance(Assignment0DeleteEmptyMethod.class, getClass())
.addSourceLines(
"A.java",
"class A {",
Expand Down Expand Up @@ -44,7 +44,7 @@ void identification() {

@Test
void replacement() {
BugCheckerRefactoringTestHelper.newInstance(DeleteEmptyMethod.class, getClass())
BugCheckerRefactoringTestHelper.newInstance(Assignment0DeleteEmptyMethod.class, getClass())
.addInputLines(
"A.java",
"final class A {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.jupiter.api.Test;

@Disabled("Enable this when implementing the BugChecker.")
final class AssertJIsNullMethodTest {
final class Assignment1AssertJIsNullMethodTest {
@Test
void identification() {
CompilationTestHelper.newInstance(AssertJIsNullMethod.class, getClass())
CompilationTestHelper.newInstance(Assignment1AssertJIsNullMethod.class, getClass())
.addSourceLines(
"A.java",
"import static org.assertj.core.api.Assertions.assertThat;",
Expand All @@ -34,7 +34,7 @@ void identification() {

@Test
void replacement() {
BugCheckerRefactoringTestHelper.newInstance(AssertJIsNullMethod.class, getClass())
BugCheckerRefactoringTestHelper.newInstance(Assignment1AssertJIsNullMethod.class, getClass())
.addInputLines(
"A.java",
"import static org.assertj.core.api.Assertions.assertThat;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.jupiter.api.Test;

@Disabled("Enable this when implementing the BugChecker.")
final class DropMockitoEqTest {
final class Assignment2DropMockitoEqTest {
@Test
void identification() {
CompilationTestHelper.newInstance(DropMockitoEq.class, getClass())
CompilationTestHelper.newInstance(Assignment2DropMockitoEq.class, getClass())
.addSourceLines(
"A.java",
"import static org.mockito.ArgumentMatchers.eq;",
Expand Down Expand Up @@ -52,7 +52,7 @@ void identification() {

@Test
void replacement() {
BugCheckerRefactoringTestHelper.newInstance(DropMockitoEq.class, getClass())
BugCheckerRefactoringTestHelper.newInstance(Assignment2DropMockitoEq.class, getClass())
.addInputLines(
"A.java",
"import static org.mockito.ArgumentMatchers.eq;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.jupiter.api.Test;

@Disabled("Enable this when implementing the BugChecker.")
final class DropAutowiredConstructorAnnotationTest {
final class Assignment3DropAutowiredConstructorAnnotationTest {
@Test
void identification() {
CompilationTestHelper.newInstance(DropAutowiredConstructorAnnotation.class, getClass())
CompilationTestHelper.newInstance(Assignment3DropAutowiredConstructorAnnotation.class, getClass())
.addSourceLines(
"Container.java",
"import com.google.errorprone.annotations.Immutable;",
Expand Down Expand Up @@ -69,7 +69,7 @@ void identification() {
@Test
void replacement() {
BugCheckerRefactoringTestHelper.newInstance(
DropAutowiredConstructorAnnotation.class, getClass())
Assignment3DropAutowiredConstructorAnnotation.class, getClass())
.addInputLines(
"Container.java",
"import org.springframework.beans.factory.annotation.Autowired;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.jupiter.api.Test;

@Disabled("Enable this to validate part 1.")
final class JUnitTestMethodDeclarationTest {
final class Assignment4JUnitTestMethodDeclarationTest {
@Test
void identificationIllegalModifiers() {
CompilationTestHelper.newInstance(JUnitTestMethodDeclaration.class, getClass())
CompilationTestHelper.newInstance(Assignment4JUnitTestMethodDeclaration.class, getClass())
.addSourceLines(
"A.java",
"import org.junit.jupiter.api.Test;",
Expand Down Expand Up @@ -42,7 +42,7 @@ void identificationIllegalModifiers() {

@Test
void replacementIllegalModifiers() {
BugCheckerRefactoringTestHelper.newInstance(JUnitTestMethodDeclaration.class, getClass())
BugCheckerRefactoringTestHelper.newInstance(Assignment4JUnitTestMethodDeclaration.class, getClass())
.addInputLines(
"A.java",
"import org.junit.jupiter.api.Test;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.jupiter.api.Test;

@Disabled("Enable this when implementing the BugChecker.")
final class DeleteIdentityConversionTest {
final class Assignment5DeleteIdentityConversionTest {
@Test
void identification() {
CompilationTestHelper.newInstance(DeleteIdentityConversion.class, getClass())
CompilationTestHelper.newInstance(Assignment5DeleteIdentityConversion.class, getClass())
.addSourceLines(
"A.java",
"import static com.google.errorprone.matchers.Matchers.instanceMethod;",
Expand Down Expand Up @@ -160,7 +160,7 @@ void identification() {

@Test
void replacement() {
BugCheckerRefactoringTestHelper.newInstance(DeleteIdentityConversion.class, getClass())
BugCheckerRefactoringTestHelper.newInstance(Assignment5DeleteIdentityConversion.class, getClass())
.addInputLines(
"A.java",
"import static com.google.errorprone.matchers.Matchers.staticMethod;",
Expand Down

0 comments on commit ca4f7e5

Please sign in to comment.