public class ExecutingInvocationUnit extends BasicInvocationUnit
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 Value
s 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
Executor
s. 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 Executor
s.
Modifier and Type | Class and Description |
---|---|
static class |
ExecutingInvocationUnit.Builder
Builds an
ExecutingInvocationUnit . |
valueFactory
Modifier | Constructor and Description |
---|---|
protected |
ExecutingInvocationUnit(ValueFactory valueFactory,
boolean enableSameInstanceIdApproximation,
java.util.List<Executor> registeredExecutors)
Creates an
ExecutingInvocationUnit . |
Modifier and Type | Method and Description |
---|---|
boolean |
canExecute(@NotNull MethodSignature signature)
Returns whether the invocation unit is able to handle the given method.
|
MethodResult |
executeMethod(ConcreteCall call,
Value... parameters)
Execute the method given by a
ConcreteCall . |
MethodResult |
executeMethod(Executor executor,
MethodExecutionInfo methodInfo)
Executes a method using a given
Executor . |
Value |
getFieldValue(Clazz clazz,
FieldrefConstant fieldrefConstant,
java.lang.String type)
Returns the value of the specified field.
|
Value |
getMethodReturnValue(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant,
java.lang.String returnType)
Returns the return value of the specified method.
|
boolean |
methodMayHaveSideEffects(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant,
java.lang.String returnType)
Returns true if the method itself can modify the stack/variables and therefore needs to be
executed even if it returns void.
|
void |
setMethodParameterValue(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant,
int parameterIndex,
Value value)
Sets the value of the specified method parameter.
|
boolean |
supportsAnyMethodOf(@NotNull Clazz clazz)
Checks whether any method of the given class is supported by the executors.
|
boolean |
supportsAnyMethodOf(@NotNull java.lang.String className)
Checks whether any method of the given class is supported by the executors.
|
void |
visitAnyMethodrefConstant(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant)
Visits any RefConstant instance.
|
getExceptionValue, getFieldClassValue, getMethodParameterValue, getMethodReturnValue, setFieldClassValue, setFieldValue, setMethodReturnValue, visitLibraryField, visitLibraryMethod, visitProgramField, visitProgramMethod
enterExceptionHandler, enterMethod, exitMethod, invokeMember, visitFieldrefConstant, visitInvokeDynamicConstant, visitParameter
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
enterExceptionHandler, enterMethod, exitMethod, invokeMember
visitAnyMember, visitLibraryMember, visitProgramMember
visitAnyConstant, visitAnyRefConstant, visitClassConstant, visitDoubleConstant, visitDynamicConstant, visitFloatConstant, visitIntegerConstant, visitInterfaceMethodrefConstant, visitLongConstant, visitMethodHandleConstant, visitMethodrefConstant, visitMethodTypeConstant, visitModuleConstant, visitNameAndTypeConstant, visitPackageConstant, visitPrimitiveArrayConstant, visitStringConstant, visitUtf8Constant
protected ExecutingInvocationUnit(ValueFactory valueFactory, boolean enableSameInstanceIdApproximation, java.util.List<Executor> registeredExecutors)
ExecutingInvocationUnit
.public void visitAnyMethodrefConstant(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant)
ConstantVisitor
visitAnyMethodrefConstant
in interface ConstantVisitor
visitAnyMethodrefConstant
in class SimplifiedInvocationUnit
public void setMethodParameterValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, int parameterIndex, Value value)
SimplifiedInvocationUnit
setMethodParameterValue
in class BasicInvocationUnit
public boolean methodMayHaveSideEffects(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, java.lang.String returnType)
SimplifiedInvocationUnit
methodMayHaveSideEffects
in class SimplifiedInvocationUnit
public Value getMethodReturnValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, java.lang.String returnType)
SimplifiedInvocationUnit
getMethodReturnValue
in class BasicInvocationUnit
public MethodResult executeMethod(ConcreteCall call, Value... parameters)
ConcreteCall
. See executeMethod(Executor, MethodExecutionInfo)
call
- The concrete call.parameters
- The calling parameters.public MethodResult executeMethod(Executor executor, MethodExecutionInfo methodInfo)
Executor
. Replace references of the instance in
variables and stack if necessary. The return value represents the result of the executed
method.executor
- The Executor
which handles this method call.methodInfo
- Information about the method to execute.public boolean canExecute(@NotNull @NotNull MethodSignature signature)
signature
- The method signature of the method being testedpublic boolean supportsAnyMethodOf(@NotNull @NotNull Clazz clazz)
clazz
- The class to checkpublic boolean supportsAnyMethodOf(@NotNull @NotNull java.lang.String className)
className
- The class name to checkpublic Value getFieldValue(Clazz clazz, FieldrefConstant fieldrefConstant, java.lang.String type)
SimplifiedInvocationUnit
getFieldValue
in class BasicInvocationUnit