@HashCodeAndEqualsPlugin.Enhance public abstract static class Advice.AssignReturned extends Object implements Advice.PostProcessor
A post processor that uses the return value of an advice method to define values for fields, arguments, the instrumented method's return value or the exception being thrown. This post processor allows for the assignment of values from advice methods that use delegation. When inlining advice code, it is recommended to assign values directly to annotated parameters.
Important: This post processor is not registered by default but requires explicit registration via
WithCustomMapping#with(PostProcessor.Factory)
.
Important: Assignment exceptions will not be handled by a suppression handler but will be propagated.
Modifier and Type | Class and Description |
---|---|
static interface |
Advice.AssignReturned.AsScalar
Indicates that the advice method's return value is to be treated as a scalar value also if it is
of an array type.
|
static class |
Advice.AssignReturned.Factory
A factory to create a
Advice.AssignReturned post processor. |
protected static class |
Advice.AssignReturned.ForArray
A post processor implementation of
Advice.AssignReturned that works on the value of an array. |
protected static class |
Advice.AssignReturned.ForScalar
A post processor implementation of
Advice.AssignReturned that uses the returned value as such. |
static interface |
Advice.AssignReturned.Handler
A handler for an
Advice.AssignReturned post processor to assign a value that was returned by
advice to a value of the instrumented method. |
protected static class |
Advice.AssignReturned.NullCheck
A stack manipulation that applies a null-check on the returned value which indicates if an assignment
should be skipped, if discovered.
|
static interface |
Advice.AssignReturned.ToAllArguments
Assigns the advice method's return value as an array to a number of arguments which are returned as an array where
each element assigns a single value with the same index as the instrumented method's parameter.
|
static interface |
Advice.AssignReturned.ToArguments
Assigns the advice method's return value to an argument of the instrumented method of the given index.
|
static interface |
Advice.AssignReturned.ToFields
Assigns the advice method's return value to a given field.
|
static interface |
Advice.AssignReturned.ToReturned
Assigns the advice method's return value to the instrumented method's return value.
|
static interface |
Advice.AssignReturned.ToThis
Assigns the advice method's return value to the
this reference of the instrumented method. |
static interface |
Advice.AssignReturned.ToThrown
Assigns the advice method's return value to the instrumented method's return value.
|
Advice.PostProcessor.Compound, Advice.PostProcessor.NoOp
Modifier and Type | Field and Description |
---|---|
protected boolean |
exit
true if this post processor is used within exit advice. |
static int |
NO_INDEX
Indicates that a value is not assigned from an array but as a scalar value.
|
protected TypeDescription.Generic |
type
The advice method's return type.
|
Modifier | Constructor and Description |
---|---|
protected |
AssignReturned(TypeDescription.Generic type,
boolean exit)
Creates a new post processor for assigning an advice method's return value.
|
Modifier and Type | Method and Description |
---|---|
protected abstract Collection<Advice.AssignReturned.Handler> |
getHandlers()
Returns a collection of all handlers to apply.
|
protected abstract TypeDescription.Generic |
getType()
Returns the assigned type that is handled by any handler.
|
StackManipulation |
resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
Assigner assigner,
Advice.ArgumentHandler argumentHandler)
Resolves this post processor for a given instrumented method.
|
protected abstract StackManipulation |
toLoadInstruction(Advice.AssignReturned.Handler handler,
int offset)
Creates a load instruction for the given handler.
|
public static final int NO_INDEX
protected final TypeDescription.Generic type
protected final boolean exit
true
if this post processor is used within exit advice.protected AssignReturned(TypeDescription.Generic type, boolean exit)
type
- The advice method's return type.exit
- true
if this post processor is used within exit advice.public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler)
resolve
in interface Advice.PostProcessor
instrumentedType
- The instrumented type.instrumentedMethod
- The instrumented method.assigner
- The assigner to use.argumentHandler
- The argument handler for the instrumented method.protected abstract TypeDescription.Generic getType()
protected abstract Collection<Advice.AssignReturned.Handler> getHandlers()
protected abstract StackManipulation toLoadInstruction(Advice.AssignReturned.Handler handler, int offset)
handler
- The handler for which to apply a load instruction.offset
- The offset of the value that is returned by the advice method.Copyright © 2014–2021. All rights reserved.