Class InvocationHandlerAdapter

    • Field Detail

      • INVOCATION_HANDLER_TYPE

        private static final TypeDescription.Generic INVOCATION_HANDLER_TYPE
        A type description of the InvocationHandler.
      • UNCACHED

        private static final boolean UNCACHED
        Indicates that a value should not be cached.
        See Also:
        Constant Field Values
      • CACHED

        private static final boolean CACHED
        Indicates that a Method should be cached.
        See Also:
        Constant Field Values
      • UNPRIVILEGED

        private static final boolean UNPRIVILEGED
        Indicates that a lookup of a method constant should not be looked up using an AccessController.
        See Also:
        Constant Field Values
      • PRIVILEGED

        private static final boolean PRIVILEGED
        Indicates that a lookup of a method constant should be looked up using an AccessController.
        See Also:
        Constant Field Values
      • fieldName

        protected final java.lang.String fieldName
        The name of the field for storing an invocation handler.
      • assigner

        protected final Assigner assigner
        The assigner that is used for assigning the return invocation handler's return value to the intercepted method's return value.
      • cached

        protected final boolean cached
        Determines if the Method instances that are handed to the intercepted methods are cached in static fields.
      • privileged

        protected final boolean privileged
        Determines if the Method instances are retrieved by using an AccessController.
    • Constructor Detail

      • InvocationHandlerAdapter

        protected InvocationHandlerAdapter​(java.lang.String fieldName,
                                           boolean cached,
                                           boolean privileged,
                                           Assigner assigner)
        Creates a new invocation handler for a given field.
        Parameters:
        fieldName - The name of the field.
        cached - Determines if the Method instances that are handed to the intercepted methods are cached in static fields.
        privileged - Determines if the Method instances are retrieved by using an AccessController.
        assigner - The assigner to apply when defining this implementation.
    • Method Detail

      • of

        public static InvocationHandlerAdapter of​(java.lang.reflect.InvocationHandler invocationHandler)
        Creates an implementation for any instance of an InvocationHandler that delegates all method interceptions to the given instance which will be stored in a static field.
        Parameters:
        invocationHandler - The invocation handler to which all method calls are delegated.
        Returns:
        An implementation that delegates all method interceptions to the given invocation handler.
      • of

        public static InvocationHandlerAdapter of​(java.lang.reflect.InvocationHandler invocationHandler,
                                                  java.lang.String fieldName)
        Creates an implementation for any instance of an InvocationHandler that delegates all method interceptions to the given instance which will be stored in a static field.
        Parameters:
        invocationHandler - The invocation handler to which all method calls are delegated.
        fieldName - The name of the field.
        Returns:
        An implementation that delegates all method interceptions to the given invocation handler.
      • toField

        public static InvocationHandlerAdapter toField​(java.lang.String name)
        Creates an implementation for any InvocationHandler that delegates all method interceptions to a field with the given name. This field has to be of a subtype of invocation handler and needs to be set before any invocations are intercepted. Otherwise, a NullPointerException will be thrown.
        Parameters:
        name - The name of the field.
        Returns:
        An implementation that delegates all method interceptions to an instance field of the given name.
      • toField

        public static InvocationHandlerAdapter toField​(java.lang.String name,
                                                       FieldLocator.Factory fieldLocatorFactory)
        Creates an implementation for any InvocationHandler that delegates all method interceptions to a field with the given name. This field has to be of a subtype of invocation handler and needs to be set before any invocations are intercepted. Otherwise, a NullPointerException will be thrown.
        Parameters:
        name - The name of the field.
        fieldLocatorFactory - The field locator factory
        Returns:
        An implementation that delegates all method interceptions to an instance field of the given name.
      • argumentValuesOf

        private java.util.List<StackManipulation> argumentValuesOf​(MethodDescription instrumentedMethod)
        Returns a list of stack manipulations that loads all arguments of an instrumented method.
        Parameters:
        instrumentedMethod - The method that is instrumented.
        Returns:
        A list of stack manipulation that loads all arguments of an instrumented method.
      • withoutMethodCache

        public abstract InvocationHandlerAdapter.WithoutPrivilegeConfiguration withoutMethodCache()
        By default, any Method instance that is handed over to an InvocationHandler is cached in a static field. By invoking this method, this feature can be disabled.
        Returns:
        A similar invocation handler adapter that applies caching.
      • withAssigner

        public abstract Implementation withAssigner​(Assigner assigner)
        Configures an assigner to use with this invocation handler adapter.
        Parameters:
        assigner - The assigner to apply when defining this implementation.
        Returns:
        This instrumentation with the given assigner configured.
      • withPrivilegedLookup

        public abstract InvocationHandlerAdapter.AssignerConfigurable withPrivilegedLookup()
        Configures that the method constants supplied to the invocation handler adapter are resolved using an AccessController.
        Returns:
        This instrumentation with a privileged lookup configured.
      • apply

        protected ByteCodeAppender.Size apply​(org.objectweb.asm.MethodVisitor methodVisitor,
                                              Implementation.Context implementationContext,
                                              MethodDescription instrumentedMethod,
                                              StackManipulation preparingManipulation,
                                              FieldDescription fieldDescription)
        Applies an implementation that delegates to a invocation handler.
        Parameters:
        methodVisitor - The method visitor for writing the byte code to.
        implementationContext - The implementation context for the current implementation.
        instrumentedMethod - The method that is instrumented.
        preparingManipulation - A stack manipulation that applies any preparation to the operand stack.
        fieldDescription - The field that contains the value for the invocation handler.
        Returns:
        The size of the applied assignment.