Annotation Interface Origin
The origin annotation provides some meta information about the source method that is bound to this method where the binding is dependant of the parameter's type:
- If the annotated parameter is of type
Method
,Constructor
orjava.lang.reflect.Executable
, the parameter is assigned a reference to the method or constructor it instruments. If the reference is not assignable to the sort of the intercepted source, the target is not considered for binding. - If the annotated parameter is of type
Class
, the parameter is assigned a reference of the type of the instrumented type. - If the annotated parameter is of type
String
, the parameter is assigned a string with the value that would be returned by theMethod.toString()
method. - If the annotated parameter is a
int
type, it is assigned the intercepted method's modifiers. - If the annotated type is
java.lang.invoke.MethodHandle
, a handle of the intercepted method is injected. Ajava.lang.invoke.MethodHandle
is stored in a class's constant pool and does therefore not face the same runtime performance limitations as a (non-cached)Method
reference. Method handles are only supported for byte code versions starting from Java 7. - If the annotated type is
java.lang.invoke.MethodType
, a description of the intercepted method's type is injected. Method type descriptions are only supported for byte code versions starting from Java 7.
Any other parameter type will cause an IllegalStateException
.
Important: A method handle or method type reference can only be used if the referenced method's types are all visible
to the instrumented type or an IllegalAccessError
will be thrown at runtime.
Important: Don't confuse this annotation with Advice.Origin
annotation. This annotation
should be used only in combination with method delegation
(MethodDelegation.to(...)
).
For Advice
ASM visitor use alternative annotation from
net.bytebuddy.asm.Advice
package.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
A binder for binding parameters that are annotated withOrigin
. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionboolean
Determines if the value that is assigned by this annotation is cached.boolean
Determines if the method should be resolved by using anjava.security.AccessController
using the privileges of the generated class.
-
Element Details
-
cache
boolean cacheDetermines if the value that is assigned by this annotation is cached. For values that can be stored in the constant pool, this value is ignored as such values are cached implicitly. As a result, this value currently only affects caching ofMethod
instances.- Returns:
true
if the value for this parameter should be cached in astatic
field inside the instrumented class.
- Default:
- true
-
privileged
boolean privilegedDetermines if the method should be resolved by using anjava.security.AccessController
using the privileges of the generated class. Doing so requires the generation of an auxiliary class that implementsjava.security.PrivilegedExceptionAction
.- Returns:
true
if the class should be looked up using anjava.security.AccessController
.
- Default:
- false
-