Class ExecutingInvocationUnit

  • All Implemented Interfaces:
    ConstantVisitor, MemberVisitor, ParameterVisitor, InvocationUnit

    public class ExecutingInvocationUnit
    extends BasicInvocationUnit
    This InvocationUnit is capable of executing the invoked methods with particular values as parameters.

    If a method has a return value, this value is determined and supplied as a particular Value. Methods that operate on an instance are able to modify the calling instance. For such methods, references in the stack and variables to that instance are replaced with the modified one. This also applies to constructors.

    This class is responsible for creating the final particular Values for methods that were handled without errors and creating fallback values in case the method could not be handled. It also performs the action of replacing references of instances that changed in the stack and variables if needed. This is however limited as we only update the instance if it was modified and ignores all other parameters which might have changed too.

    An ExecutingInvocationUnit delegates the acquisition of method results and certain other decisions (e.g. whether replacing references in the stack and variables is needed) to its Executors. Per default, an instance of this class will have access to a StringReflectionExecutor that handles methods of String, StringBuilder and StringBuffer. The ExecutingInvocationUnit.Builder, allows for disabling the default StringReflectionExecutor and adding other Executors.

    • Constructor Detail

      • ExecutingInvocationUnit

        protected ExecutingInvocationUnit​(ValueFactory valueFactory,
                                          boolean enableSameInstanceIdApproximation,
                                          java.util.List<Executor> registeredExecutors)
    • Method Detail

      • executeMethod

        public MethodResult executeMethod​(Executor executor,
                                          MethodExecutionInfo methodInfo)
        Executes a method using a given Executor. Replace references of the instance in variables and stack if necessary. The return value represents the result of the executed method.
        Parameters:
        executor - The Executor which handles this method call.
        methodInfo - Information about the method to execute.
        Returns:
        The method result value.
      • canExecute

        public boolean canExecute​(@NotNull
                                  @NotNull MethodSignature signature)
        Returns whether the invocation unit is able to handle the given method.
        Parameters:
        signature - The method signature of the method being tested
        Returns:
        true if the method can be executed.
      • supportsAnyMethodOf

        public boolean supportsAnyMethodOf​(@NotNull
                                           @NotNull Clazz clazz)
        Checks whether any method of the given class is supported by the executors.
        Parameters:
        clazz - The class to check
        Returns:
        true if any method of the given class is supported by the executor
      • supportsAnyMethodOf

        public boolean supportsAnyMethodOf​(@NotNull
                                           @NotNull java.lang.String className)
        Checks whether any method of the given class is supported by the executors.
        Parameters:
        className - The class name to check
        Returns:
        true if any method of the given class is supported by the executor