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 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> |
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> 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 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(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 |
invokeSuper()
Invokes the method that is instrumented by the returned instance by a super method invocation.
|
InstrumentedType |
prepare(InstrumentedType instrumentedType)
During the preparation phase of an implementation, implementations are eligible to adding fields or methods
to the currently instrumented type.
|
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(JavaInstance... javaInstance)
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 |
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 |
withAssigner(Assigner assigner,
Assigner.Typing typing)
Defines an assigner to be used for assigning values to the parameters of the invoked method.
|
MethodCall |
withField(String... fieldName)
Defines a method call which fetches a value from an existing field.
|
MethodCall |
withInstanceField(Class<?> type,
String name)
Defines a method call which fetches a value from an instance field.
|
MethodCall |
withInstanceField(TypeDescription typeDescription,
String name)
Defines a method call which fetches a value from an instance field.
|
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> 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> 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(MethodCall.MethodLocator methodLocator)
methodLocator
- The method locator to apply for locating the method to invoke given the instrumented
method.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 static MethodCall invokeSuper()
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(JavaInstance... javaInstance)
javaInstance
- 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 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 withInstanceField(Class<?> type, String name)
null
. The field itself is defined by this implementation.type
- The type of the field.name
- The name of the field.public MethodCall withInstanceField(TypeDescription typeDescription, String name)
null
. The field itself is defined by this implementation.typeDescription
- The type of the field.name
- The name of the field.public MethodCall withField(String... fieldName)
fieldName
- The name of the field.public MethodCall 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)
Implementation
ByteCodeAppender
that is emitted
on the call to
Implementation.appender(Implementation.Target)
call. On this method call, loaded type initializers can also be added to the instrumented type.prepare
in interface Implementation
instrumentedType
- The instrumented type that is the basis of the ongoing instrumentation.public ByteCodeAppender appender(Implementation.Target implementationTarget)
Implementation
appender
in interface Implementation
implementationTarget
- The target of the current implementation.Implementation.prepare(InstrumentedType)
.Copyright © 2014–2015. All rights reserved.