Class MethodFinder
java.lang.Object
madkit.reflection.MethodFinder
Utilities for finding method references in Agent classes. Provides methods to find and
retrieve methods from agent classes, including private and inherited methods.
- Since:
- 6.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Method
getMethodFromTypes
(Class<?> agentClass, String methodName, Class<?>... parameterTypes) Returns the agent's method namedmethodName
considering a given agentClass.static Method
getMethodOn
(Class<?> agentClass, String methodName, Object... argsSample) Returns the agent's method namedmethodName
considering a given agentClass and a sample of the arguments which could be passed to it.
-
Method Details
-
getMethodFromTypes
public static Method getMethodFromTypes(Class<?> agentClass, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException Returns the agent's method namedmethodName
considering a given agentClass. This also works for private and inherited methods.- Parameters:
agentClass
- the class wherein the search has to be startedmethodName
- the name of the methodparameterTypes
- the parameter types of the targeted method- Returns:
- the agent's method named
methodName
- Throws:
NoSuchMethodException
- if the method cannot be found
-
getMethodOn
public static Method getMethodOn(Class<?> agentClass, String methodName, Object... argsSample) throws NoSuchMethodException Returns the agent's method namedmethodName
considering a given agentClass and a sample of the arguments which could be passed to it. The purpose of this method is restricted to a limited number of use cases sincegetMethodFromTypes(Class, String, Class...)
should be preferred if the exact signature of the searched method is known. A typical use case of this method is when the only information available is the arguments which are passed, for instance when overriding theActivator.execute(Object...)
method and the like inActivator
subclasses. This also works for private and inherited methods.- Parameters:
agentClass
- the class wherein the search has to be mademethodName
- the name of the methodargsSample
- a sample of the args which can be passed to the method- Returns:
- the agent's method named
methodName
- Throws:
NoSuchMethodException
- if a matching method cannot be found
-