public class DefaultMethodCall extends Object implements Instrumentation
Instrumentation
invokes a default method for the methods it instruments.
A default method is potentially ambiguous if a method of identical signature is defined in several interfaces.
For this reason, this instrumentation allows for the specification of prioritized interfaces whose default
methods, if a method of equivalent signature is defined for a specific interface. All prioritized interfaces are
searched for default methods in the order of their specification. If no prioritized interface defines a default method
of equivalent signature to the given instrumented method, any non-prioritized interface is searched for a suitable
default method. If exactly one of those interfaces defines a suitable default method, this method is invoked.
If no method or more than one method is identified as a suitable default method, an exception is thrown.
When it comes to default methods, the Java programming language specifies stronger requirements for the legitimacy of invoking a default method than the Java runtime. The Java compiler requires a method to be the most specific method in its defining type's type hierarchy, i.e. the method must not be overridden by another interface or class type. Additionally, the method must be invokable from an interface type which is directly implemented by the instrumented type. The Java runtime only requires the second condition to be fulfilled which is why this instrumentation only checks the later condition, as well.
Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultMethodCall.Appender
The appender for implementing a
DefaultMethodCall . |
Instrumentation.Compound, Instrumentation.Context, Instrumentation.ForAbstractMethod, Instrumentation.Simple, Instrumentation.SpecialMethodInvocation, Instrumentation.Target
Modifier | Constructor and Description |
---|---|
protected |
DefaultMethodCall(List<TypeDescription> prioritizedInterfaces)
Creates a new
DefaultMethodCall instrumentation for a given list of
prioritized interfaces. |
Modifier and Type | Method and Description |
---|---|
ByteCodeAppender |
appender(Instrumentation.Target instrumentationTarget)
Creates a byte code appender that determines the implementation of the instrumented type's methods.
|
boolean |
equals(Object other) |
int |
hashCode() |
InstrumentedType |
prepare(InstrumentedType instrumentedType)
During the preparation phase of an instrumentation, implementations are eligible to adding fields or methods
to the currently instrumented type.
|
static Instrumentation |
prioritize(Class<?>... prioritizedInterface)
Creates a
DefaultMethodCall instrumentation which searches the given list
of interface types for a suitable default method in their order. |
static Instrumentation |
prioritize(TypeDescription... prioritizedInterface)
Creates a
DefaultMethodCall instrumentation which searches the given list
of interface types for a suitable default method in their order. |
String |
toString() |
static Instrumentation |
unambiguousOnly()
Creates a
DefaultMethodCall instrumentation without prioritizing any
interface. |
protected DefaultMethodCall(List<TypeDescription> prioritizedInterfaces)
DefaultMethodCall
instrumentation for a given list of
prioritized interfaces.prioritizedInterfaces
- A list of prioritized interfaces in the order in which a method should be attempted to
be called.public static Instrumentation prioritize(Class<?>... prioritizedInterface)
DefaultMethodCall
instrumentation which searches the given list
of interface types for a suitable default method in their order. If no such prioritized interface is suitable,
because it is either not defined on the instrumented type or because it does not define a suitable default method,
any remaining interface is searched for a suitable default method. If no or more than one method defines a
suitable default method, an exception is thrown.prioritizedInterface
- A list of prioritized default method interfaces in their prioritization order.public static Instrumentation prioritize(TypeDescription... prioritizedInterface)
DefaultMethodCall
instrumentation which searches the given list
of interface types for a suitable default method in their order. If no such prioritized interface is suitable,
because it is either not defined on the instrumented type or because it does not define a suitable default method,
any remaining interface is searched for a suitable default method. If no or more than one method defines a
suitable default method, an exception is thrown.prioritizedInterface
- A list of prioritized default method interfaces in their prioritization order.public static Instrumentation unambiguousOnly()
DefaultMethodCall
instrumentation without prioritizing any
interface. Instead, any interface that is defined for a given type is searched for a suitable default method. If
exactly one interface defines a suitable default method, this method is invoked from the instrumented method.
Otherwise, an exception is thrown.public InstrumentedType prepare(InstrumentedType instrumentedType)
Instrumentation
ByteCodeAppender
that is emitted
on the call to
Instrumentation.appender(net.bytebuddy.instrumentation.Instrumentation.Target)
call. On this method call, loaded type initializers can also be added to the instrumented type.prepare
in interface Instrumentation
instrumentedType
- The instrumented type that is the basis of the ongoing instrumentation.public ByteCodeAppender appender(Instrumentation.Target instrumentationTarget)
Instrumentation
appender
in interface Instrumentation
instrumentationTarget
- The target of the current instrumentation.Instrumentation.prepare(net.bytebuddy.instrumentation.type.InstrumentedType)
.Copyright © 2014–2015. All rights reserved.