Skip to content

Commit 54e7619

Browse files
committed
Address review comments
1 parent eb24648 commit 54e7619

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreASTHelpers.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.sun.source.tree.ClassTree;
88
import com.sun.source.tree.MethodTree;
99
import com.sun.source.tree.Tree;
10-
import javax.lang.model.element.Name;
1110

1211
/**
1312
* A set of helper methods for working with the AST.
@@ -20,12 +19,13 @@ private MoreASTHelpers() {}
2019
/**
2120
* Finds methods with the given name in the given class.
2221
*
23-
* @param enclosingClass The class to search in.
2422
* @param methodName The method name to search for.
23+
* @param state A {@link VisitorState} describing the context in which the given {@link Tree} is
24+
* found.
2525
* @return The {@link MethodTree}s of the methods with the given name in the given class.
2626
*/
27-
public static ImmutableList<MethodTree> findMethods(ClassTree enclosingClass, String methodName) {
28-
return enclosingClass.getMembers().stream()
27+
public static ImmutableList<MethodTree> findMethods(String methodName, VisitorState state) {
28+
return state.findEnclosing(ClassTree.class).getMembers().stream()
2929
.filter(MethodTree.class::isInstance)
3030
.map(MethodTree.class::cast)
3131
.filter(method -> method.getName().contentEquals(methodName))
@@ -41,11 +41,6 @@ public static ImmutableList<MethodTree> findMethods(ClassTree enclosingClass, St
4141
* @return Whether there are any methods with the given name in the given class.
4242
*/
4343
public static boolean isMethodInEnclosingClass(String methodName, VisitorState state) {
44-
return state.findEnclosing(ClassTree.class).getMembers().stream()
45-
.filter(MethodTree.class::isInstance)
46-
.map(MethodTree.class::cast)
47-
.map(MethodTree::getName)
48-
.map(Name::toString)
49-
.anyMatch(methodName::equals);
44+
return !findMethods(methodName, state).isEmpty();
5045
}
5146
}

error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tech.picnic.errorprone.bugpatterns.util;
22

33
import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE;
4-
import static com.google.errorprone.matchers.Matchers.allOf;
54
import static com.google.errorprone.matchers.Matchers.annotations;
65
import static com.google.errorprone.matchers.Matchers.anyOf;
76
import static com.google.errorprone.matchers.Matchers.isType;
@@ -20,7 +19,7 @@
2019
import javax.lang.model.type.TypeKind;
2120

2221
/**
23-
* A set of JUnit Jupiter-specific helper methods and {@link Matcher Matchers}.
22+
* A set of JUnit-specific helper methods and {@link Matcher Matchers}.
2423
*
2524
* <p>These are additions to the ones from {@link com.google.errorprone.matchers.JUnitMatchers}.
2625
*/
@@ -47,7 +46,7 @@ public final class MoreJUnitMatchers {
4746
* Matches methods that have a {@link org.junit.jupiter.params.provider.MethodSource} annotation.
4847
*/
4948
public static final Matcher<MethodTree> HAS_METHOD_SOURCE =
50-
allOf(annotations(AT_LEAST_ONE, isType("org.junit.jupiter.params.provider.MethodSource")));
49+
annotations(AT_LEAST_ONE, isType("org.junit.jupiter.params.provider.MethodSource"));
5150

5251
private MoreJUnitMatchers() {}
5352

0 commit comments

Comments
 (0)