Class ExecutableInvoker


  • @API(status=INTERNAL,
         since="5.0")
    public class ExecutableInvoker
    extends java.lang.Object
    ExecutableInvoker encapsulates the invocation of a Executable (i.e., method or constructor), including support for dynamic resolution of method parameters via ParameterResolvers.
    Since:
    5.0
    • Constructor Detail

      • ExecutableInvoker

        public ExecutableInvoker()
    • Method Detail

      • invoke

        public <T> T invoke​(java.lang.reflect.Constructor<T> constructor,
                            java.util.Optional<java.lang.Object> outerInstance,
                            ExtensionContext extensionContext,
                            ExtensionRegistry extensionRegistry,
                            ExecutableInvoker.ReflectiveInterceptorCall<java.lang.reflect.Constructor<T>,​T> interceptorCall)
        Invoke the supplied constructor with the supplied outer instance and dynamic parameter resolution.

        This method should only be used to invoke the constructor for an inner class.

        Parameters:
        constructor - the constructor to invoke and resolve parameters for
        outerInstance - the outer instance to supply as the first argument to the constructor; empty, for top-level classes
        extensionContext - the current ExtensionContext
        extensionRegistry - the ExtensionRegistry to retrieve ParameterResolvers from
        interceptorCall - the call for intercepting this constructor invocation via all registered interceptors
      • invoke

        public <T> T invoke​(java.lang.reflect.Method method,
                            java.lang.Object target,
                            ExtensionContext extensionContext,
                            ExtensionRegistry extensionRegistry,
                            ExecutableInvoker.ReflectiveInterceptorCall<java.lang.reflect.Method,​T> interceptorCall)
        Invoke the supplied static method with dynamic parameter resolution.
        Parameters:
        method - the method to invoke and resolve parameters for
        extensionContext - the current ExtensionContext
        extensionRegistry - the ExtensionRegistry to retrieve ParameterResolvers from
        interceptorCall - the call for intercepting this method invocation via all registered interceptors
      • resolveParameters

        private java.lang.Object[] resolveParameters​(java.lang.reflect.Method method,
                                                     java.util.Optional<java.lang.Object> target,
                                                     ExtensionContext extensionContext,
                                                     ExtensionRegistry extensionRegistry)
        Resolve the array of parameters for the supplied method and target.
        Parameters:
        method - the method for which to resolve parameters
        target - an Optional containing the target on which the executable will be invoked; never null but should be empty for static methods and constructors
        extensionContext - the current ExtensionContext
        extensionRegistry - the ExtensionRegistry to retrieve ParameterResolvers from
        Returns:
        the array of Objects to be used as parameters in the executable invocation; never null though potentially empty
      • resolveParameters

        private java.lang.Object[] resolveParameters​(java.lang.reflect.Executable executable,
                                                     java.util.Optional<java.lang.Object> target,
                                                     java.util.Optional<java.lang.Object> outerInstance,
                                                     ExtensionContext extensionContext,
                                                     ExtensionRegistry extensionRegistry)
        Resolve the array of parameters for the supplied executable, target, and outer instance.
        Parameters:
        executable - the executable for which to resolve parameters
        target - an Optional containing the target on which the executable will be invoked; never null but should be empty for static methods and constructors
        outerInstance - the outer instance that will be supplied as the first argument to a constructor for an inner class; should be null for methods and constructors for top-level or static classes
        extensionContext - the current ExtensionContext
        extensionRegistry - the ExtensionRegistry to retrieve ParameterResolvers from
        Returns:
        the array of Objects to be used as parameters in the executable invocation; never null though potentially empty
      • validateResolvedType

        private void validateResolvedType​(java.lang.reflect.Parameter parameter,
                                          java.lang.Object value,
                                          java.lang.reflect.Executable executable,
                                          ParameterResolver resolver)
      • asLabel

        private static java.lang.String asLabel​(java.lang.reflect.Executable executable)