Class MethodMatcher
- java.lang.Object
-
- org.openrewrite.java.MethodMatcher
-
public class MethodMatcher extends java.lang.Object
This class accepts an AspectJ method pattern and is used to identify methods that match the expression. The format of the method pattern is as follows:#declaring class# #method name#(#argument list#)
- The declaring class must be fully qualified.
- A wildcard character, "*", may be used in either the declaring class or method name.
- The argument list is expressed as a comma-separated list of the argument types
- ".." can be used in the argument list to match zero or more arguments of any type.
EXAMPLES:
* *(..) - All method invocations java.util.* *(..) - All method invocations to classes belonging to java.util (including sub-packages) java.util.Collections *(..) - All method invocations on java.util.Collections class java.util.Collections unmodifiable*(..) - All method invocations starting with "unmodifiable" on java.util.Collections java.util.Collections min(..) - All method invocations for all overloads of "min" java.util.Collections emptyList() - All method invocations on java.util.Collections.emptyList() my.org.MyClass *(boolean, ..) - All method invocations where the first arg is a boolean in my.org.MyClass
-
-
Constructor Summary
Constructors Constructor Description MethodMatcher(java.lang.String signature)
MethodMatcher(java.lang.String signature, boolean matchOverrides)
MethodMatcher(java.lang.String signature, @Nullable java.lang.Boolean matchOverrides)
MethodMatcher(J.MethodDeclaration method)
MethodMatcher(J.MethodDeclaration method, boolean matchOverrides)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isFullyQualifiedClassReference(J.FieldAccess fieldAccess)
Evaluate whether this MethodMatcher and the specified FieldAccess are describing the same type or not.boolean
matches(@Nullable JavaType type)
boolean
matches(Expression maybeMethod)
boolean
matches(J.MethodDeclaration method, J.ClassDeclaration enclosing)
boolean
matches(J.MethodInvocation method)
boolean
matches(J.NewClass constructor)
static java.lang.String
methodPattern(J.MethodDeclaration method)
-
-
-
Constructor Detail
-
MethodMatcher
public MethodMatcher(java.lang.String signature, @Nullable @Nullable java.lang.Boolean matchOverrides)
-
MethodMatcher
public MethodMatcher(java.lang.String signature, boolean matchOverrides)
-
MethodMatcher
public MethodMatcher(J.MethodDeclaration method, boolean matchOverrides)
-
MethodMatcher
public MethodMatcher(java.lang.String signature)
-
MethodMatcher
public MethodMatcher(J.MethodDeclaration method)
-
-
Method Detail
-
matches
public boolean matches(@Nullable @Nullable JavaType type)
-
matches
public boolean matches(J.MethodDeclaration method, J.ClassDeclaration enclosing)
-
matches
public boolean matches(Expression maybeMethod)
-
matches
public boolean matches(J.MethodInvocation method)
-
matches
public boolean matches(J.NewClass constructor)
-
isFullyQualifiedClassReference
public boolean isFullyQualifiedClassReference(J.FieldAccess fieldAccess)
Evaluate whether this MethodMatcher and the specified FieldAccess are describing the same type or not. Known limitation/bug: MethodMatchers can have patterns/wildcards like "com.*.Bar" instead of something concrete like "com.foo.Bar". This limitation is not desirable or intentional and should be fixed. If a methodMatcher is passed that includes wildcards the result will always be "false"- Parameters:
fieldAccess
- A J.FieldAccess that hopefully has the same fully qualified type as this matcher.
-
methodPattern
public static java.lang.String methodPattern(J.MethodDeclaration method)
-
-