public abstract class FixedValue extends Object implements Implementation
StubMethod
implementation, this implementation allows
to determine a specific value which must be assignable to the returning value of any instrumented method. Otherwise,
an exception will be thrown.Modifier and Type | Class and Description |
---|---|
static interface |
FixedValue.AssignerConfigurable
Represents a fixed value implementation that is using a default assigner for attempting to assign
the fixed value to the return type of the instrumented method.
|
protected static class |
FixedValue.ForNullValue
A fixed value of
null . |
protected static class |
FixedValue.ForOriginType
A fixed value that appends the origin type of the instrumented type.
|
protected static class |
FixedValue.ForPoolValue
A fixed value implementation that represents its fixed value as a value that is written to the instrumented
class's constant pool.
|
protected static class |
FixedValue.ForStaticField
A fixed value implementation that represents its fixed value as a static field of the instrumented class.
|
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Modifier and Type | Field and Description |
---|---|
protected Assigner |
assigner
The assigner that is used for assigning the fixed value to a method's return type.
|
protected Assigner.Typing |
typing
Indicates if dynamic type castings should be attempted for incompatible assignments.
|
Modifier | Constructor and Description |
---|---|
protected |
FixedValue(Assigner assigner,
Assigner.Typing typing)
Creates a new fixed value implementation.
|
Modifier and Type | Method and Description |
---|---|
protected ByteCodeAppender.Size |
apply(MethodVisitor methodVisitor,
Implementation.Context implementationContext,
MethodDescription instrumentedMethod,
TypeDescription.Generic fixedValueType,
StackManipulation valueLoadingInstruction)
Blueprint method that for applying the actual implementation.
|
boolean |
equals(Object other) |
int |
hashCode() |
static Implementation |
nullValue()
Returns a null value from an instrumented method.
|
static FixedValue.AssignerConfigurable |
originType()
Returns the origin type from an instrumented method.
|
static FixedValue.AssignerConfigurable |
reference(Object fixedValue)
Other than
value(Object) , this function
will create a fixed value implementation that will always defined a field in the instrumented class. |
static FixedValue.AssignerConfigurable |
reference(Object fixedValue,
String fieldName)
Other than
value(Object) , this function
will create a fixed value implementation that will always defined a field in the instrumented class. |
static FixedValue.AssignerConfigurable |
value(JavaInstance fixedValue)
Returns the loaded version of the given
JavaInstance . |
static FixedValue.AssignerConfigurable |
value(Object fixedValue)
Returns a fixed value from any intercepted method.
|
static FixedValue.AssignerConfigurable |
value(TypeDescription fixedValue)
Returns the given type in form of a loaded type.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
appender
prepare
protected final Assigner assigner
protected final Assigner.Typing typing
protected FixedValue(Assigner assigner, Assigner.Typing typing)
assigner
- The assigner to use for assigning the fixed value to the return type of the instrumented value.typing
- Indicates if dynamic type castings should be attempted for incompatible assignments.public static FixedValue.AssignerConfigurable value(Object fixedValue)
Returns a fixed value from any intercepted method. The fixed value is stored in the constant pool if this is possible.
Java is capable of storing any primitive value, String
values and Class
references in the constant pool.
Since Java 7, MethodHandle
as well as MethodType
references are also supported. Alternatively, the fixed
value is stored in a static field.
When a value is stored in the class's constant pool, its identity is lost. If an object's identity is important, the
reference(Object)
method should be used instead.
Important: When supplying a method handle or a method type, all types that are implied must be visible to the instrumented
type or an IllegalAccessException
will be thrown at runtime.
fixedValue
- The fixed value to return from the method.fixedValue
.public static FixedValue.AssignerConfigurable reference(Object fixedValue)
value(Object)
, this function
will create a fixed value implementation that will always defined a field in the instrumented class. As a result,
object identity will be preserved between the given fixedValue
and the value that is returned by
instrumented methods. The field name can be explicitly determined. The field name is generated from the fixed value's
hash code.fixedValue
- The fixed value to be returned by methods that are instrumented by this implementation.fixedValue
.public static FixedValue.AssignerConfigurable reference(Object fixedValue, String fieldName)
value(Object)
, this function
will create a fixed value implementation that will always defined a field in the instrumented class. As a result,
object identity will be preserved between the given fixedValue
and the value that is returned by
instrumented methods. The field name can be explicitly determined.fixedValue
- The fixed value to be returned by methods that are instrumented by this implementation.fieldName
- The name of the field for storing the fixed value.fixedValue
.public static FixedValue.AssignerConfigurable value(TypeDescription fixedValue)
fixedValue
- The type to return from the method.fixedValue
.public static FixedValue.AssignerConfigurable value(JavaInstance fixedValue)
JavaInstance
. The value is loaded from the written class's constant pool.fixedValue
- The type to return from the method.fixedValue
.public static Implementation nullValue()
null
from a method.public static FixedValue.AssignerConfigurable originType()
protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod, TypeDescription.Generic fixedValueType, StackManipulation valueLoadingInstruction)
methodVisitor
- The method visitor to which the implementation is applied to.implementationContext
- The implementation context for the given implementation.instrumentedMethod
- The instrumented method that is target of the implementation.fixedValueType
- A description of the type of the fixed value that is loaded by the
valueLoadingInstruction
.valueLoadingInstruction
- A stack manipulation that represents the loading of the fixed value onto the
operand stack.Copyright © 2014–2016. All rights reserved.