77import com .sun .source .tree .ClassTree ;
88import com .sun .source .tree .MethodTree ;
99import 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}
0 commit comments