Class MethodCallProxy
java.lang.Object
net.bytebuddy.implementation.auxiliary.MethodCallProxy
- All Implemented Interfaces:
AuxiliaryType
A method call proxy represents a class that is compiled against a particular method which can then be called whenever
either its
Callable.call()
or Runnable.run()
method is called where the method
call proxy implements both interfaces.
In order to do so, the method call proxy instances are constructed by providing all the necessary information for calling a particular method:
- If the target method is not
static
, the first argument should be an instance on which the method is called. - All arguments for the called method in the order in which they are required.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A stack manipulation that creates aMethodCallProxy
for a given method an pushes such an object onto the call stack.protected static enum
An implementation for a constructor of aMethodCallProxy
.protected static class
An implementation for a method of aMethodCallProxy
.protected static enum
A precomputed method graph that only displays the methods that are relevant for creating a method call proxy.Nested classes/interfaces inherited from interface net.bytebuddy.implementation.auxiliary.AuxiliaryType
AuxiliaryType.NamingStrategy, AuxiliaryType.SignatureRelevant
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Assigner
The assigner to use for invoking a bridge method target where the parameter and return types need to be assigned.private static final String
The prefix of the fields holding the original method invocation's arguments.private final boolean
Determines if the generated proxy should be serializableProxy.private final Implementation.SpecialMethodInvocation
The special method invocation to invoke from the auxiliary type.Fields inherited from interface net.bytebuddy.implementation.auxiliary.AuxiliaryType
DEFAULT_TYPE_MODIFIER
-
Constructor Summary
ConstructorsConstructorDescriptionMethodCallProxy
(Implementation.SpecialMethodInvocation specialMethodInvocation, boolean serializableProxy) Creates a new method call proxy for a given method and uses a default assigner for assigning the method's return value to either theCallable.call()
orRunnable.run()
method returns.MethodCallProxy
(Implementation.SpecialMethodInvocation specialMethodInvocation, boolean serializableProxy, Assigner assigner) Creates a new method call proxy for a given method. -
Method Summary
Modifier and TypeMethodDescriptionprivate static LinkedHashMap<String,
TypeDescription> extractFields
(MethodDescription methodDescription) Creates a linked hash map of field names to their types where each field represents a parameter of the method.private static String
fieldName
(int index) Creates a field name for a method parameter of a given index.Produces a suffix that gives this auxiliary type a stable name.make
(String auxiliaryTypeName, ClassFileVersion classFileVersion, MethodAccessorFactory methodAccessorFactory) Creates a new auxiliary type.
-
Field Details
-
FIELD_NAME_PREFIX
The prefix of the fields holding the original method invocation's arguments.- See Also:
-
specialMethodInvocation
The special method invocation to invoke from the auxiliary type. -
serializableProxy
private final boolean serializableProxyDetermines if the generated proxy should be serializableProxy. -
assigner
The assigner to use for invoking a bridge method target where the parameter and return types need to be assigned.
-
-
Constructor Details
-
MethodCallProxy
public MethodCallProxy(Implementation.SpecialMethodInvocation specialMethodInvocation, boolean serializableProxy) Creates a new method call proxy for a given method and uses a default assigner for assigning the method's return value to either theCallable.call()
orRunnable.run()
method returns.- Parameters:
specialMethodInvocation
- The special method invocation which should be invoked by this method call proxy.serializableProxy
- Determines if the generated proxy should be serializableProxy.
-
MethodCallProxy
public MethodCallProxy(Implementation.SpecialMethodInvocation specialMethodInvocation, boolean serializableProxy, Assigner assigner) Creates a new method call proxy for a given method.- Parameters:
specialMethodInvocation
- The special method invocation which should be invoked by this method call proxy.serializableProxy
- Determines if the generated proxy should be serializableProxy.assigner
- An assigner for assigning the target method's return value to either theCallable.call()
orRunnable.run()
} methods' return values.
-
-
Method Details
-
extractFields
private static LinkedHashMap<String,TypeDescription> extractFields(MethodDescription methodDescription) Creates a linked hash map of field names to their types where each field represents a parameter of the method.- Parameters:
methodDescription
- The method to extract into fields.- Returns:
- A map of fields in the order they need to be loaded onto the operand stack for invoking the original method, including a reference to the instance of the instrumented type that is invoked if applicable.
-
fieldName
Creates a field name for a method parameter of a given index.- Parameters:
index
- The index for which the field name is to be created.- Returns:
- The name for the given parameter.
-
getSuffix
Produces a suffix that gives this auxiliary type a stable name. A best effort is made that this suffix is unique.- Specified by:
getSuffix
in interfaceAuxiliaryType
- Returns:
- The suffix for this auxiliary type.
-
make
public DynamicType make(String auxiliaryTypeName, ClassFileVersion classFileVersion, MethodAccessorFactory methodAccessorFactory) Creates a new auxiliary type.- Specified by:
make
in interfaceAuxiliaryType
- Parameters:
auxiliaryTypeName
- The fully qualified binary name for this auxiliary type. The type should be in the same package than the instrumented type this auxiliary type is providing services to in order to allow package-private access.classFileVersion
- The class file version the auxiliary class should be written in.methodAccessorFactory
- A factory for accessor methods.- Returns:
- A dynamically created type representing this auxiliary type.
-