Class ExecutionVisitor<M extends IResolvableModel<V,M>,O extends IResolvableOperation<V>,V extends VariableDeclaration,R extends Resolver<M,O,?,V>>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.EvaluationVisitor
-
- net.ssehub.easy.instantiation.core.model.common.ExecutionVisitor<M,O,V,R>
-
- Type Parameters:
M- the actual model typeO- the actual operation typeV- the actual variable declaration typeR- the resolver type
- All Implemented Interfaces:
IVisitor,IExpressionVisitor
- Direct Known Subclasses:
BuildlangExecution,TemplateLangExecution
public abstract class ExecutionVisitor<M extends IResolvableModel<V,M>,O extends IResolvableOperation<V>,V extends VariableDeclaration,R extends Resolver<M,O,?,V>> extends EvaluationVisitor implements IVisitor
Extends the basic expression evaluation visitor for the execution of those classes being defined in this package.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classExecutionVisitor.ConditionTestSpecifies various types of artifact condition tests.
-
Field Summary
Fields Modifier and Type Field Description private RuntimeEnvironment<V,M>environmentprivate RuntimeEnvironment<?,?>origEnvironmentprivate java.util.Map<java.lang.String,java.lang.Object>parameterprivate ITracertracer
-
Constructor Summary
Constructors Modifier Constructor Description protectedExecutionVisitor(RuntimeEnvironment<V,M> environment, ITracer tracer, java.util.Map<java.lang.String,java.lang.Object> parameter)Creates an execution visitor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidassignModelParameter(IResolvableModel<V,M> targetModel, IResolvableModel<V,M> srcModel)Assigns the model parameters.protected booleancheckConditionResult(java.lang.Object value, java.lang.Object element, ExecutionVisitor.ConditionTest test)Checks the results of an evaluation of a condition.protected java.lang.ObjectconvertToContainer(Expression expr, java.lang.Object value, java.lang.String eltName)Converts the actualvalueofexprto a container if required and possible.protected abstract ModelCallExpression<V,M,O>createModelCall(M model, O operation, CallArgument... arguments)Creates a model call expression instance.protected java.util.Map<java.lang.String,java.lang.Object>determineScriptParam(ModelCallExpression<V,M,O> call)Determines script parameters from a call, i.e., takes over arguments and fixes them.protected java.lang.ObjectdoAssignmentConversions(VariableDeclaration var, java.lang.Object value)Performs special conversions prior to an assignment.protected abstract OdynamicDispatch(O operation, java.lang.Object[] args, IArgumentProvider argumentProvider, boolean enableParentScope)Performs the dynamic dispatch on the operation type.protected voidenableArtifactAutoStoreOnParameters(boolean autoStore)Enables/disables auto storing parameters upon variables becoming unavailable.private java.lang.ObjectevaluateDefault(VariableDeclaration decl)Evaluates the default value ofdecl.protected voidevaluateModelParameter(IResolvableModel<V,M> targetModel, IResolvableModel<V,M> srcModel, int startIndex)Assigns the model parameters.protected java.lang.ObjectexecuteMain(M model, O operation)Executes the main operation.protected abstract java.lang.ObjectexecuteModelCall(O operation)Actually executes a model call.protected abstract IExpressionParser<R>getExpressionParser()Returns the actual expression parser.protected java.lang.ObjectgetParameter(java.lang.String name)Returns the specified parameter.protected intgetParameterCount()Returns the number of parameters.RuntimeEnvironment<V,M>getRuntimeEnvironment()Returns the runtime environment (for testing).protected ITracergetTracer()Returns the tracer instance..protected voidhandleParameterInSequence(IResolvableModel<V,M> model, java.util.Map<java.lang.String,V> varMap)Handles model parameters in sequence if appropriate.protected booleanhasParameter(java.lang.String name)Returns whether the specified parameter is defined.protected voidinitializeImplicitVariables(IResolvableModel<V,M> model)Initializes implicit variables of a model (before explicitly defined variables).protected booleanmayFail(java.lang.Object elt)Returns whether a rule element may fail.protected voidnotifyValueDefined(VariableDeclaration var, FieldDescriptor field, java.lang.Object val)Is called when a value of a value is defined.protected java.lang.ObjectproceedModelCall(O resolved, M model, IArgumentProvider arguments, boolean isPlaceholder, boolean enableParentScope)Performs a model call.protected voidprocessModelParameter(IResolvableModel<V,M> model)Processes the parameters ofmodel.voidrelease(boolean releaseDefault)Releases the resources allocated by this execution.protected java.util.Map<java.lang.String,java.lang.Object>replaceParameter(java.util.Map<java.lang.String,java.lang.Object> parameter)Exchanges the current script parameter in case of context changes.protected voidsetModelArgument(V param, java.lang.Object value)Defines the value of a given model/main argument and allows (by overriding) implicit (programmed) conversion of main arguments.java.lang.ObjectvisitAdvice(Advice advice)Visits an advice.java.lang.ObjectvisitExpressionStatement(ExpressionStatement statement)Visits a statement.protected java.lang.ObjectvisitModelCallExpression(ModelCallExpression<V,M,O> call)Visits a model call expression.voidvisitModelHeader(IResolvableModel<V,M> model)Visits the related model headers.private voidvisitModelHeader(IResolvableModel<V,M> model, java.util.Set<IResolvableModel<V,M>> visited)Visits the related model headers.java.lang.ObjectvisitVariableDeclaration(VariableDeclaration var)Visits a variable declaration.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.expressions.EvaluationVisitor
addImplicitParamters, appendInCompositeExpression, evaluateContentExpression, lastContentReplaceEmptyLine, visitCallExpression, visitCompositeExpression, visitConstantExpression, visitContainerInitializerExpression, visitExpression, visitExpressionEvaluator, visitFieldAccessExpression, visitMultiAndExpression, visitParenthesisExpression, visitResolvableOperationCallExpression, visitResolvableOperationExpression, visitStringExpression, visitValueAssignmentExpression, visitVariableExpression, visitVarModelIdentifierExpression, visitVilTypeExpression
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.common.IVisitor
visitCompound, visitTypedef
-
-
-
-
Field Detail
-
origEnvironment
private RuntimeEnvironment<?,?> origEnvironment
-
environment
private RuntimeEnvironment<V extends VariableDeclaration,M extends IResolvableModel<V,M>> environment
-
tracer
private ITracer tracer
-
parameter
private java.util.Map<java.lang.String,java.lang.Object> parameter
-
-
Constructor Detail
-
ExecutionVisitor
protected ExecutionVisitor(RuntimeEnvironment<V,M> environment, ITracer tracer, java.util.Map<java.lang.String,java.lang.Object> parameter)
Creates an execution visitor.- Parameters:
environment- the runtime environmenttracer- the execution tracer instance (for testing)parameter- the parameter given from outside for the execution of the model
-
-
Method Detail
-
replaceParameter
protected java.util.Map<java.lang.String,java.lang.Object> replaceParameter(java.util.Map<java.lang.String,java.lang.Object> parameter)
Exchanges the current script parameter in case of context changes. [better - assign to context]- Parameters:
parameter- the new parameter set- Returns:
- the old parameter set
-
getRuntimeEnvironment
public RuntimeEnvironment<V,M> getRuntimeEnvironment()
Returns the runtime environment (for testing).- Overrides:
getRuntimeEnvironmentin classEvaluationVisitor- Returns:
- the runtime environment
-
getParameter
protected java.lang.Object getParameter(java.lang.String name)
Returns the specified parameter.- Parameters:
name- the name of the parameter- Returns:
- the value of the parameter
-
enableArtifactAutoStoreOnParameters
protected void enableArtifactAutoStoreOnParameters(boolean autoStore)
Enables/disables auto storing parameters upon variables becoming unavailable.- Parameters:
autoStore- do auto store or not
-
release
public void release(boolean releaseDefault)
Releases the resources allocated by this execution.- Parameters:
releaseDefault- shall also default artifacts, i.e., artifacts that cannot be assigned to a source / target artifact model be released? May affect execution of other VIL models.
-
hasParameter
protected boolean hasParameter(java.lang.String name)
Returns whether the specified parameter is defined.- Parameters:
name- the name of the parameter- Returns:
trueif the parameter is defined,falseelse
-
getParameterCount
protected int getParameterCount()
Returns the number of parameters.- Returns:
- the number of parameters
-
getTracer
protected ITracer getTracer()
Returns the tracer instance..- Returns:
- the tracer instance
-
visitVariableDeclaration
public java.lang.Object visitVariableDeclaration(VariableDeclaration var) throws VilException
Description copied from interface:IVisitorVisits a variable declaration.- Specified by:
visitVariableDeclarationin interfaceIVisitor- Parameters:
var- the variable declaration- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
doAssignmentConversions
protected java.lang.Object doAssignmentConversions(VariableDeclaration var, java.lang.Object value)
Performs special conversions prior to an assignment.- Parameters:
var- the target variablevalue- the value to be assigned- Returns:
- the converted value or
value
-
visitAdvice
public java.lang.Object visitAdvice(Advice advice) throws VilException
Description copied from interface:IVisitorVisits an advice.- Specified by:
visitAdvicein interfaceIVisitor- Parameters:
advice- the advice to be visited- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitExpressionStatement
public java.lang.Object visitExpressionStatement(ExpressionStatement statement) throws VilException
Description copied from interface:IVisitorVisits a statement.- Specified by:
visitExpressionStatementin interfaceIVisitor- Parameters:
statement- the statement- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
notifyValueDefined
protected void notifyValueDefined(VariableDeclaration var, FieldDescriptor field, java.lang.Object val)
Description copied from class:EvaluationVisitorIs called when a value of a value is defined.- Overrides:
notifyValueDefinedin classEvaluationVisitor- Parameters:
var- the variablefield- the field invar, may be nullval- the value
-
checkConditionResult
protected boolean checkConditionResult(java.lang.Object value, java.lang.Object element, ExecutionVisitor.ConditionTest test)Checks the results of an evaluation of a condition.- Parameters:
value- the evaluation resultelement- the element to check ontest- how to test individual artifacts- Returns:
trueif the condition is fulfilled,falseelse
-
visitModelHeader
public void visitModelHeader(IResolvableModel<V,M> model) throws VilException
Visits the related model headers.- Parameters:
model- the model to be visited- Throws:
VilException- in case that visiting fails (cyclic inclusion)
-
visitModelHeader
private void visitModelHeader(IResolvableModel<V,M> model, java.util.Set<IResolvableModel<V,M>> visited) throws VilException
Visits the related model headers.- Parameters:
model- the model to be visitedvisited- the already visited models- Throws:
VilException- in case that visiting fails for some reason
-
initializeImplicitVariables
protected void initializeImplicitVariables(IResolvableModel<V,M> model) throws VilException
Initializes implicit variables of a model (before explicitly defined variables).- Parameters:
model- the model being initialized- Throws:
VilException- in case that the initialization fails, e.g., assigning values
-
setModelArgument
protected void setModelArgument(V param, java.lang.Object value) throws VilException
Defines the value of a given model/main argument and allows (by overriding) implicit (programmed) conversion of main arguments.- Parameters:
param- the model/main parameter corresponding to the argumentvalue- the actual value of the argument- Throws:
VilException- in case that setting the value fails due to type conflicts or as a constant shall be modified
-
processModelParameter
protected void processModelParameter(IResolvableModel<V,M> model) throws VilException
Processes the parameters ofmodel. CallshandleParameterInSequence(IResolvableModel, Map).- Parameters:
model- the model to be processed- Throws:
VilException- in case of execution errors
-
handleParameterInSequence
protected void handleParameterInSequence(IResolvableModel<V,M> model, java.util.Map<java.lang.String,V> varMap) throws VilException
Handles model parameters in sequence if appropriate. If and only if mapping is possible, this method shall modifyvarMapby removing assigned parameters. Otherwise, no error shall be emitted by this method. Implemented empty in this class as intended for overriding.- Parameters:
model- the model to be processedvarMap- a mapping of parameter names to implementing variable declarations, to be modified as a side effect if parameters are bound- Throws:
VilException- in case of execution errors
-
determineScriptParam
protected java.util.Map<java.lang.String,java.lang.Object> determineScriptParam(ModelCallExpression<V,M,O> call) throws VilException
Determines script parameters from a call, i.e., takes over arguments and fixes them.- Parameters:
call- the call to be executed- Returns:
- the script parameter (may be null)
- Throws:
VilException- in case of evaluation problems
-
visitModelCallExpression
protected java.lang.Object visitModelCallExpression(ModelCallExpression<V,M,O> call) throws VilException
Visits a model call expression. Currently, this method is intended to facilitate reuse and not declared in the visitor in order to avoid further template parameters etc. This method callsexecuteModelCall(IResolvableOperation).- Parameters:
call- the call to be visited- Returns:
- the result of the execution
- Throws:
VilException- in case that the execution fails
-
proceedModelCall
protected java.lang.Object proceedModelCall(O resolved, M model, IArgumentProvider arguments, boolean isPlaceholder, boolean enableParentScope) throws VilException
Performs a model call. Currently, this method is intended to facilitate reuse, in particular for VTL. This method callsexecuteModelCall(IResolvableOperation).- Parameters:
resolved- the resolved operationmodel- the containing modelarguments- the call argumentsisPlaceholder- whetherresolvedshall be treated as a placeholder operationenableParentScope- enable the parent declaration scopes for dynamic dispatch, shall not be done in case of explicit super calls due to potential endless recursion- Returns:
- the result of the execution
- Throws:
VilException- in case that the execution fails
-
evaluateDefault
private java.lang.Object evaluateDefault(VariableDeclaration decl) throws VilException
Evaluates the default value ofdecl.- Parameters:
decl- the declaration to evaluate the default value for- Returns:
- the default value or null if none was defined
- Throws:
VilException- if evaluating the default value (if defined) fails
-
assignModelParameter
protected abstract void assignModelParameter(IResolvableModel<V,M> targetModel, IResolvableModel<V,M> srcModel) throws VilException
Assigns the model parameters. Allows to use model-specific code.- Parameters:
targetModel- the target model to be executedsrcModel- the source model to take the (named, optional) parameters from- Throws:
VilException- if accessing parameters / assigning values fails
-
evaluateModelParameter
protected void evaluateModelParameter(IResolvableModel<V,M> targetModel, IResolvableModel<V,M> srcModel, int startIndex) throws VilException
Assigns the model parameters.- Parameters:
targetModel- the target model to be executedsrcModel- the source model to take the (named, optional) parameters fromstartIndex- which parameter to start from- Throws:
VilException- if accessing parameters / assigning values fails
-
dynamicDispatch
protected abstract O dynamicDispatch(O operation, java.lang.Object[] args, IArgumentProvider argumentProvider, boolean enableParentScope)
Performs the dynamic dispatch on the operation type.- Parameters:
operation- the operation to be dispatchedargs- the actual argumentsargumentProvider- access to the argument expressionsenableParentScope- enable the parent declaration scopes for dynamic dispatch, shall not be done in case of explicit super calls due to potential endless recursion- Returns:
operationor the more actual operation
-
executeModelCall
protected abstract java.lang.Object executeModelCall(O operation) throws VilException
Actually executes a model call. Basically, a subclassing visitor shall call the related visit method. Currently, this method is intended to facilitate reuse and not declared in the visitor in order to avoid further template parameters etc.- Parameters:
operation- the operation to be executed- Returns:
- the execution result
- Throws:
VilException- in case that execution fails
-
executeMain
protected java.lang.Object executeMain(M model, O operation) throws VilException
Executes the main operation. Prerequisite is that (at least the leading) parameters ofmodelare assignable to the parameters of theoperation. This must be ensured by the caller. More parameters inmodel("varargs" passed from the instantiator) are ignored.- Parameters:
model- the model to execute the operation onoperation- the operation- Returns:
- the result of the execution
- Throws:
VilException- if execution fails
-
createModelCall
protected abstract ModelCallExpression<V,M,O> createModelCall(M model, O operation, CallArgument... arguments) throws VilException
Creates a model call expression instance.- Parameters:
model- the modeloperation- the operation to be called onmodelarguments- the arguments- Returns:
- the call expression instance
- Throws:
VilException- in case of an erroneously qualified name
-
mayFail
protected boolean mayFail(java.lang.Object elt)
Returns whether a rule element may fail.- Parameters:
elt- the element to be checked- Returns:
trueif the element may fail (guard expression),falseelse
-
convertToContainer
protected java.lang.Object convertToContainer(Expression expr, java.lang.Object value, java.lang.String eltName) throws VilException
Converts the actualvalueofexprto a container if required and possible.- Parameters:
expr- the expressionvalue- the actual value of expressioneltName- the name of the language element / concept, e.g., "loop" or "map"- Returns:
- the converted
valueorvalue - Throws:
VilException- in case of conversion problems
-
getExpressionParser
protected abstract IExpressionParser<R> getExpressionParser()
Returns the actual expression parser.- Returns:
- the actual expression parser
-
-