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 . |
protected static interface |
MethodCall.ArgumentLoader
An argument loader is responsible for loading an argument for an invoked method
onto the operand stack.
|
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 class |
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 |
methodInvoker
The method invoker to use.
|
protected MethodCall.MethodLocator |
methodLocator
The method locator to use.
|
protected MethodCall.TargetHandler |
targetHandler
The target handler to use.
|
protected MethodCall.TerminationHandler |
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 methodLocator,
MethodCall.TargetHandler targetHandler,
List<MethodCall.ArgumentLoader.Factory> argumentLoaders,
MethodCall.MethodInvoker methodInvoker,
MethodCall.TerminationHandler terminationHandler,
Assigner assigner,
Assigner.Typing typing)
Creates a new method call implementation.
|
Modifier and Type | Method and Description |
---|---|
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.
|
boolean |
equals(Object other) |
int |
hashCode() |
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 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 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 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 . |
String |
toString() |
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(Object... argument)
Defines a number of arguments to be handed to the method that is being invoked by this implementation.
|
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 |
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 |
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 methodLocator
protected final MethodCall.TargetHandler targetHandler
protected final List<MethodCall.ArgumentLoader.Factory> argumentLoaders
protected final MethodCall.MethodInvoker methodInvoker
protected final MethodCall.TerminationHandler terminationHandler
protected final Assigner assigner
protected final Assigner.Typing typing
protected MethodCall(MethodCall.MethodLocator methodLocator, MethodCall.TargetHandler targetHandler, List<MethodCall.ArgumentLoader.Factory> argumentLoaders, MethodCall.MethodInvoker methodInvoker, MethodCall.TerminationHandler 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)
constructor
- The constructor to invoke.public static MethodCall.WithoutSpecifiedTarget invoke(MethodDescription methodDescription)
private
methods. Finally, static
methods are invoked statically.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 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 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 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)
Implementation.Composable
andThen
in interface Implementation.Composable
implementation
- The subsequent implementation.public InstrumentedType prepare(InstrumentedType instrumentedType)
InstrumentedType.Prepareable
prepare
in interface InstrumentedType.Prepareable
instrumentedType
- The instrumented type in its current form.public ByteCodeAppender appender(Implementation.Target implementationTarget)
Implementation
appender
in interface Implementation
implementationTarget
- The target of the current implementation.InstrumentedType.Prepareable.prepare(InstrumentedType)
.Copyright © 2014–2017. All rights reserved.