Class ExecutingInvocationUnit
- java.lang.Object
-
- proguard.evaluation.SimplifiedInvocationUnit
-
- proguard.evaluation.BasicInvocationUnit
-
- proguard.evaluation.ExecutingInvocationUnit
-
- All Implemented Interfaces:
ConstantVisitor
,MemberVisitor
,ParameterVisitor
,InvocationUnit
public class ExecutingInvocationUnit extends BasicInvocationUnit
ThisInvocationUnit
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 itsExecutor
s. Per default, an instance of this class will have access to aStringReflectionExecutor
that handles methods ofString
,StringBuilder
andStringBuffer
. TheExecutingInvocationUnit.Builder
, allows for disabling the defaultStringReflectionExecutor
and adding otherExecutor
s.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExecutingInvocationUnit.Builder
Builds anExecutingInvocationUnit
.
-
Field Summary
-
Fields inherited from class proguard.evaluation.BasicInvocationUnit
valueFactory
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExecutingInvocationUnit(ValueFactory valueFactory, boolean enableSameInstanceIdApproximation, java.util.List<Executor> registeredExecutors)
Creates anExecutingInvocationUnit
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 aConcreteCall
.MethodResult
executeMethod(Executor executor, MethodExecutionInfo methodInfo)
Executes a method using a givenExecutor
.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 java.lang.String className)
Checks whether any method of the given class is supported by the executors.boolean
supportsAnyMethodOf(@NotNull Clazz clazz)
Checks whether any method of the given class is supported by the executors.void
visitAnyMethodrefConstant(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant)
Visits any RefConstant instance.-
Methods inherited from class proguard.evaluation.BasicInvocationUnit
getExceptionValue, getFieldClassValue, getMethodParameterValue, getMethodReturnValue, setFieldClassValue, setFieldValue, setMethodReturnValue, visitLibraryField, visitLibraryMethod, visitProgramField, visitProgramMethod
-
Methods inherited from class proguard.evaluation.SimplifiedInvocationUnit
enterExceptionHandler, enterMethod, exitMethod, invokeMember, visitFieldrefConstant, visitInvokeDynamicConstant, visitParameter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface proguard.classfile.constant.visitor.ConstantVisitor
visitAnyConstant, visitAnyRefConstant, visitClassConstant, visitDoubleConstant, visitDynamicConstant, visitFloatConstant, visitIntegerConstant, visitInterfaceMethodrefConstant, visitLongConstant, visitMethodHandleConstant, visitMethodrefConstant, visitMethodTypeConstant, visitModuleConstant, visitNameAndTypeConstant, visitPackageConstant, visitPrimitiveArrayConstant, visitStringConstant, visitUtf8Constant
-
Methods inherited from interface proguard.evaluation.InvocationUnit
enterExceptionHandler, enterMethod, exitMethod, invokeMember
-
Methods inherited from interface proguard.classfile.visitor.MemberVisitor
visitAnyMember, visitLibraryMember, visitProgramMember
-
-
-
-
Constructor Detail
-
ExecutingInvocationUnit
protected ExecutingInvocationUnit(ValueFactory valueFactory, boolean enableSameInstanceIdApproximation, java.util.List<Executor> registeredExecutors)
Creates anExecutingInvocationUnit
.
-
-
Method Detail
-
visitAnyMethodrefConstant
public void visitAnyMethodrefConstant(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant)
Description copied from interface:ConstantVisitor
Visits any RefConstant instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyMethodrefConstant
in interfaceConstantVisitor
- Overrides:
visitAnyMethodrefConstant
in classSimplifiedInvocationUnit
-
setMethodParameterValue
public void setMethodParameterValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, int parameterIndex, Value value)
Description copied from class:SimplifiedInvocationUnit
Sets the value of the specified method parameter.- Overrides:
setMethodParameterValue
in classBasicInvocationUnit
-
methodMayHaveSideEffects
public boolean methodMayHaveSideEffects(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, java.lang.String returnType)
Description copied from class:SimplifiedInvocationUnit
Returns true if the method itself can modify the stack/variables and therefore needs to be executed even if it returns void.- Overrides:
methodMayHaveSideEffects
in classSimplifiedInvocationUnit
-
getMethodReturnValue
public Value getMethodReturnValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, java.lang.String returnType)
Description copied from class:SimplifiedInvocationUnit
Returns the return value of the specified method.- Overrides:
getMethodReturnValue
in classBasicInvocationUnit
-
executeMethod
public MethodResult executeMethod(ConcreteCall call, Value... parameters)
Execute the method given by aConcreteCall
. SeeexecuteMethod(Executor, MethodExecutionInfo)
- Parameters:
call
- The concrete call.parameters
- The calling parameters.- Returns:
- The method result value.
-
executeMethod
public MethodResult executeMethod(Executor executor, MethodExecutionInfo methodInfo)
Executes a method using a givenExecutor
. Replace references of the instance in variables and stack if necessary. The return value represents the result of the executed method.- Parameters:
executor
- TheExecutor
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
-
getFieldValue
public Value getFieldValue(Clazz clazz, FieldrefConstant fieldrefConstant, java.lang.String type)
Description copied from class:SimplifiedInvocationUnit
Returns the value of the specified field.- Overrides:
getFieldValue
in classBasicInvocationUnit
-
-