Interface MethodUtils
-
-
Method Summary
Static Methods Modifier and Type Method Description static java.util.List<javax.lang.model.element.ExecutableElement>
filterDeclaredMethods(javax.lang.model.type.TypeMirror type, boolean includeHierarchicalTypes, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Filters the declared methods of the specified type based on the given predicates.static java.util.List<javax.lang.model.element.ExecutableElement>
filterMethods(java.util.List<javax.lang.model.element.ExecutableElement> methods, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Filters the given list of executable elements (methods) based on the provided predicates.static java.util.List<javax.lang.model.element.ExecutableElement>
findAllDeclaredMethods(javax.lang.model.element.TypeElement type, java.lang.reflect.Type... excludedTypes)
Find all declared methods of the specified type element, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.static java.util.List<javax.lang.model.element.ExecutableElement>
findAllDeclaredMethods(javax.lang.model.element.TypeElement type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find all declared methods of the specified type element, including those inherited from superclasses and interfaces, and optionally filter them using the provided predicates.static java.util.List<javax.lang.model.element.ExecutableElement>
findAllDeclaredMethods(javax.lang.model.type.TypeMirror type, java.lang.reflect.Type... excludedTypes)
Find all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.static java.util.List<javax.lang.model.element.ExecutableElement>
findAllDeclaredMethods(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and optionally filter them using the provided predicates.static java.util.List<javax.lang.model.element.ExecutableElement>
findDeclaredMethods(javax.lang.model.element.TypeElement type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find the declared methods of the specified type element.static java.util.List<javax.lang.model.element.ExecutableElement>
findDeclaredMethods(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find the declared methods of the specified type mirror.static javax.lang.model.element.ExecutableElement
findMethod(javax.lang.model.element.TypeElement type, java.lang.String methodName)
Finds a method with the specified name in the given type, using an empty parameter type array as default.static javax.lang.model.element.ExecutableElement
findMethod(javax.lang.model.element.TypeElement type, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Finds a method with the specified name and parameter type names in the given type element.static javax.lang.model.element.ExecutableElement
findMethod(javax.lang.model.element.TypeElement type, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Finds a method with the specified name and parameter types in the given type element.static javax.lang.model.element.ExecutableElement
findMethod(javax.lang.model.type.TypeMirror type, java.lang.String methodName)
Finds a method with the specified name in the given type, using an empty parameter type array as default.static javax.lang.model.element.ExecutableElement
findMethod(javax.lang.model.type.TypeMirror type, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Finds a method with the specified name and parameter type names in the given type mirror.static javax.lang.model.element.ExecutableElement
findMethod(javax.lang.model.type.TypeMirror type, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Finds a method with the specified name and parameter types in the given type mirror.static java.util.List<javax.lang.model.element.ExecutableElement>
findPublicNonStaticMethods(javax.lang.model.element.TypeElement type, java.lang.reflect.Type... excludedTypes)
Find all public non-static methods declared in the specified type element, excluding those inherited from superclasses or interfaces.static java.util.List<javax.lang.model.element.ExecutableElement>
findPublicNonStaticMethods(javax.lang.model.type.TypeMirror type, java.lang.reflect.Type... excludedTypes)
Find all public non-static methods declared in the specified type mirror, excluding those inherited from superclasses or interfaces, and optionally exclude methods declared in the specified excluded types.static java.util.List<javax.lang.model.element.ExecutableElement>
getAllDeclaredMethods(javax.lang.model.element.TypeElement type)
Get all declared methods of the specified type element, including those inherited from superclasses and interfaces.static java.util.List<javax.lang.model.element.ExecutableElement>
getAllDeclaredMethods(javax.lang.model.type.TypeMirror type)
Get all declared methods of the specified type mirror, including those inherited from superclasses and interfaces.static java.util.List<javax.lang.model.element.ExecutableElement>
getDeclaredMethods(javax.lang.model.element.TypeElement type)
Get all declared methods of the specified type element.static java.util.List<javax.lang.model.element.ExecutableElement>
getDeclaredMethods(javax.lang.model.type.TypeMirror type)
Get all declared methods of the specified type mirror.static javax.lang.model.element.Element
getEnclosingElement(javax.lang.model.element.ExecutableElement method)
Returns the class or interface defining the executable.static java.lang.String
getMethodName(javax.lang.model.element.ExecutableElement method)
Gets the simple name of the method as a string.static java.util.List<javax.lang.model.type.TypeMirror>
getMethodParameterTypeMirrors(javax.lang.model.element.ExecutableElement method)
Gets the parameter type mirrors of the given method.static java.lang.String[]
getMethodParameterTypeNames(javax.lang.model.element.ExecutableElement method)
Gets the parameter type names of the given method.static javax.lang.model.element.ExecutableElement
getOverrideMethod(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement declaringMethod)
Finds an overridden method in the given type that corresponds to the provided declaring method.static java.lang.String
getReturnTypeName(javax.lang.model.element.ExecutableElement method)
Gets the return type name of the given method.static boolean
isMethod(javax.lang.model.element.ExecutableElement method)
Checks if the given executable element is a method.static boolean
isPublicNonStaticMethod(javax.lang.model.element.ExecutableElement method)
Checks whether the given method is a public non-static method.static boolean
matches(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Checks if the given method matches the specified method name and parameter type names.static boolean
matches(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Checks if the given method matches the specified method name and parameter types.static boolean
matchesMethod(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Checks if the given method matches the specified method name and parameter type names.static boolean
matchesMethod(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Checks if the given method matches the specified method name and parameter types.static boolean
matchesMethodName(javax.lang.model.element.ExecutableElement method, java.lang.String methodName)
Checks if the given method has the specified method name.static java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>
methodPredicateForExcludedTypes(java.lang.reflect.Type... excludedTypes)
Creates a predicate that filters out methods declared in the specified excluded types.
-
-
-
Method Detail
-
getDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> getDeclaredMethods(javax.lang.model.element.TypeElement type)
Get all declared methods of the specified type element.- Parameters:
type
- the specified type element, may be null- Returns:
- a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
-
getDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> getDeclaredMethods(javax.lang.model.type.TypeMirror type)
Get all declared methods of the specified type mirror.- Parameters:
type
- the specified type mirror, may be null- Returns:
- a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
-
getAllDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> getAllDeclaredMethods(javax.lang.model.element.TypeElement type)
Get all declared methods of the specified type element, including those inherited from superclasses and interfaces.- Parameters:
type
- the specified type element, may be null- Returns:
- a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
-
getAllDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> getAllDeclaredMethods(javax.lang.model.type.TypeMirror type)
Get all declared methods of the specified type mirror, including those inherited from superclasses and interfaces.- Parameters:
type
- the specified type mirror, may be null- Returns:
- a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
-
findDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findDeclaredMethods(javax.lang.model.element.TypeElement type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find the declared methods of the specified type element.- Parameters:
type
- the specified type element, may be nullmethodFilters
- the filters for method elements- Returns:
- a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
-
findDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findDeclaredMethods(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find the declared methods of the specified type mirror.- Parameters:
type
- the specified type mirror, may be nullmethodFilters
- the filters for method elements- Returns:
- a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
-
findAllDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods(javax.lang.model.element.TypeElement type, java.lang.reflect.Type... excludedTypes)
Find all declared methods of the specified type element, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.- Parameters:
type
- the specified type element, may be nullexcludedTypes
- the types whose methods should be excluded from the result, optional- Returns:
- a list of executable elements representing all declared methods of the specified type, excluding those declared in the excluded types, or an empty list if the input type is null
-
findAllDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods(javax.lang.model.type.TypeMirror type, java.lang.reflect.Type... excludedTypes)
Find all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.- Parameters:
type
- the specified type mirror, may be nullexcludedTypes
- the types whose methods should be excluded from the result, optional- Returns:
- a list of executable elements representing all declared methods of the specified type, excluding those declared in the excluded types, or an empty list if the input type is null
-
findPublicNonStaticMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findPublicNonStaticMethods(javax.lang.model.element.TypeElement type, java.lang.reflect.Type... excludedTypes)
Find all public non-static methods declared in the specified type element, excluding those inherited from superclasses or interfaces.- Parameters:
type
- the specified type element, may be nullexcludedTypes
- the types whose methods should be excluded from the result, optional- Returns:
- a list of executable elements representing all public non-static methods declared in the specified type, excluding those declared in the excluded types, or an empty list if the input type is null
-
findPublicNonStaticMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findPublicNonStaticMethods(javax.lang.model.type.TypeMirror type, java.lang.reflect.Type... excludedTypes)
Find all public non-static methods declared in the specified type mirror, excluding those inherited from superclasses or interfaces, and optionally exclude methods declared in the specified excluded types.- Parameters:
type
- the specified type mirror, may be nullexcludedTypes
- the types whose methods should be excluded from the result, optional- Returns:
- a list of executable elements representing all public non-static methods declared in the specified type, excluding those declared in the excluded types, or an empty list if the input type is null
-
findAllDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods(javax.lang.model.element.TypeElement type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find all declared methods of the specified type element, including those inherited from superclasses and interfaces, and optionally filter them using the provided predicates.- Parameters:
type
- the specified type element, may be nullmethodFilters
- the filters for method elements, optional- Returns:
- a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, or an empty list if the input type is null
-
findAllDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Find all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and optionally filter them using the provided predicates.- Parameters:
type
- the specified type mirror, may be nullmethodFilters
- the filters for method elements, optional- Returns:
- a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, or an empty list if the input type is null
-
filterDeclaredMethods
static java.util.List<javax.lang.model.element.ExecutableElement> filterDeclaredMethods(javax.lang.model.type.TypeMirror type, boolean includeHierarchicalTypes, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Filters the declared methods of the specified type based on the given predicates.- Parameters:
type
- the type whose declared methods are to be filteredincludeHierarchicalTypes
- whether to include methods from superclasses and interfacesmethodFilters
- the predicates used to filter the methods- Returns:
- a list of executable elements representing the filtered methods, or an empty list if the input type is null or no methods match the filters
-
isMethod
static boolean isMethod(javax.lang.model.element.ExecutableElement method)
Checks if the given executable element is a method.- Parameters:
method
- the executable element to check- Returns:
- true if the element is a method, false otherwise
-
isPublicNonStaticMethod
static boolean isPublicNonStaticMethod(javax.lang.model.element.ExecutableElement method)
Checks whether the given method is a public non-static method.- Parameters:
method
- the executable element to check- Returns:
- true if the method is a public non-static method, false otherwise
-
findMethod
static javax.lang.model.element.ExecutableElement findMethod(javax.lang.model.element.TypeElement type, java.lang.String methodName)
Finds a method with the specified name in the given type, using an empty parameter type array as default.- Parameters:
type
- the type element to search for the methodmethodName
- the name of the method to find- Returns:
- the first matching executable element representing the method, or null if none is found
-
findMethod
static javax.lang.model.element.ExecutableElement findMethod(javax.lang.model.type.TypeMirror type, java.lang.String methodName)
Finds a method with the specified name in the given type, using an empty parameter type array as default.- Parameters:
type
- the type mirror to search for the methodmethodName
- the name of the method to find- Returns:
- the first matching executable element representing the method, or null if none is found
-
findMethod
static javax.lang.model.element.ExecutableElement findMethod(javax.lang.model.element.TypeElement type, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Finds a method with the specified name and parameter types in the given type element.- Parameters:
type
- the type element to search for the methodmethodName
- the name of the method to findparameterTypes
- the parameter types of the method to match- Returns:
- the first matching executable element representing the method, or null if none is found
-
findMethod
static javax.lang.model.element.ExecutableElement findMethod(javax.lang.model.type.TypeMirror type, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Finds a method with the specified name and parameter types in the given type mirror.- Parameters:
type
- the type mirror to search for the methodmethodName
- the name of the method to findparameterTypes
- the parameter types of the method to match- Returns:
- the first matching executable element representing the method, or null if none is found
-
findMethod
static javax.lang.model.element.ExecutableElement findMethod(javax.lang.model.element.TypeElement type, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Finds a method with the specified name and parameter type names in the given type element.- Parameters:
type
- the type element to search for the methodmethodName
- the name of the method to findparameterTypeNames
- the names of the parameter types of the method to match- Returns:
- the first matching executable element representing the method, or null if none is found
-
findMethod
static javax.lang.model.element.ExecutableElement findMethod(javax.lang.model.type.TypeMirror type, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Finds a method with the specified name and parameter type names in the given type mirror.- Parameters:
type
- the type mirror to search for the methodmethodName
- the name of the method to findparameterTypeNames
- the names of the parameter types of the method to match- Returns:
- the first matching executable element representing the method, or null if none is found
-
getOverrideMethod
static javax.lang.model.element.ExecutableElement getOverrideMethod(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement declaringMethod)
Finds an overridden method in the given type that corresponds to the provided declaring method.- Parameters:
processingEnv
- the processing environment used to get element utilitiestype
- the type element in which to search for the overridden methoddeclaringMethod
- the method element whose override is to be found- Returns:
- the overridden method in the specified type, or null if no such method exists
-
filterMethods
static java.util.List<javax.lang.model.element.ExecutableElement> filterMethods(java.util.List<javax.lang.model.element.ExecutableElement> methods, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
Filters the given list of executable elements (methods) based on the provided predicates.- Parameters:
methods
- the list of executable elements (methods) to be filteredmethodFilters
- the array of predicates used for filtering the methods- Returns:
- a filtered list of executable elements matching all the provided predicates, or an empty list if the input list is null or empty, or no methods match the filters
-
getMethodName
static java.lang.String getMethodName(javax.lang.model.element.ExecutableElement method)
Gets the simple name of the method as a string.- Parameters:
method
- the executable element representing the method, may be null- Returns:
- the simple name of the method, or null if the method is null
-
getReturnTypeName
static java.lang.String getReturnTypeName(javax.lang.model.element.ExecutableElement method)
Gets the return type name of the given method.- Parameters:
method
- the executable element representing the method- Returns:
- the return type name of the method, or null if the method is null
-
getMethodParameterTypeMirrors
static java.util.List<javax.lang.model.type.TypeMirror> getMethodParameterTypeMirrors(javax.lang.model.element.ExecutableElement method)
Gets the parameter type mirrors of the given method.- Parameters:
method
- the executable element representing the method- Returns:
- a list of type mirrors representing the parameter types of the method, or an empty list if the method is null or has no parameters
-
getMethodParameterTypeNames
static java.lang.String[] getMethodParameterTypeNames(javax.lang.model.element.ExecutableElement method)
Gets the parameter type names of the given method.- Parameters:
method
- the executable element- Returns:
- the parameter type names of the given method
-
matches
static boolean matches(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Checks if the given method matches the specified method name and parameter types.- Parameters:
method
- the executable element representing the method to checkmethodName
- the name of the method to matchparameterTypes
- the parameter types of the method to match- Returns:
- true if the method matches the given name and parameter types, false otherwise
-
matches
static boolean matches(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Checks if the given method matches the specified method name and parameter type names.- Parameters:
method
- the executable element representing the method to checkmethodName
- the name of the method to matchparameterTypeNames
- the names of the parameter types to match- Returns:
- true if the method matches the given name and parameter type names, false otherwise
-
matchesMethodName
static boolean matchesMethodName(javax.lang.model.element.ExecutableElement method, java.lang.String methodName)
Checks if the given method has the specified method name.- Parameters:
method
- the executable element representing the method to checkmethodName
- the name of the method to match- Returns:
- true if the method's name matches the given method name, false otherwise
-
matchesMethod
static boolean matchesMethod(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
Checks if the given method matches the specified method name and parameter types.- Parameters:
method
- the executable element representing the method to checkmethodName
- the name of the method to matchparameterTypes
- the parameter types of the method to match- Returns:
- true if the method matches the given name and parameter types, false otherwise
-
matchesMethod
static boolean matchesMethod(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
Checks if the given method matches the specified method name and parameter type names.- Parameters:
method
- the executable element representing the method to checkmethodName
- the name of the method to matchparameterTypeNames
- the names of the parameter types to match- Returns:
- true if the method matches the given name and parameter type names, false otherwise
-
getEnclosingElement
static javax.lang.model.element.Element getEnclosingElement(javax.lang.model.element.ExecutableElement method)
Returns the class or interface defining the executable.- Parameters:
method
-ExecutableElement
- Returns:
null
ifmethod
isnull
-
methodPredicateForExcludedTypes
static java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement> methodPredicateForExcludedTypes(java.lang.reflect.Type... excludedTypes)
Creates a predicate that filters out methods declared in the specified excluded types.- Parameters:
excludedTypes
- the types whose methods should be excluded from the result- Returns:
- a predicate that returns
true
for methods not declared in any of the excluded types
-
-