Top Description Inners Fields Constructors Methods
org.easymock.bytebuddy.implementation

public Class DefaultMethodCall

extends Object
implements Implementation
Class Inheritance
All Implemented Interfaces
org.easymock.bytebuddy.implementation.Implementation, org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable
Annotations
@Enhance
Imports
org.easymock.bytebuddy.build.HashCodeAndEqualsPlugin, org.easymock.bytebuddy.description.method.MethodDescription, org.easymock.bytebuddy.description.type.TypeDescription, .TypeList, org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType, org.easymock.bytebuddy.implementation.bytecode.ByteCodeAppender, .StackManipulation, org.easymock.bytebuddy.implementation.bytecode.member.MethodReturn, .MethodVariableAccess, org.easymock.bytebuddy.jar.asm.MethodVisitor, java.util.*

This Implementation 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 implementation 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 implementation only checks the later condition, as well.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private final List<TypeDescription>
prioritizedInterfaces

A list of prioritized interfaces in the order in which a method should be attempted to be called.

Constructor Summary

AccessConstructor and Description
protected
DefaultMethodCall(List<TypeDescription>
A list of prioritized interfaces in the order in which a method should be attempted to be called.
prioritizedInterfaces
)

Creates a new org.easymock.bytebuddy.implementation.DefaultMethodCall implementation for a given list of prioritized interfaces.

Method Summary

Modifier and TypeMethod and Description
public ByteCodeAppender
appender(Implementation.Target
The target of the current implementation.
implementationTarget
)

Implements org.easymock.bytebuddy.implementation.Implementation.appender.

Creates a byte code appender that determines the implementation of the instrumented type's methods.
private List<TypeDescription>

Returns:

A list of prioritized interfaces that are additionally implemented by the given type.
filterRelevant
(TypeDescription
The instrumented type for which the prioritized interfaces are to be filtered.
typeDescription
)

Filters the relevant prioritized interfaces for a given type, i.e. finds the types that are directly declared on a given instrumented type.

public InstrumentedType
prepare(InstrumentedType
The instrumented type in its current form.
instrumentedType
)

Implements org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable.prepare.

Prepares a given instrumented type.
public static Implementation

Returns:

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.
prioritize
(Class<?>...
A list of prioritized default method interfaces in their prioritization order.
prioritizedInterface
)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation which searches the given list of interface types for a suitable default method in their order.

public static Implementation

Returns:

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.
prioritize
(Iterable<? extends Class<?>>
A list of prioritized default method interfaces in their prioritization order.
prioritizedInterfaces
)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation which searches the given list of interface types for a suitable default method in their order.

public static Implementation

Returns:

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.
prioritize
(TypeDescription...
A list of prioritized default method interfaces in their prioritization order.
prioritizedInterface
)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation which searches the given list of interface types for a suitable default method in their order.

public static Implementation

Returns:

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.
prioritize
(Collection<? extends TypeDescription>
A collection of prioritized default method interfaces in their prioritization order.
prioritizedInterfaces
)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation which searches the given list of interface types for a suitable default method in their order.

public static Implementation

Returns:

An implementation which calls an instrumented method's compatible default method if such a method is unambiguous.
unambiguousOnly
()

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation without prioritizing any interface.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

prioritizedInterfacesback to summary
private final List<TypeDescription> prioritizedInterfaces

A list of prioritized interfaces in the order in which a method should be attempted to be called.

Constructor Detail

DefaultMethodCallback to summary
protected DefaultMethodCall(List<TypeDescription> prioritizedInterfaces)

Creates a new org.easymock.bytebuddy.implementation.DefaultMethodCall implementation for a given list of prioritized interfaces.

Parameters
prioritizedInterfaces:List<TypeDescription>

A list of prioritized interfaces in the order in which a method should be attempted to be called.

Method Detail

appenderback to summary
public ByteCodeAppender appender(Implementation.Target implementationTarget)

Implements org.easymock.bytebuddy.implementation.Implementation.appender.

Doc from org.easymock.bytebuddy.implementation.Implementation.appender.

Creates a byte code appender that determines the implementation of the instrumented type's methods.

Parameters
implementationTarget:Implementation.Target

The target of the current implementation.

Returns:ByteCodeAppender

A byte code appender for implementing methods delegated to this implementation. This byte code appender is also responsible for handling methods that were added by this implementation on the call to Implementation#prepare(InstrumentedType).

filterRelevantback to summary
private List<TypeDescription> filterRelevant(TypeDescription typeDescription)

Filters the relevant prioritized interfaces for a given type, i.e. finds the types that are directly declared on a given instrumented type.

Parameters
typeDescription:TypeDescription

The instrumented type for which the prioritized interfaces are to be filtered.

Returns:List<TypeDescription>

A list of prioritized interfaces that are additionally implemented by the given type.

prepareback to summary
public InstrumentedType prepare(InstrumentedType instrumentedType)

Implements org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable.prepare.

Doc from org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable.prepare.

Prepares a given instrumented type.

Parameters
instrumentedType:InstrumentedType

