Package nz.org.riskscape.engine
Class DefaultFunctionResolver
java.lang.Object
nz.org.riskscape.engine.DefaultFunctionResolver
- All Implemented Interfaces:
nz.org.riskscape.engine.function.FunctionResolver
public class DefaultFunctionResolver
extends Object
implements nz.org.riskscape.engine.function.FunctionResolver
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
evaluateConstant
(nz.org.riskscape.engine.rl.RealizationContext context, nz.org.riskscape.rl.ast.FunctionCall functionCall, int argIndex, Class<T> requiredJavaType, nz.org.riskscape.engine.types.Type requiredType) Helper method for aRealizableFunction
to extract a constant from the arguments with various error handling along the way.nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.function.RiskscapeFunction>
resolve
(nz.org.riskscape.engine.rl.RealizationContext context, nz.org.riskscape.rl.ast.FunctionCall functionCall, nz.org.riskscape.engine.types.Type inputType, List<nz.org.riskscape.engine.types.Type> argumentTypes, nz.org.riskscape.engine.function.IdentifiedFunction function)
-
Constructor Details
-
DefaultFunctionResolver
public DefaultFunctionResolver()
-
-
Method Details
-
evaluateConstant
public static <T> T evaluateConstant(nz.org.riskscape.engine.rl.RealizationContext context, nz.org.riskscape.rl.ast.FunctionCall functionCall, int argIndex, Class<T> requiredJavaType, nz.org.riskscape.engine.types.Type requiredType) throws nz.org.riskscape.problem.ProblemException Helper method for a
RealizableFunction
to extract a constant from the arguments with various error handling along the way. This method will fail if the expression is not a constant expression (e.g. it depends on values extracted from scope).- Type Parameters:
T
-- Parameters:
context
- context in which realization is happening - typically the argument that was passed toRealizableFunction.realize(RealizationContext, FunctionCall, List)
functionCall
- the functionCall expression that contains an argument to be realized constantlyargIndex
- the index of the argument (0 based) that should be a constantrequiredJavaType
- the desired java type of the constant - must map to a built-in riskscape type viaTypes.fromJavaType(Class)
requiredType
- the Riskscape version of the requiredJavaType argument. Is only used for a problem and no riskscape type checking is actually done against this type.- Returns:
- the constant value from the function call expression
- Throws:
nz.org.riskscape.problem.ProblemException
- if the expression was bad, not a constant, or of the wrong type. Contained problem should be suitable for display to the user without wrapping with more function-call specific context
-
resolve
public nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.function.RiskscapeFunction> resolve(nz.org.riskscape.engine.rl.RealizationContext context, nz.org.riskscape.rl.ast.FunctionCall functionCall, nz.org.riskscape.engine.types.Type inputType, List<nz.org.riskscape.engine.types.Type> argumentTypes, nz.org.riskscape.engine.function.IdentifiedFunction function) - Specified by:
resolve
in interfacenz.org.riskscape.engine.function.FunctionResolver
-