@HashCodeAndEqualsPlugin.Enhance public class MethodCall extends Object implements Implementation.Composable
Implementation
allows the invocation of a specified method while
providing explicit arguments to this method.Modifier and Type | Class and Description |
---|---|
protected class |
MethodCall.Appender
The appender being used to implement a
MethodCall . |
static interface |
MethodCall.ArgumentLoader
An argument loader is responsible for loading an argument for an invoked method
onto the operand stack.
|
static class |
MethodCall.FieldSetting
A
MethodCall that sets the call's result as the value of a field. |
protected static interface |
MethodCall.MethodInvoker
A method invoker is responsible for creating a method invocation that is to be applied by a
MethodCall . |
static interface |
MethodCall.MethodLocator
A method locator is responsible for identifying the method that is to be invoked
by a
MethodCall . |
protected static interface |
MethodCall.TargetHandler
A target handler is responsible for invoking a method for a
MethodCall . |
protected static interface |
MethodCall.TerminationHandler
A termination handler is responsible to handle the return value of a method that is invoked via a
MethodCall . |
static class |
MethodCall.WithoutSpecifiedTarget
Represents a
MethodCall that invokes a method without specifying
an invocation method. |
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Modifier and Type | Field and Description |
---|---|
protected List<MethodCall.ArgumentLoader.Factory> |
argumentLoaders
The argument loader to load arguments onto the operand stack in their application order.
|
protected Assigner |
assigner
The assigner to use.
|
protected MethodCall.MethodInvoker.Factory |
methodInvoker
The method invoker to use.
|
protected MethodCall.MethodLocator.Factory |
methodLocator
The method locator to use.
|
protected MethodCall.TargetHandler.Factory |
targetHandler
The target handler to use.
|
protected MethodCall.TerminationHandler.Factory |
terminationHandler
The termination handler to use.
|
protected Assigner.Typing |
typing
Indicates if dynamic type castings should be attempted for incompatible assignments.
|
Modifier | Constructor and Description |
---|---|
protected |
MethodCall(MethodCall.MethodLocator.Factory methodLocator,
MethodCall.TargetHandler.Factory targetHandler,
List<MethodCall.ArgumentLoader.Factory> argumentLoaders,
MethodCall.MethodInvoker.Factory methodInvoker,
MethodCall.TerminationHandler.Factory terminationHandler,
Assigner assigner,
Assigner.Typing typing)
Creates a new method call implementation.
|
Modifier and Type | Method and Description |
---|---|
Implementation.Composable |
andThen(Implementation.Composable implementation)
Appends the supplied composable implementation to this implementation.
|
Implementation |
andThen(Implementation implementation)
Appends the supplied implementation to this implementation.
|
ByteCodeAppender |
appender(Implementation.Target implementationTarget)
Creates a byte code appender that determines the implementation of the instrumented type's methods.
|
static Implementation.Composable |
call(Callable<?> callable)
Implements a method by invoking the provided
Callable . |
static MethodCall |
construct(Constructor<?> constructor)
Invokes the given constructor in order to create an instance.
|
static MethodCall |
construct(MethodDescription methodDescription)
Invokes the given constructor in order to create an instance.
|
static MethodCall.WithoutSpecifiedTarget |
invoke(Constructor<?> constructor)
Invokes the given constructor on the instance of the instrumented type.
|
static MethodCall.WithoutSpecifiedTarget |
invoke(ElementMatcher<? super MethodDescription> matcher)
Invokes a unique virtual method or constructor of the instrumented type that is matched by the specified matcher.
|
static MethodCall.WithoutSpecifiedTarget |
invoke(ElementMatcher<? super MethodDescription> matcher,
MethodGraph.Compiler methodGraphCompiler)
Invokes a unique virtual method or constructor of the instrumented type that is matched by the specified matcher.
|
static MethodCall.WithoutSpecifiedTarget |
invoke(Method method)
Invokes the given method.
|
static MethodCall.WithoutSpecifiedTarget |
invoke(MethodCall.MethodLocator.Factory methodLocator)
Invokes a method using the provided method locator.
|
static MethodCall.WithoutSpecifiedTarget |
invoke(MethodDescription methodDescription)
Invokes the given method.
|
static MethodCall.WithoutSpecifiedTarget |
invokeSelf()
Invokes the instrumented method recursively.
|
static MethodCall |
invokeSuper()
Invokes the instrumented method as a super method call on the instance itself.
|
InstrumentedType |
prepare(InstrumentedType instrumentedType)
Prepares a given instrumented type.
|
static Implementation.Composable |
run(Runnable runnable)
Implements a method by invoking the provided
Runnable . |
MethodCall.FieldSetting |
setsField(ElementMatcher<? super FieldDescription> matcher)
Sets the result of the method call as a value of the specified field.
|
MethodCall.FieldSetting |
setsField(Field field)
Sets the result of the method call as a value of the specified field.
|
MethodCall.FieldSetting |
setsField(FieldDescription fieldDescription)
Sets the result of the method call as a value of the specified field.
|
MethodCall |
with(EnumerationDescription... enumerationDescription)
Defines the given enumeration values to be provided as arguments to the invoked method where the values
are read from the enumeration class on demand.
|
MethodCall |
with(JavaConstant... javaConstant)
Defines the given Java instances to be provided as arguments to the invoked method where the given
instances are stored in the generated class's constant pool.
|
MethodCall |
with(List<? extends MethodCall.ArgumentLoader.Factory> argumentLoaders)
Defines a method call that resolves arguments by the supplied argument loader factories.
|
MethodCall |
with(MethodCall.ArgumentLoader.Factory... argumentLoader)
Defines a method call that resolves arguments by the supplied argument loader factories.
|
MethodCall |
with(Object... argument)
Defines a number of arguments to be handed to the method that is being invoked by this implementation.
|
MethodCall |
with(StackManipulation stackManipulation,
Type type)
Adds a stack manipulation as an assignment to the next parameter.
|
MethodCall |
with(StackManipulation stackManipulation,
TypeDefinition typeDefinition)
Adds a stack manipulation as an assignment to the next parameter.
|
MethodCall |
with(TypeDescription... typeDescription)
Defines the given types to be provided as arguments to the invoked method where the represented types
are stored in the generated class's constant pool.
|
MethodCall |
withAllArguments()
Adds all arguments of the instrumented method as arguments to the invoked method to this method call.
|
MethodCall |
withArgument(int... index)
Defines a number of arguments of the instrumented method by their parameter indices to be handed
to the invoked method as an argument.
|
MethodCall |
withArgumentArray()
Adds an array containing all arguments of the instrumented method to this method call.
|
MethodCall |
withArgumentArrayElements(int index)
Creates a method call where the parameter with
index is expected to be an array and where each element of the array
is expected to represent an argument for the method being invoked. |
MethodCall |
withArgumentArrayElements(int index,
int size)
Creates a method call where the parameter with
index is expected to be an array and where size elements are loaded
from the array as arguments for the invoked method. |
MethodCall |
withArgumentArrayElements(int index,
int start,
int size)
Creates a method call where the parameter with
index is expected to be an array and where size elements are loaded
from the array as arguments for the invoked method. |
Implementation.Composable |
withAssigner(Assigner assigner,
Assigner.Typing typing)
Defines an assigner to be used for assigning values to the parameters of the invoked method.
|
MethodCall |
withField(FieldLocator.Factory fieldLocatorFactory,
String... name)
Defines a method call which fetches a value from a list of existing fields.
|
MethodCall |
withField(String... name)
Defines a method call which fetches a value from a list of existing fields.
|
MethodCall |
withMethodCall(MethodCall methodCall)
Defines a method call which fetches a value from a method call.
|
MethodCall |
withOwnType()
Assigns the
Class value of the instrumented type. |
MethodCall |
withReference(Object... argument)
Defines a number of arguments to be handed to the method that is being invoked by this implementation.
|
MethodCall |
withThis()
Assigns the
this reference to the next parameter. |
protected final MethodCall.MethodLocator.Factory methodLocator
protected final MethodCall.TargetHandler.Factory targetHandler
protected final List<MethodCall.ArgumentLoader.Factory> argumentLoaders
protected final MethodCall.MethodInvoker.Factory methodInvoker
protected final MethodCall.TerminationHandler.Factory terminationHandler
protected final Assigner assigner
protected final Assigner.Typing typing
protected MethodCall(MethodCall.MethodLocator.Factory methodLocator, MethodCall.TargetHandler.Factory targetHandler, List<MethodCall.ArgumentLoader.Factory> argumentLoaders, MethodCall.MethodInvoker.Factory methodInvoker, MethodCall.TerminationHandler.Factory terminationHandler, Assigner assigner, Assigner.Typing typing)
methodLocator
- The method locator to use.targetHandler
- The target handler to use.argumentLoaders
- The argument loader to load arguments onto the operand stack in their application order.methodInvoker
- The method invoker to use.terminationHandler
- The termination handler to use.assigner
- The assigner to use.typing
- Indicates if dynamic type castings should be attempted for incompatible assignments.public static MethodCall.WithoutSpecifiedTarget invoke(Method method)
static
.method
- The method to invoke.public static MethodCall.WithoutSpecifiedTarget invoke(Constructor<?> constructor)
Invokes the given constructor on the instance of the instrumented type.
Important: A constructor invocation can only be applied within another constructor to invoke the super constructor or an auxiliary
constructor. To construct a new instance, use construct(Constructor)
.
constructor
- The constructor to invoke.public static MethodCall.WithoutSpecifiedTarget invoke(MethodDescription methodDescription)
Invokes the given method. If the method description describes a constructor, it is automatically invoked as
a special method invocation on the instance of the instrumented type. The same is true for private
methods. Finally, static
methods are invoked statically.
Important: A constructor invocation can only be applied within another constructor to invoke the super constructor or an auxiliary
constructor. To construct a new instance, use construct(MethodDescription)
.
methodDescription
- The method to invoke.public static MethodCall.WithoutSpecifiedTarget invoke(ElementMatcher<? super MethodDescription> matcher)
matcher
- The matcher to identify the method to invoke.public static MethodCall.WithoutSpecifiedTarget invoke(ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler)
matcher
- The matcher to identify the method to invoke.methodGraphCompiler
- The method graph compiler to use.public static MethodCall.WithoutSpecifiedTarget invoke(MethodCall.MethodLocator.Factory methodLocator)
methodLocator
- The method locator to apply for locating the method to invoke given the instrumented
method.public static MethodCall.WithoutSpecifiedTarget invokeSelf()
StackOverflowError
due to
infinite recursion.public static MethodCall invokeSuper()
invokeSelf().onSuper()
.public static Implementation.Composable call(Callable<?> callable)
Callable
. The return value of the provided object is casted to the implemented method's
return type, if necessary.callable
- The callable to invoke when a method is intercepted.public static Implementation.Composable run(Runnable runnable)
Runnable
. If the instrumented method returns a value, null
is returned.runnable
- The runnable to invoke when a method is intercepted.public static MethodCall construct(Constructor<?> constructor)
constructor
- The constructor to invoke.public static MethodCall construct(MethodDescription methodDescription)
methodDescription
- A description of the constructor to invoke.public MethodCall with(Object... argument)
String
or null
are loaded
directly onto the operand stack. This might corrupt referential identity for these values. Any other values
are stored within a static
field that is added to the instrumented type.argument
- The arguments to provide to the method that is being called in their order.public MethodCall with(TypeDescription... typeDescription)
typeDescription
- The type descriptions to provide as arguments.public MethodCall with(EnumerationDescription... enumerationDescription)
enumerationDescription
- The enumeration descriptions to provide as arguments.public MethodCall with(JavaConstant... javaConstant)
javaConstant
- The Java instances to provide as arguments.public MethodCall withReference(Object... argument)
null
value is not stored within a field.argument
- The arguments to provide to the method that is being called in their order.public MethodCall withArgument(int... index)
index
- The parameter indices of the instrumented method to be handed to the invoked method as an
argument in their order. The indices are zero-based.public MethodCall withAllArguments()
public MethodCall withArgumentArray()
public MethodCall withArgumentArrayElements(int index)
Creates a method call where the parameter with index
is expected to be an array and where each element of the array
is expected to represent an argument for the method being invoked.
Note: This is typically used in combination with dynamic type assignments which is activated via
withAssigner(Assigner, Assigner.Typing)
using a Assigner.Typing#DYNAMIC
.
index
- The index of the parameter.size
elements from the array handed to the instrumented method as argument index
.public MethodCall withArgumentArrayElements(int index, int size)
Creates a method call where the parameter with index
is expected to be an array and where size
elements are loaded
from the array as arguments for the invoked method.
Note: This is typically used in combination with dynamic type assignments which is activated via
withAssigner(Assigner, Assigner.Typing)
using a Assigner.Typing#DYNAMIC
.
index
- The index of the parameter.size
- The amount of elements to load from the array.size
elements from the array handed to the instrumented method as argument index
.public MethodCall withArgumentArrayElements(int index, int start, int size)
Creates a method call where the parameter with index
is expected to be an array and where size
elements are loaded
from the array as arguments for the invoked method. The first element is loaded from index start
.
Note: This is typically used in combination with dynamic type assignments which is activated via
withAssigner(Assigner, Assigner.Typing)
using a Assigner.Typing#DYNAMIC
.
index
- The index of the parameter.start
- The first array index to consider.size
- The amount of elements to load from the array with increasing index from start
.size
elements from the array handed to the instrumented method as argument index
.public MethodCall withThis()
this
reference to the next parameter.this
reference
of the instance of the intercepted method.public MethodCall withOwnType()
Class
value of the instrumented type.Class
value of the instrumented type.public MethodCall withField(String... name)
name
- The names of the fields.public MethodCall withField(FieldLocator.Factory fieldLocatorFactory, String... name)
fieldLocatorFactory
- The field locator factory to use.name
- The names of the fields.public MethodCall withMethodCall(MethodCall methodCall)
methodCall
- The method call to use.public MethodCall with(StackManipulation stackManipulation, Type type)
stackManipulation
- The stack manipulation loading the value.type
- The type of the argument being loaded.public MethodCall with(StackManipulation stackManipulation, TypeDefinition typeDefinition)
stackManipulation
- The stack manipulation loading the value.typeDefinition
- The type of the argument being loaded.public MethodCall with(MethodCall.ArgumentLoader.Factory... argumentLoader)
argumentLoader
- The argument loaders to apply to the subsequent arguments of thepublic MethodCall with(List<? extends MethodCall.ArgumentLoader.Factory> argumentLoaders)
argumentLoaders
- The argument loaders to apply to the subsequent arguments of thepublic MethodCall.FieldSetting setsField(Field field)
void
, this instrumentation must be chained with another instrumentation.field
- The field to set.public MethodCall.FieldSetting setsField(FieldDescription fieldDescription)
void
, this instrumentation must be chained with another instrumentation.fieldDescription
- The field to set.public MethodCall.FieldSetting setsField(ElementMatcher<? super FieldDescription> matcher)
void
, this instrumentation must be chained with another instrumentation.matcher
- A matcher that locates a field in the instrumented type's hierarchy.public Implementation.Composable withAssigner(Assigner assigner, Assigner.Typing typing)
andThen(Implementation)
such
that a return value of this method call is discarded.assigner
- The assigner to use.typing
- Indicates if dynamic type castings should be attempted for incompatible assignments.public Implementation andThen(Implementation implementation)
andThen
in interface Implementation.Composable
implementation
- The subsequent implementation.public Implementation.Composable andThen(Implementation.Composable implementation)
andThen
in interface Implementation.Composable
implementation
- The subsequent composable implementation.public InstrumentedType prepare(InstrumentedType instrumentedType)
prepare
in interface InstrumentedType.Prepareable
instrumentedType
- The instrumented type in its current form.public ByteCodeAppender appender(Implementation.Target implementationTarget)
appender
in interface Implementation
implementationTarget
- The target of the current implementation.InstrumentedType.Prepareable.prepare(InstrumentedType)
.Copyright © 2014–2020. All rights reserved.