The instrumented type in its current form.

Returns:InstrumentedType

The prepared instrumented type.

prioritizeback to summary
public static Implementation prioritize(Class<?>... prioritizedInterface)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation 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.

Parameters
prioritizedInterface:Class<?>[]

A list of prioritized default method interfaces in their prioritization order.

Returns:Implementation

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.

prioritizeback to summary
public static Implementation prioritize(Iterable<? extends Class<?>> prioritizedInterfaces)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation 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.

Parameters
prioritizedInterfaces:Iterable<? extends Class<?>>

A list of prioritized default method interfaces in their prioritization order.

Returns:Implementation

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.

prioritizeback to summary
public static Implementation prioritize(TypeDescription... prioritizedInterface)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation 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.

Parameters
prioritizedInterface:TypeDescription[]

A list of prioritized default method interfaces in their prioritization order.

Returns:Implementation

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.

prioritizeback to summary
public static Implementation prioritize(Collection<? extends TypeDescription> prioritizedInterfaces)

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation 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.

Parameters
prioritizedInterfaces:Collection<? extends TypeDescription>

A collection of prioritized default method interfaces in their prioritization order.

Returns:Implementation

An implementation which calls an instrumented method's compatible default method that considers the given interfaces to be prioritized in their order.

unambiguousOnlyback to summary
public static Implementation unambiguousOnly()

Creates a org.easymock.bytebuddy.implementation.DefaultMethodCall implementation 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.

Returns:Implementation

An implementation which calls an instrumented method's compatible default method if such a method is unambiguous.

org.easymock.bytebuddy.implementation back to summary

protected Class DefaultMethodCall.Appender

extends Object
implements ByteCodeAppender
Class Inheritance
  • java.lang.Object
  • org.easymock.bytebuddy.implementation.DefaultMethodCall.Appender
All Implemented Interfaces
org.easymock.bytebuddy.implementation.bytecode.ByteCodeAppender
Annotations
@Enhance

The appender for implementing a org.easymock.bytebuddy.implementation.DefaultMethodCall.

Field Summary

Modifier and TypeField and Description
private final Implementation.Target
implementationTarget

The implementation target of this appender.

private final Set<TypeDescription>
nonPrioritizedInterfaces

The relevant non-prioritized interfaces to be considered by this appender.

private final List<TypeDescription>
prioritizedInterfaces

The relevant prioritized interfaces to be considered by this appender.

Constructor Summary

AccessConstructor and Description
protected
Appender(Implementation.Target
The implementation target of this appender.
implementationTarget
,
List<TypeDescription>
The relevant prioritized interfaces to be considered by this appender.
prioritizedInterfaces
)

Creates a new appender for implementing a org.easymock.bytebuddy.implementation.DefaultMethodCall.

Method Summary

Modifier and TypeMethod and Description
public ByteCodeAppender.Size
apply(MethodVisitor
The method visitor to which the byte code appender writes its code to.
methodVisitor
,
Implementation.Context
The implementation context of the current type creation process.
implementationContext
,
MethodDescription
The method that is the target of the instrumentation.
instrumentedMethod
)

Implements org.easymock.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Applies this byte code appender to a type creation process.
private StackManipulation

Returns:

A potentially illegal stack manipulation representing the default method invocation for the given method.
locateDefault
(MethodDescription
The method that is currently instrumented.
methodDescription
)

Locates a special method invocation to be invoked from a given method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

implementationTargetback to summary
private final Implementation.Target implementationTarget

The implementation target of this appender.

nonPrioritizedInterfacesback to summary
private final Set<TypeDescription> nonPrioritizedInterfaces

The relevant non-prioritized interfaces to be considered by this appender.

Annotations
@ValueHandling:IGNORE
prioritizedInterfacesback to summary
private final List<TypeDescription> prioritizedInterfaces

The relevant prioritized interfaces to be considered by this appender.

Constructor Detail

Appenderback to summary
protected Appender(Implementation.Target implementationTarget, List<TypeDescription> prioritizedInterfaces)

Creates a new appender for implementing a org.easymock.bytebuddy.implementation.DefaultMethodCall.

Parameters
implementationTarget:Implementation.Target

The implementation target of this appender.

prioritizedInterfaces:List<TypeDescription>

The relevant prioritized interfaces to be considered by this appender.

Method Detail

applyback to summary
public ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod)

Implements org.easymock.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Doc from org.easymock.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Applies this byte code appender to a type creation process.

Parameters
methodVisitor:MethodVisitor

The method visitor to which the byte code appender writes its code to.

implementationContext:Implementation.Context

The implementation context of the current type creation process.

instrumentedMethod:MethodDescription

The method that is the target of the instrumentation.

Returns:ByteCodeAppender.Size

The required size for the applied byte code to run.

locateDefaultback to summary
private StackManipulation locateDefault(MethodDescription methodDescription)

Locates a special method invocation to be invoked from a given method.

Parameters
methodDescription:MethodDescription

The method that is currently instrumented.

Returns:StackManipulation

A potentially illegal stack manipulation representing the default method invocation for the given method.