Class MethodInfo
- All Implemented Interfaces:
Comparable<MethodInfo>
See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
MethodInfo
(ClassInfo declaringClass, Method m) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionaccept
(Predicate<MethodInfo> test, Consumer<MethodInfo> action) Performs an action on this object if the specified predicate test passes.Attempts to callx.setAccessible(
and quietly ignores security exceptions.true )boolean
argsOnlyOfType
(Class<?>... args) Returnstrue if the parameters on the method only consist of the types specified in the list.boolean
Returnstrue if this constructor can accept the specified arguments in the specified order.int
canAcceptFuzzy
(Object... args) Returns the number of matching arguments for this method.int
<A extends Annotation>
MethodInfoforEachAnnotation
(Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations defined on this method.<A extends Annotation>
MethodInfoforEachAnnotation
(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations defined on this method.forEachAnnotationInfo
(Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) Perform an action on all matching annotations on this method.forEachMatching
(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching declared methods with the same name and arguments on all superclasses and interfaces.forEachMatchingParentFirst
(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching declared methods with the same name and arguments on all superclasses and interfaces.<A extends Annotation>
AgetAnnotation
(Class<A> type) Finds the annotation of the specified type defined on this method.<A extends Annotation>
AgetAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Finds the annotation of the specified type defined on this method.Constructs anAnnotationList
of all annotations found on this method.getAnnotationList
(Predicate<AnnotationInfo<?>> filter) Constructs anAnnotationList
of all matching annotations found on this method.getAnnotationListMethodOnly
(Predicate<AnnotationInfo<?>> filter) Same asgetAnnotationList(Predicate)
except only returns annotations defined on methods.final Annotation
getAnyAnnotation
(Class<? extends Annotation>... types) Returns the first annotation in the specified list on this method.getName()
Returns the name of this method.Returns the bean property name if this is a getter or setter.Returns the generic return type of this method as aClassInfo
object.Returns the signature of this method.boolean
hasAllArgs
(Class<?>... requiredParams) Returnstrue if this method has at least the specified parameters.<A extends Annotation>
booleanhasAnnotation
(Class<A> type) Returnstrue if the specified annotation is present on this method.<A extends Annotation>
booleanhasAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is present on this method.final boolean
hasAnyAnnotations
(Class<? extends Annotation>... types) Returnstrue if at least one of the specified annotation is present on this method.boolean
Returnstrue if this method has the specified parameter.<A extends Annotation>
booleanhasNoAnnotation
(Class<A> type) Returnstrue if the specified annotation is not present on this method.<A extends Annotation>
booleanhasNoAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is not present on this method.boolean
hasReturnType
(Class<?> c) Returnstrue if this method has this return type.boolean
Returnstrue if this method has this return type.boolean
hasReturnTypeParent
(Class<?> c) Returnstrue if this method has this parent return type.boolean
Returnstrue if this method has this parent return type.inner()
Returns the wrapped method.<T> T
Shortcut for calling the invoke method on the underlying method.invokeFuzzy
(Object pojo, Object... args) Invokes the specified method using fuzzy-arg matching.boolean
isBridge()
Returnstrue if this method is a bridge method.boolean
matches
(Predicate<MethodInfo> test) Returnstrue if this object passes the specified predicate test.static MethodInfo
Convenience method for instantiating aMethodInfo
;static MethodInfo
Convenience method for instantiating aMethodInfo
;static MethodInfo
Convenience method for instantiating aMethodInfo
;Methods inherited from class org.apache.juneau.reflect.ExecutableInfo
forEachParam, forEachParameterAnnotation, fuzzyArgsMatch, fuzzyArgsMatch, fuzzyArgsMatch, getDeclaringClass, getExceptionTypes, getFullName, getParam, getParamCount, getParams, getParamType, getParamTypes, getRawGenericParamType, getRawGenericParamTypes, getRawParameter, getRawParameters, getRawParamType, getRawParamTypes, getShortName, getSimpleName, hasFuzzyParamTypes, hasFuzzyParamTypes, hasMatchingParamTypes, hasMatchingParamTypes, hasName, hasName, hasName, hasNoParams, hasNumParams, hasParams, hasParamTypes, hasParamTypes, is, isAbstract, isAll, isAny, isConstructor, isDeprecated, isNotAbstract, isNotDeprecated, isNotProtected, isNotPublic, isNotStatic, isProtected, isPublic, isStatic, isVisible, setAccessible, toString
-
Constructor Details
-
MethodInfo
Constructor.- Parameters:
declaringClass
- The class that declares this method.m
- The method being wrapped.
-
-
Method Details
-
of
Convenience method for instantiating aMethodInfo
;- Parameters:
declaringClass
- The class that declares this method.m
- The method being wrapped.- Returns:
- A new
MethodInfo
object, ornull if the method was null;
-
of
Convenience method for instantiating aMethodInfo
;- Parameters:
declaringClass
- The class that declares this method.m
- The method being wrapped.- Returns:
- A new
MethodInfo
object, ornull if the method was null;
-
of
Convenience method for instantiating aMethodInfo
;- Parameters:
m
- The method being wrapped.- Returns:
- A new
MethodInfo
object, ornull if the method was null;
-
inner
Returns the wrapped method.- Returns:
- The wrapped method.
-
canAccept
Returnstrue if this constructor can accept the specified arguments in the specified order.- Parameters:
args
- The arguments to check.- Returns:
true if this constructor can accept the specified arguments in the specified order.
-
canAcceptFuzzy
Returns the number of matching arguments for this method.- Parameters:
args
- The arguments to check.- Returns:
- the number of matching arguments for this method.
-
forEachMatching
Performs an action on all matching declared methods with the same name and arguments on all superclasses and interfaces.Methods are accessed from child-to-parent order.
- Parameters:
filter
- A predicate to apply to the entries to determine if action should be performed. Can benull .action
- An action to perform on the entry.- Returns:
- This object.
-
forEachMatchingParentFirst
public MethodInfo forEachMatchingParentFirst(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching declared methods with the same name and arguments on all superclasses and interfaces.Methods are accessed from parent-to-child order.
- Parameters:
filter
- A predicate to apply to the entries to determine if action should be performed. Can benull .action
- An action to perform on the entry.- Returns:
- This object.
-
getAnnotation
Finds the annotation of the specified type defined on this method.If this is a method and the annotation cannot be found on the immediate method, searches methods with the same signature on the parent classes or interfaces.
The search is performed in child-to-parent order.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.- Returns:
- The annotation if found, or
null if not.
-
getAnnotation
Finds the annotation of the specified type defined on this method.Searches all methods with the same signature on the parent classes or interfaces and the return type on the method.
- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation to look for.- Returns:
- The first annotation found, or
null if it doesn't exist.
-
hasAnnotation
Returnstrue if the specified annotation is present on this method.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.- Returns:
true if the specified annotation is present on this method.
-
hasAnnotation
public <A extends Annotation> boolean hasAnnotation(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is present on this method.- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation to look for.- Returns:
true if the specified annotation is present on this method.
-
hasNoAnnotation
public <A extends Annotation> boolean hasNoAnnotation(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is not present on this method.- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation to look for.- Returns:
true if the specified annotation is not present on this method.
-
hasNoAnnotation
Returnstrue if the specified annotation is not present on this method.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.- Returns:
true if the specified annotation is not present on this method.
-
hasAnyAnnotations
Returnstrue if at least one of the specified annotation is present on this method.- Parameters:
types
- The annotation to look for.- Returns:
true if at least one of the specified annotation is present on this method.
-
forEachAnnotation
public <A extends Annotation> MethodInfo forEachAnnotation(Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations defined on this method.Searches all methods with the same signature on the parent classes or interfaces and the return type on the method.
Results are parent-to-child ordered.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.filter
- A predicate to apply to the entries to determine if action should be performed. Can benull .action
- An action to perform on the entry.- Returns:
- This object.
-
forEachAnnotation
public <A extends Annotation> MethodInfo forEachAnnotation(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations defined on this method.Searches all methods with the same signature on the parent classes or interfaces and the return type on the method.
Results are parent-to-child ordered.- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation type.filter
- A predicate to apply to the entries to determine if action should be performed. Can benull .action
- An action to perform on the entry.- Returns:
- This object.
-
getAnyAnnotation
Returns the first annotation in the specified list on this method.- Parameters:
types
- The annotations to look for.- Returns:
- The first matching annotation.
-
getAnnotationList
Constructs anAnnotationList
of all annotations found on this method.Annotations are appended in the following orders:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
- On this method and matching methods ordered parent-to-child.
- Returns:
- A new
AnnotationList
object on every call.
-
getAnnotationList
Constructs anAnnotationList
of all matching annotations found on this method.Annotations are appended in the following orders:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
- On this method and matching methods ordered parent-to-child.
- Parameters:
filter
- A predicate to apply to the entries to determine if value should be added. Can benull .- Returns:
- A new
AnnotationList
object on every call.
-
getAnnotationListMethodOnly
Same asgetAnnotationList(Predicate)
except only returns annotations defined on methods.- Parameters:
filter
- A predicate to apply to the entries to determine if value should be added. Can benull .- Returns:
- A new
AnnotationList
object on every call.
-
forEachAnnotationInfo
public MethodInfo forEachAnnotationInfo(Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) Perform an action on all matching annotations on this method.- Parameters:
filter
- A predicate to apply to the entries to determine if action should be performed. Can benull .action
- An action to perform on the entry.- Returns:
- This object.
-
getReturnType
Returns the generic return type of this method as aClassInfo
object.- Returns:
- The generic return type of this method.
-
hasReturnType
Returnstrue if this method has this return type.- Parameters:
c
- The return type to test for.- Returns:
true if this method has this return type.
-
hasReturnType
Returnstrue if this method has this return type.- Parameters:
ci
- The return type to test for.- Returns:
true if this method has this return type.
-
hasReturnTypeParent
Returnstrue if this method has this parent return type.- Parameters:
c
- The return type to test for.- Returns:
true if this method has this parent return type.
-
hasReturnTypeParent
Returnstrue if this method has this parent return type.- Parameters:
ci
- The return type to test for.- Returns:
true if this method has this parent return type.
-
matches
Returnstrue if this object passes the specified predicate test.- Parameters:
test
- The test to perform.- Returns:
true if this object passes the specified predicate test.
-
accept
Performs an action on this object if the specified predicate test passes.- Parameters:
test
- A test to apply to determine if action should be executed. Can benull .action
- An action to perform on this object.- Returns:
- This object.
-
invoke
Shortcut for calling the invoke method on the underlying method.- Type Parameters:
T
- The method return type.- Parameters:
obj
- the object the underlying method is invoked from.args
- the arguments used for the method call- Returns:
- The object returned from the method.
- Throws:
ExecutableException
- Exception occurred on invoked constructor/method/field.
-
invokeFuzzy
Invokes the specified method using fuzzy-arg matching.Arguments will be matched to the parameters based on the parameter types.
Arguments can be in any order.
Extra arguments will be ignored.
Missing arguments will be leftnull .Note that this only works for methods that have distinguishable argument types.
It's not going to work on methods with generic argument types likeObject - Parameters:
pojo
- The POJO the method is being called on.
Can benull for static methods.args
- The arguments to pass to the method.- Returns:
- The results of the method invocation.
- Throws:
ExecutableException
- Exception occurred on invoked constructor/method/field.
-
getSignature
Returns the signature of this method.For no-arg methods, the signature will be a simple string such as
"toString" . For methods with one or more args, the arguments will be fully-qualified class names (e.g."append(java.util.StringBuilder,boolean)" )- Returns:
- The methods signature.
-
getPropertyName
Returns the bean property name if this is a getter or setter.- Returns:
- The bean property name, or
null if this isn't a getter or setter.
-
argsOnlyOfType
Returnstrue if the parameters on the method only consist of the types specified in the list.Example:
// Example method: public void foo(Stringbar , Integerbaz ); argsOnlyOfType(fooMethod , String.class , Integer.class );// True. argsOnlyOfType(fooMethod , String.class , Integer.class , Map.class );// True. argsOnlyOfType(fooMethod , String.class );// False. - Parameters:
args
- The valid class types (exact) for the arguments.- Returns:
true if the method parameters only consist of the types specified in the list.
-
hasAllArgs
Returnstrue if this method has at least the specified parameters.Method may or may not have additional parameters besides those specified.
- Parameters:
requiredParams
- The parameter types to check for.- Returns:
true if this method has at least the specified parameters.
-
hasArg
Returnstrue if this method has the specified parameter.Method may or may not have additional parameters besides the one specified.
- Parameters:
requiredParam
- The parameter type to check for.- Returns:
true if this method has at least the specified parameter.
-
isBridge
Returnstrue if this method is a bridge method.- Returns:
true if this method is a bridge method.
-
getName
Returns the name of this method.- Returns:
- The name of this method
-
compareTo
- Specified by:
compareTo
in interfaceComparable<MethodInfo>
-
accessible
Description copied from class:ExecutableInfo
Attempts to callx.setAccessible(
and quietly ignores security exceptions.true )- Overrides:
accessible
in classExecutableInfo
- Returns:
- This object.
-