Class FixedValue
java.lang.Object
net.bytebuddy.implementation.FixedValue
- All Implemented Interfaces:
InstrumentedType.Prepareable, Implementation
- Direct Known Subclasses:
FixedValue.ForArgument, FixedValue.ForConstantValue, FixedValue.ForOriginType, FixedValue.ForThisValue, FixedValue.ForValue
This implementation returns a fixed value for a method. Other than the
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.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents 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 classA fixed value implementation that returns a method's argument.protected static classA fixed value implementation that represents its fixed value as a constant pool value or a byte code instruction.protected static enumA fixed value ofnull.protected static classA fixed value that appends the origin type of the instrumented type.protected static classA fixed value ofthis.protected static classA fixed value implementation that represents its fixed value as a static field of the instrumented class.Nested classes/interfaces inherited from interface Implementation
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.TargetNested classes/interfaces inherited from interface InstrumentedType.Prepareable
InstrumentedType.Prepareable.NoOp -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AssignerThe assigner that is used for assigning the fixed value to a method's return type.protected final Assigner.TypingIndicates if dynamic type castings should be attempted for incompatible assignments. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFixedValue(Assigner assigner, Assigner.Typing typing) Creates a new fixed value implementation. -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteCodeAppender.Sizeapply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod, TypeDescription.Generic typeDescription, StackManipulation stackManipulation) Blueprint method that for applying the actual implementation.argument(int index) Returns the argument at the specified index.static ImplementationReturns anullvalue from an instrumented method.Returns the origin type from an instrumented method.Other thanvalue(Object), this function will create a fixed value implementation that will always defined a field in the instrumented class.Other thanvalue(Object), this function will create a fixed value implementation that will always defined a field in the instrumented class.self()Returnsthisfrom an instrumented method.Returns a fixed value from any intercepted method.value(TypeDescription type) Returns the given type in form of a loaded type.value(ConstantValue constant) Returns the loaded version of the givenJavaConstant.value(JavaConstant constant) Returns the loaded version of the givenJavaConstant.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Implementation
appenderMethods inherited from interface InstrumentedType.Prepareable
prepare
-
Field Details
-
assigner
The assigner that is used for assigning the fixed value to a method's return type. -
typing
Indicates if dynamic type castings should be attempted for incompatible assignments.
-
-
Constructor Details
-
FixedValue
Creates a new fixed value implementation.- Parameters:
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.
-
-
Method Details
-
value
Returns a fixed value from any intercepted method. The fixed value is stored in the constant pool if this is possible. Specifically, an argument that is a
JavaConstant,TypeDescription, primitive,StringorClassvalue is stored in the constant pool. Since Java 7,MethodHandleas well asMethodTypereferences 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
IllegalAccessExceptionwill be thrown at runtime.- Parameters:
value- The fixed value to return from the method.- Returns:
- An implementation for the given
value. - See Also:
-
reference
Other thanvalue(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 givenvalueand 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.- Parameters:
value- The fixed value to be returned by methods that are instrumented by this implementation.- Returns:
- An implementation for the given
value.
-
reference
Other thanvalue(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 givenvalueand the value that is returned by instrumented methods. The field name can be explicitly determined.- Parameters:
value- The fixed value to be returned by methods that are instrumented by this implementation.name- The name of the field for storing the fixed value.- Returns:
- An implementation for the given
value.
-
value
Returns the given type in form of a loaded type. The value is loaded from the written class's constant pool.- Parameters:
type- The type to return from the method.- Returns:
- An implementation for the given
value.
-
value
Returns the loaded version of the givenJavaConstant. The value is loaded from the written class's constant pool.- Parameters:
constant- The type to return from the method.- Returns:
- An implementation for the given
value.
-
value
Returns the loaded version of the givenJavaConstant. The value is loaded from the written class's constant pool.- Parameters:
constant- The type to return from the method.- Returns:
- An implementation for the given
value.
-
argument
Returns the argument at the specified index.- Parameters:
index- The index of the argument to return.- Returns:
- An implementation of a method that returns the argument at the specified index.
-
self
Returnsthisfrom an instrumented method.- Returns:
- An implementation that returns
thisfrom a method.
-
nullValue
Returns anullvalue from an instrumented method.- Returns:
- An implementation that returns
nullfrom a method.
-
originType
Returns the origin type from an instrumented method.- Returns:
- An implementation that returns the origin type of the current instrumented type.
-
apply
protected ByteCodeAppender.Size apply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod, TypeDescription.Generic typeDescription, StackManipulation stackManipulation) Blueprint method that for applying the actual implementation.- Parameters:
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.typeDescription- A description of the type of the fixed value that is loaded by thevalueLoadingInstruction.stackManipulation- A stack manipulation that represents the loading of the fixed value onto the operand stack.- Returns:
- A representation of the stack and variable array sized that are required for this implementation.
-