Class ModelHelper
- java.lang.Object
-
- proguard.evaluation.value.object.model.reflective.ModelHelper
-
public final class ModelHelper extends java.lang.ObjectHelper methods to useModels.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelHelper.MethodExecutionContextA helper class groupingMethodExecutionInfoandValueCalculatoras the execution context of a method.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanallParticular(java.util.List<Value> values)Simple helper method to check if all values in the given list are particular.static booleanareInstanceAndParametersParticular(MethodExecutionInfo executionInfo)Check whether both the instance (for instance methods) and all parameters of a method call are particular.static MethodResultcreateDefaultBuilderResult(ModelHelper.MethodExecutionContext context, java.lang.Object newInstance)Helper to create a method result containing "this", the instance a method has been called on.static MethodResultcreateDefaultConstructorResult(ModelHelper.MethodExecutionContext context, Model concreteValue)Helper to create a value from a standard modeled constructor call.static MethodResultcreateDefaultReturnResult(ModelHelper.MethodExecutionContext context, @Nullable java.lang.Object concreteValue)Helper to create a value from a standard modeled method call.static MethodResultcreateUnknownBuilderResult(ModelHelper.MethodExecutionContext context)Helper to create a method result containing "this" with unknown value.static MethodResultexecuteViaHandler(ModelHelper.MethodExecutionContext context, java.util.Map<BasicMethodInfo,java.lang.reflect.Method> handlers, Model instance)Utility method to execute a modeled method on a model using the provided Map of supported handlers.static <T extends ReflectiveModel<T>>
java.util.Map<BasicMethodInfo,java.lang.reflect.Method>getConstructorHandlers(java.lang.Class<T> modelClass)Given a model class, use reflection to build a mapping fromBasicMethodInfos used by the analysis to identify a constructor to theMethodhandler to the method modeling it, in order to be able to invoke it.static <T extends ReflectiveModel<T>>
TgetDummyObject(java.lang.Class<T> modelClass)static <T extends ReflectiveModel<T>>
java.util.Map<BasicMethodInfo,java.lang.reflect.Method>getInstanceMethodHandlers(java.lang.Class<T> modelClass)Given a model class, use reflection to build a mapping fromBasicMethodInfos used by the analysis to identify an instance method to theMethodhandler to the method modeling it, in order to be able to invoke it.static <T extends ReflectiveModel<T>>
java.util.Map<BasicMethodInfo,java.lang.reflect.Method>getStaticMethodHandlers(java.lang.Class<T> modelClass)Given a model class, use reflection to build a mapping fromBasicMethodInfos used by the analysis to identify an instance method to theMethodhandler to the method modeling it, in order to be able to invoke it.static <T extends ReflectiveModel<T>>
java.util.Collection<BasicMethodInfo>getSupportedMethods(java.lang.Class<T> modelClass)
-
-
-
Method Detail
-
getConstructorHandlers
public static <T extends ReflectiveModel<T>> java.util.Map<BasicMethodInfo,java.lang.reflect.Method> getConstructorHandlers(java.lang.Class<T> modelClass)
Given a model class, use reflection to build a mapping fromBasicMethodInfos used by the analysis to identify a constructor to theMethodhandler to the method modeling it, in order to be able to invoke it.The model needs to annotate the methods modeling constructors with
ModeledConstructor.- Parameters:
modelClass- theModel's class- Returns:
- a mapping from a signature to the method modeling the constructor it represents
-
getInstanceMethodHandlers
public static <T extends ReflectiveModel<T>> java.util.Map<BasicMethodInfo,java.lang.reflect.Method> getInstanceMethodHandlers(java.lang.Class<T> modelClass)
Given a model class, use reflection to build a mapping fromBasicMethodInfos used by the analysis to identify an instance method to theMethodhandler to the method modeling it, in order to be able to invoke it.The model needs to annotate the methods modeling instance methods with
ModeledInstanceMethod.- Parameters:
modelClass- theModel's class- Returns:
- a mapping from a signature to the method modeling the instance method it represents
-
getStaticMethodHandlers
public static <T extends ReflectiveModel<T>> java.util.Map<BasicMethodInfo,java.lang.reflect.Method> getStaticMethodHandlers(java.lang.Class<T> modelClass)
Given a model class, use reflection to build a mapping fromBasicMethodInfos used by the analysis to identify an instance method to theMethodhandler to the method modeling it, in order to be able to invoke it.The model needs to annotate the methods modeling instance methods with
ModeledInstanceMethod.- Parameters:
modelClass- theModel's class- Returns:
- a mapping from a signature to the method modeling the static method it represents
-
getDummyObject
public static <T extends ReflectiveModel<T>> T getDummyObject(java.lang.Class<T> modelClass)
-
getSupportedMethods
public static <T extends ReflectiveModel<T>> java.util.Collection<BasicMethodInfo> getSupportedMethods(java.lang.Class<T> modelClass)
-
allParticular
public static boolean allParticular(java.util.List<Value> values)
Simple helper method to check if all values in the given list are particular.- Parameters:
values- Values to check.- Returns:
- Whether all of the values are particular.
-
areInstanceAndParametersParticular
public static boolean areInstanceAndParametersParticular(MethodExecutionInfo executionInfo)
Check whether both the instance (for instance methods) and all parameters of a method call are particular.- Parameters:
executionInfo- information on a method execution.- Returns:
- whether both the instance and the parameters are particular.
-
executeViaHandler
public static MethodResult executeViaHandler(ModelHelper.MethodExecutionContext context, java.util.Map<BasicMethodInfo,java.lang.reflect.Method> handlers, Model instance)
Utility method to execute a modeled method on a model using the provided Map of supported handlers.- Parameters:
context- The method execution context.handlers- Map ofBasicMethodInfotoMethods which are supported.instance- Instance to execute the method on.- Returns:
- The result of the method execution.
- Throws:
java.lang.UnsupportedOperationException- If a method without handler is requested.java.lang.RuntimeException- For any exception during reflective execution of the method.
-
createDefaultConstructorResult
public static MethodResult createDefaultConstructorResult(ModelHelper.MethodExecutionContext context, Model concreteValue)
Helper to create a value from a standard modeled constructor call. This should be used for constructor where all of these are true:- Create a known (particular) value
- Have no side effects besides constructing the object
- Parameters:
context- The method execution context.concreteValue- The value of the constructed object.- Returns:
- The result containing the updated instance.
-
createDefaultReturnResult
public static MethodResult createDefaultReturnResult(ModelHelper.MethodExecutionContext context, @Nullable @Nullable java.lang.Object concreteValue)
Helper to create a value from a standard modeled method call. This should be used for calls where all of these are true:- Return a known (particular) value
- Is a pure function (i.e. no side-effects, just returns a value)
- Parameters:
context- The method execution context.concreteValue- The value of the returned object, can be precise or aModel.- Returns:
- The result containing the return value.
-
createDefaultBuilderResult
public static MethodResult createDefaultBuilderResult(ModelHelper.MethodExecutionContext context, java.lang.Object newInstance)
Helper to create a method result containing "this", the instance a method has been called on. This should be used for calls where all of these are true:- Returns the instance the method was invoked on
- Have no side effects besides the modification of the instance
Usually, this would be used on classes with a fluent interface, e.g. setters when using the Builder design pattern:
Builder setValue(value) { this.value = value; // modify instance return this; }- Parameters:
context- The method execution context.newInstance- The new instance, can be precise or aModel.- Returns:
- The result containing the return value.
-
createUnknownBuilderResult
public static MethodResult createUnknownBuilderResult(ModelHelper.MethodExecutionContext context)
Helper to create a method result containing "this" with unknown value. The helper should be used only for calls where all of these are true:- Returns the instance the method was invoked on, the instance value might or might not be already known
- Have no other side effects
- The value of the instance is now unknown
Usually, this would be used on classes with a fluent interface, e.g. setters when using the Builder design pattern:
Builder setValue(value) { this.value = value; // modify instance return this; }- Parameters:
context- The method execution context.- Returns:
- The result containing the return value.
-
-