Class BuildlangExecution
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.EvaluationVisitor
-
- net.ssehub.easy.instantiation.core.model.common.ExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.BuildlangExecution
-
- All Implemented Interfaces:
IBuildlangVisitor,IVisitor,RuleBodyExecutor,IMatchVisitor,ITerminator,IVisitor,IExpressionVisitor
public class BuildlangExecution extends ExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver> implements IBuildlangVisitor, RuleBodyExecutor, ITerminator
Executes a build language project. Please note that for full functionality,#setExpressionParser(IExpressionParser)must be called appropriately.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.ssehub.easy.instantiation.core.model.common.ExecutionVisitor
ExecutionVisitor.ConditionTest
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.Filebasestatic java.lang.StringDEFAULT_MAIN_RULEThe name of the default main rule (called "main").private booleanenableRuleElementFailedprivate RuntimeEnvironmentenvironmentprivate ExecutableRulesexecutableRulesprivate java.util.List<Rule>failedstatic ExpressionParserRegistry.ILanguage<Resolver>LANGUAGEprivate MatchResolvermatchResolverstatic java.lang.StringPARAM_CONFIGThe default configuration parameter (called "config").static java.lang.StringPARAM_SOURCEThe default source project parameter (called "source").static java.lang.StringPARAM_TARGETThe default target project parameter (called "target").private Resolverresolverprivate java.util.Stack<RuleExecutionContext>ruleStackprivate java.lang.StringstartRuleNameprivate booleanstopprivate java.util.Set<ITerminatable>terminatablesprivate ITracertracerprivate VariableFindervariableFinder
-
Constructor Summary
Constructors Modifier Constructor Description BuildlangExecution(ITracer tracer, java.io.File base, java.lang.String startRuleName, java.util.Map<java.lang.String,java.lang.Object> parameter)Creates a new execution environment.BuildlangExecution(ITracer tracer, java.io.File base, java.util.Map<java.lang.String,java.lang.Object> parameter)Creates a new execution environment.protectedBuildlangExecution(RuntimeEnvironment environment)Creates a new execution visitor for import expression evaluation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.io.Fileabsolute(java.lang.String path, java.io.File base)Makespathabsolute with respect tobaseif necessary.protected voidaddImplicitParamters(java.util.Map<java.lang.String,java.lang.Object> named)Adds additional implicit named parameters.private voidaddVariablesToFinder(Rule rule, Rule.Side side, boolean matchVariables)protected java.lang.ObjectapplyRuleBody(Rule rule, java.lang.Object[] rhsValues, RuleExecutionContext context)Determines pre- and postcondition matches and, if enabled, assigns RHS/LHS variables and executes the rule body.protected voidassignModelParameter(IResolvableModel<VariableDeclaration,Script> targetModel, IResolvableModel<VariableDeclaration,Script> 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.private voidcheckConstants(Script script)Checks the constant values for proper initialization.protected voidcheckPostconditions(RuleExecutionContext context)Checks the postconditions of therule.protected voidcleanupRuleExecution(RuleExecutionContext context)Cleans up the rule execution.private static Collection<java.lang.Object>[]createCollectionArray(int length)Creates an empty array of collections.protected ExecutableRulescreateExecutableRulesInstance()Creates an executable rules instance.private static java.util.Iterator<java.lang.Object>[]createIteratorArray(int length)Creates an empty array of iterators.protected ModelCallExpression<VariableDeclaration,Script,AbstractRule>createModelCall(Script model, AbstractRule operation, CallArgument... arguments)Creates a model call expression instance.protected RuntimeEnvironmentcreateRuntimeEnvironment()Creates the initial runtime environment.private RuleExecutionResult.StatusdetermineRhsLhsMatching(Rule rule, java.lang.Object[] rhsValues)Checks the RHS/LHS matching.protected AbstractRuledynamicDispatch(AbstractRule operation, java.lang.Object[] args, IArgumentProvider argumentProvider, boolean enableParentScope)Performs the dynamic dispatch on the operation type.private Collection<java.lang.Object>evaluate(JoinVariableDeclaration var)Evaluates the condition for a variable.private java.lang.ObjectevaluateExternalValue(VariableDeclaration var, java.lang.String value)Evaluates an external value for a givenvar.private voidevaluateJoinCombination(JoinExpression join, java.util.List<IVilType> simpleResult, java.util.List<IVilType[]> complexResult)Evaluates a join combination.protected java.lang.ObjectexecuteDefault(Script script)Executes the givenscriptvia its default entry point.private java.lang.ObjectexecuteLoop(IEnumeratingLoop loop, boolean parallelize, java.util.List<java.lang.Object> result)Executes a loop.protected java.lang.ObjectexecuteModelCall(AbstractRule rule)Actually executes a model call.java.lang.ObjectexecuteRuleBody(IRuleBlock ruleBody, RuleExecutionContext context)Executes a rule body.private java.lang.ObjectexecuteScript(Script script, RuleCallExpression start)Executes the given script starting atstart.protected IExpressionParser<Resolver>getExpressionParser()Returns the actual expression parser.RulegetFailed(int index)Returns the specified failed rule.intgetFailedCount()Returns the number of failed rules.protected intgetRuleStackSize()Returns the size of the rule stack.RuntimeEnvironmentgetRuntimeEnvironment()Returns the runtime environment (for testing).private java.io.FilegetTargetPath(Script script, java.util.Map<java.lang.String,java.lang.Object> scriptParam)Returns the target path orbase.protected ITracergetTracer()Returns the tracer instance..protected voidhandleParameterInSequence(IResolvableModel<VariableDeclaration,Script> model, java.util.Map<java.lang.String,VariableDeclaration> varMap)Handles model parameters in sequence if appropriate.private voidinitialize()Does common initializations based on already set values (requires {@link #environment) to be set properly).protected voidinitializeImplicitVariables(IResolvableModel<VariableDeclaration,Script> model)Initializes implicit variables of a model (before explicitly defined variables).(package private) booleanisOnStack(AbstractRule rule)Returns whether the givenruleis on the execution stack.private java.lang.Objectjoin(JoinExpression join)Performs the join operation.private voidloadProperties(java.io.File file, java.util.Properties prop, java.lang.String os)Loads properties fromfileintoproppossibly overriding existing properties.private static java.lang.ObjectmapResult(TypeDescriptor<?> mapType, java.util.List<java.lang.Object> result, boolean failed)Creates the actual result of executing aMapExpression.protected RuleExecutionContextpeekRuleStack()Returns the top element on the rule stack.private java.lang.StringpostprocessSystemCallArgument(java.lang.String argument)Post processes system call arguments, e.g., by removing line separators.protected booleanprepareExecution(RuleExecutionContext context)Evaluates the rule header and returns whether the rule is applicable.protected voidprocessProperties(Script script, java.io.File base)Processes theLoadProperties.voidregister(ITerminatable terminatable)Registers a terminatable.private voidregisterParameter(AbstractRule rule)Registers the parameter ofrule.voidrelease(boolean releaseDefault)Releases the resources allocated by this execution.(package private) voidresolveMatches(AbstractRule rule, Rule.Side side)Resolves rule condition matches.private ScriptresolveScript(Project project, IVersionRestriction restrictions)Resolves the script for an instantiation expression.protected booleanruleElementFailed(IRuleElement elt, RuleExecutionContext context)Is called wheneltfailed in execution, e.g., to put further information about failing into the rule executioncontext.protected booleansetEnableRuleElementFailed(boolean enableRuleElementFailed)Enables / disables failed rule elements in some situations.private voidsetJoinVariableValue(JoinExpression join, int index, java.lang.Object value)Sets the specified join variable.protected voidsetModelArgument(VariableDeclaration param, java.lang.Object value)Defines the value of a given model/main argument and allows (by overriding) implicit (programmed) conversion of main arguments.private voidsetModelArgument(IResolvableModel<VariableDeclaration,Script> srcModel, int index, java.lang.String name)Sets a model argument.voidstop()Stops the execution, e.g., within endless loops constructed by the user.private static java.lang.Class<?>[]types(JoinExpression join)Returns the types to be used to parameterize the return type.voidunregister(ITerminatable terminatable)Unregisters a terminatable.java.lang.ObjectvisitAlternativeExpression(AlternativeExpression alt)Visits an alternative.java.lang.ObjectvisitArtifactMatchExpression(ArtifactMatchExpression expression)Visits an artifact match expression.java.lang.ObjectvisitBooleanMatchExpression(BooleanMatchExpression expression)Visits a boolean match expression.java.lang.ObjectvisitCollectionMatchExpression(CollectionMatchExpression expression)Visits a collection match expression.java.lang.ObjectvisitCompound(Compound compound)Visits a compound.java.lang.ObjectvisitCompoundMatchExpression(CompoundMatchExpression expression)Visits a compound match expression.java.lang.ObjectvisitConstantExpression(ConstantExpression cst)Visits a constant node.java.lang.ObjectvisitForStatement(ForStatement stmt)Visits a for statement.java.lang.ObjectvisitInstantiateExpression(InstantiateExpression inst)Visits an instantiate expression.java.lang.ObjectvisitJoinExpression(JoinExpression ex)Visits a join expression.java.lang.ObjectvisitJoinVariableDeclaration(JoinVariableDeclaration decl)Visits a join variable declaration.java.lang.ObjectvisitLoadProperties(LoadProperties properties)Visits a load properties directive.java.lang.ObjectvisitMapExpression(MapExpression map)Visits a map expression.java.lang.ObjectvisitPathMatchExpression(PathMatchExpression expression)Visits a path match expression.java.lang.ObjectvisitResolvableOperationCallExpression(ResolvableOperationCallExpression ex)Visits resolvable operation call expression (function pointer call).java.lang.ObjectvisitRule(Rule rule)Visits a rule.java.lang.ObjectvisitRule(VtlRule rule)Visits a VTL mapping rule.java.lang.ObjectvisitRuleCallExpression(RuleCallExpression ex)Visits a rule call expression.java.lang.ObjectvisitScript(Script script)Visits a script.java.lang.ObjectvisitStrategyCallExpression(StrategyCallExpression call)Visits a strategy call node.java.lang.ObjectvisitStrategyCallExpressionImpl(StrategyCallExpression call)Implements the strategy call execution of an executable call.java.lang.ObjectvisitStringMatchExpression(StringMatchExpression expression)Visits a string match expression.java.lang.ObjectvisitTypedef(Typedef typedef)Visits a typedef.java.lang.ObjectvisitWhileStatement(WhileStatement stmt)Visits a while statement.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.common.ExecutionVisitor
convertToContainer, determineScriptParam, doAssignmentConversions, enableArtifactAutoStoreOnParameters, evaluateModelParameter, executeMain, getParameter, getParameterCount, hasParameter, mayFail, notifyValueDefined, proceedModelCall, processModelParameter, replaceParameter, visitAdvice, visitExpressionStatement, visitModelCallExpression, visitModelHeader, visitVariableDeclaration
-
Methods inherited from class net.ssehub.easy.instantiation.core.model.expressions.EvaluationVisitor
appendInCompositeExpression, evaluateContentExpression, lastContentReplaceEmptyLine, visitCallExpression, visitCompositeExpression, visitContainerInitializerExpression, visitExpression, visitExpressionEvaluator, visitFieldAccessExpression, visitMultiAndExpression, visitParenthesisExpression, 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.expressions.IExpressionVisitor
visitCallExpression, visitCompositeExpression, visitContainerInitializerExpression, visitExpression, visitExpressionEvaluator, visitFieldAccessExpression, visitMultiAndExpression, visitParenthesisExpression, visitResolvableOperationExpression, visitStringExpression, visitValueAssignmentExpression, visitVariableExpression, visitVarModelIdentifierExpression, visitVilTypeExpression
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.common.IVisitor
visitAdvice, visitExpressionStatement, visitVariableDeclaration
-
-
-
-
Field Detail
-
LANGUAGE
public static final ExpressionParserRegistry.ILanguage<Resolver> LANGUAGE
-
PARAM_SOURCE
public static final java.lang.String PARAM_SOURCE
The default source project parameter (called "source").- See Also:
- Constant Field Values
-
PARAM_TARGET
public static final java.lang.String PARAM_TARGET
The default target project parameter (called "target").- See Also:
- Constant Field Values
-
PARAM_CONFIG
public static final java.lang.String PARAM_CONFIG
The default configuration parameter (called "config").- See Also:
- Constant Field Values
-
DEFAULT_MAIN_RULE
public static final java.lang.String DEFAULT_MAIN_RULE
The name of the default main rule (called "main").- See Also:
- Constant Field Values
-
environment
private RuntimeEnvironment environment
-
tracer
private ITracer tracer
-
base
private java.io.File base
-
startRuleName
private java.lang.String startRuleName
-
failed
private java.util.List<Rule> failed
-
matchResolver
private MatchResolver matchResolver
-
variableFinder
private VariableFinder variableFinder
-
executableRules
private ExecutableRules executableRules
-
ruleStack
private java.util.Stack<RuleExecutionContext> ruleStack
-
resolver
private Resolver resolver
-
enableRuleElementFailed
private boolean enableRuleElementFailed
-
stop
private boolean stop
-
terminatables
private java.util.Set<ITerminatable> terminatables
-
-
Constructor Detail
-
BuildlangExecution
public BuildlangExecution(ITracer tracer, java.io.File base, java.util.Map<java.lang.String,java.lang.Object> parameter)
Creates a new execution environment.- Parameters:
tracer- the tracerbase- the base directory for making files absoluteparameter- the top-level parameter for the script to be executed
-
BuildlangExecution
public BuildlangExecution(ITracer tracer, java.io.File base, java.lang.String startRuleName, java.util.Map<java.lang.String,java.lang.Object> parameter)
Creates a new execution environment.- Parameters:
tracer- the tracerbase- the base directory for making files absolutestartRuleName- the name of the start rule; if multiple source projects are given, as a convention the first one shall the top-level project that needs to be executed.parameter- the top-level parameter for the script to be executed
-
BuildlangExecution
protected BuildlangExecution(RuntimeEnvironment environment)
Creates a new execution visitor for import expression evaluation.- Parameters:
environment- the runtime environment to be used for expression evaluation
-
-
Method Detail
-
stop
public void stop()
Stops the execution, e.g., within endless loops constructed by the user.
-
setEnableRuleElementFailed
protected boolean setEnableRuleElementFailed(boolean enableRuleElementFailed)
Enables / disables failed rule elements in some situations.- Parameters:
enableRuleElementFailed- whether rule elements shall be enabled- Returns:
- the old state
-
createRuntimeEnvironment
protected RuntimeEnvironment createRuntimeEnvironment()
Creates the initial runtime environment.- Returns:
- the initial runtime environment
-
getRuntimeEnvironment
public RuntimeEnvironment getRuntimeEnvironment()
Description copied from class:ExecutionVisitorReturns the runtime environment (for testing).- Overrides:
getRuntimeEnvironmentin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- Returns:
- the runtime environment
-
getTracer
protected ITracer getTracer()
Description copied from class:ExecutionVisitorReturns the tracer instance..- Overrides:
getTracerin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- Returns:
- the tracer instance
-
getExpressionParser
protected IExpressionParser<Resolver> getExpressionParser()
Description copied from class:ExecutionVisitorReturns the actual expression parser.- Specified by:
getExpressionParserin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- Returns:
- the actual expression parser
-
peekRuleStack
protected RuleExecutionContext peekRuleStack()
Returns the top element on the rule stack.- Returns:
- the top element
-
getRuleStackSize
protected int getRuleStackSize()
Returns the size of the rule stack.- Returns:
- the size of the rule stack
-
initialize
private void initialize()
Does common initializations based on already set values (requires {@link #environment) to be set properly).
-
createExecutableRulesInstance
protected ExecutableRules createExecutableRulesInstance()
Creates an executable rules instance.- Returns:
- the created instance
-
absolute
private static java.io.File absolute(java.lang.String path, java.io.File base)Makespathabsolute with respect tobaseif necessary.- Parameters:
path- the file to be made absolutebase- the base path- Returns:
- the absolute file
-
getFailedCount
public int getFailedCount()
Returns the number of failed rules.- Returns:
- the number of failed rules
-
getFailed
public Rule getFailed(int index)
Returns the specified failed rule.- Parameters:
index- the index of the failed rule- Returns:
- the failed rule
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getFailedCount()
-
checkConditionResult
protected boolean checkConditionResult(java.lang.Object value, java.lang.Object element, ExecutionVisitor.ConditionTest test)Checks the results of an evaluation of a condition.- Overrides:
checkConditionResultin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- Parameters:
value- the evaluation resultelement- the element to check ontest- how to test individual artifacts- Returns:
trueif the condition is fulfilled,falseelse
-
visitScript
public java.lang.Object visitScript(Script script) throws VilException
Description copied from interface:IVisitorVisits a script.- Specified by:
visitScriptin interfaceIVisitor- Parameters:
script- the project instance- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
executeScript
private java.lang.Object executeScript(Script script, RuleCallExpression start) throws VilException
Executes the given script starting atstart.- Parameters:
script- the script to be executedstart- the start rule (may be null to determine main)- Returns:
- the result of the execution
- Throws:
VilException- if the execution fails
-
release
public void release(boolean releaseDefault)
Description copied from class:ExecutionVisitorReleases the resources allocated by this execution.- Overrides:
releasein classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- 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.
-
executeDefault
protected java.lang.Object executeDefault(Script script) throws VilException
Executes the givenscriptvia its default entry point.- Parameters:
script- the script to be executed- Returns:
- the execution result
- Throws:
VilException- if execution fails
-
getTargetPath
private java.io.File getTargetPath(Script script, java.util.Map<java.lang.String,java.lang.Object> scriptParam)
Returns the target path orbase.- Parameters:
script- the script to obtain the target path fromscriptParam- the script parameters to consider (additional, may be null)- Returns:
- the path to the target project or
baseif not found
-
initializeImplicitVariables
protected void initializeImplicitVariables(IResolvableModel<VariableDeclaration,Script> model) throws VilException
Description copied from class:ExecutionVisitorInitializes implicit variables of a model (before explicitly defined variables).- Overrides:
initializeImplicitVariablesin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- Parameters:
model- the model being initialized- Throws:
VilException- in case that the initialization fails, e.g., assigning values
-
createModelCall
protected ModelCallExpression<VariableDeclaration,Script,AbstractRule> createModelCall(Script model, AbstractRule operation, CallArgument... arguments) throws VilException
Description copied from class:ExecutionVisitorCreates a model call expression instance.- Specified by:
createModelCallin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- 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
-
setModelArgument
protected void setModelArgument(VariableDeclaration param, java.lang.Object value) throws VilException
Description copied from class:ExecutionVisitorDefines the value of a given model/main argument and allows (by overriding) implicit (programmed) conversion of main arguments.- Overrides:
setModelArgumentin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- 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
-
processProperties
protected void processProperties(Script script, java.io.File base) throws VilException
Processes theLoadProperties.- Parameters:
script- the script to process the properties forbase- the base path to make relative paths absolute- Throws:
VilException- in case that something goes wrong
-
loadProperties
private void loadProperties(java.io.File file, java.util.Properties prop, java.lang.String os) throws VilExceptionLoads properties fromfileintoproppossibly overriding existing properties.- Parameters:
file- the file nameprop- the loaded properties (to be modified as a side effect)os- if not null to be inserted after the last "." with a following ".". If file not exists, no exception will be thrown.- Throws:
VilException- in case of loading problems
-
evaluateExternalValue
private java.lang.Object evaluateExternalValue(VariableDeclaration var, java.lang.String value) throws VilException
Evaluates an external value for a givenvar.- Parameters:
var- the variable to evaluate the value forvalue- the external value- Returns:
- the actual value for
var - Throws:
VilException- in case that conversion does not work
-
checkConstants
private void checkConstants(Script script) throws VilException
Checks the constant values for proper initialization.- Parameters:
script- the project to process the properties for- Throws:
VilException- in case that something goes wrong
-
postprocessSystemCallArgument
private java.lang.String postprocessSystemCallArgument(java.lang.String argument)
Post processes system call arguments, e.g., by removing line separators.- Parameters:
argument- the argument to be processed- Returns:
- the processed argument
-
visitStrategyCallExpression
public java.lang.Object visitStrategyCallExpression(StrategyCallExpression call) throws VilException
Description copied from interface:IVisitorVisits a strategy call node.- Specified by:
visitStrategyCallExpressionin interfaceIVisitor- Parameters:
call- the node- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitStrategyCallExpressionImpl
public java.lang.Object visitStrategyCallExpressionImpl(StrategyCallExpression call) throws VilException
Implements the strategy call execution of an executable call.- Parameters:
call- the call to execute- Returns:
- the execution result
- Throws:
VilException- in case of execution problems
-
addImplicitParamters
protected void addImplicitParamters(java.util.Map<java.lang.String,java.lang.Object> named)
Adds additional implicit named parameters.- Overrides:
addImplicitParamtersin classEvaluationVisitor- Parameters:
named- the named parameters
-
visitLoadProperties
public java.lang.Object visitLoadProperties(LoadProperties properties) throws VilException
Description copied from interface:IVisitorVisits a load properties directive.- Specified by:
visitLoadPropertiesin interfaceIVisitor- Parameters:
properties- the load properties representation- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
registerParameter
private void registerParameter(AbstractRule rule) throws VilException
Registers the parameter ofrule.- Parameters:
rule- the rule to register the parameter for- Throws:
VilException- in case of any execution error
-
addVariablesToFinder
private void addVariablesToFinder(Rule rule, Rule.Side side, boolean matchVariables)
- Parameters:
rule- the rule to take the variables fromside- the side to considermatchVariables- shall match variables (entire expression) or related loop variables be added
-
applyRuleBody
protected java.lang.Object applyRuleBody(Rule rule, java.lang.Object[] rhsValues, RuleExecutionContext context) throws VilException
Determines pre- and postcondition matches and, if enabled, assigns RHS/LHS variables and executes the rule body. Actually, this method has two purposes, namely, testing for enabling pre- and post-condition matches as well as executing the rule body, in case of RHS/LHS matches in iterative fashion. We combined both functionalities as they are closely related and modifications to the matching would otherwise need modifications to multple algorithms. This also prevents storing the matching (outdated/non-existing) pairs in memory.- Parameters:
rule- the rule to be executed (contains the rule body)rhsValues- the evaluated RHS conditions (values, determined by visiting the RHS matching expressions and therefore are Objects)context- the rule execution context, may be null if actually no execution of the rule body shall be performed and just pre-postcondition matches shall be tested- Returns:
- depending on
Rule.returnActualValue(), the actual body evaluation result or the execution status - Throws:
VilException- in case of serious execution problems
-
executeRuleBody
public java.lang.Object executeRuleBody(IRuleBlock ruleBody, RuleExecutionContext context) throws VilException
Description copied from interface:RuleBodyExecutorExecutes a rule body.- Specified by:
executeRuleBodyin interfaceRuleBodyExecutor- Parameters:
ruleBody- the rule bodycontext- the rule execution context- Returns:
- the execution status or the value of the block depending on the type of the rule
- Throws:
VilException- in case of serious execution problems
-
ruleElementFailed
protected boolean ruleElementFailed(IRuleElement elt, RuleExecutionContext context) throws VilException
Is called wheneltfailed in execution, e.g., to put further information about failing into the rule executioncontext.- Parameters:
elt- the failing elementcontext- the rule execution context- Returns:
trueif the failure shall be recorded,falseif the failure shall be ignored- Throws:
VilException- in case that the evaluation of the failed element fails
-
resolveMatches
void resolveMatches(AbstractRule rule, Rule.Side side) throws VilException
Resolves rule condition matches.- Parameters:
rule- the rule to considerside- the side of the rule- Throws:
VilException- in case of resolution problems
-
isOnStack
boolean isOnStack(AbstractRule rule)
Returns whether the givenruleis on the execution stack.- Parameters:
rule- the rule to be tested- Returns:
trueif it is on the actual execution stack,falseelse
-
determineRhsLhsMatching
private RuleExecutionResult.Status determineRhsLhsMatching(Rule rule, java.lang.Object[] rhsValues) throws VilException
Checks the RHS/LHS matching.- Parameters:
rule- the rule the matching shall be done forrhsValues- an already initialized array for carrying the primary evaluation/matching results of the RHS matching expression(s)- Returns:
- the status of the matching, i.e.,
RuleExecutionResult.Status.SUCCESSif execution can go on,RuleExecutionResult.Status.NOT_APPLICABLEif the rule shall not be applied,RuleExecutionResult.Status.FAILif already the (execution of the preconditions) fails and, thus, the entire rule shall fail - Throws:
VilException- in case of evaluating an LHS/RHS expression fails
-
visitRule
public java.lang.Object visitRule(Rule rule) throws VilException
Description copied from interface:IVisitorVisits a rule.- Specified by:
visitRulein interfaceIVisitor- Parameters:
rule- the rule- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitRule
public java.lang.Object visitRule(VtlRule rule) throws VilException
Description copied from interface:IVisitorVisits a VTL mapping rule.- Specified by:
visitRulein interfaceIVisitor- Parameters:
rule- the rule- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
prepareExecution
protected boolean prepareExecution(RuleExecutionContext context) throws VilException
Evaluates the rule header and returns whether the rule is applicable. CallcheckPostconditions(RuleExecutionContext)afterwards if required andcleanupRuleExecution(RuleExecutionContext)at the end of the evaluation.- Parameters:
context- the rule execution context, to be modified as a side effect (at least thestatus, possibly also theRuleExecutionContext.getRhsValues()RHS values).- Returns:
trueif theruleis applicable,falseelse- Throws:
VilException- in case of execution / evaluation problems
-
checkPostconditions
protected void checkPostconditions(RuleExecutionContext context) throws VilException
Checks the postconditions of therule. CallprepareExecution(RuleExecutionContext)before andcleanupRuleExecution(RuleExecutionContext)after.- Parameters:
context- the execution context, to be modified as a side effect with respect to thestatus- Throws:
VilException- in case of execution / evaluation problems
-
cleanupRuleExecution
protected void cleanupRuleExecution(RuleExecutionContext context) throws VilException
Cleans up the rule execution.- Parameters:
context- the execution context- Throws:
VilException- in case of execution problems
-
visitRuleCallExpression
public java.lang.Object visitRuleCallExpression(RuleCallExpression ex) throws VilException
Description copied from interface:IVisitorVisits a rule call expression.- Specified by:
visitRuleCallExpressionin interfaceIVisitor- Parameters:
ex- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
executeModelCall
protected java.lang.Object executeModelCall(AbstractRule rule) throws VilException
Description copied from class:ExecutionVisitorActually 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.- Specified by:
executeModelCallin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- Parameters:
rule- the operation to be executed- Returns:
- the execution result
- Throws:
VilException- in case that execution fails
-
visitPathMatchExpression
public java.lang.Object visitPathMatchExpression(PathMatchExpression expression) throws VilException
Description copied from interface:IMatchVisitorVisits a path match expression.- Specified by:
visitPathMatchExpressionin interfaceIMatchVisitor- Parameters:
expression- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitBooleanMatchExpression
public java.lang.Object visitBooleanMatchExpression(BooleanMatchExpression expression) throws VilException
Description copied from interface:IMatchVisitorVisits a boolean match expression.- Specified by:
visitBooleanMatchExpressionin interfaceIMatchVisitor- Parameters:
expression- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitStringMatchExpression
public java.lang.Object visitStringMatchExpression(StringMatchExpression expression) throws VilException
Description copied from interface:IMatchVisitorVisits a string match expression.- Specified by:
visitStringMatchExpressionin interfaceIMatchVisitor- Parameters:
expression- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitArtifactMatchExpression
public java.lang.Object visitArtifactMatchExpression(ArtifactMatchExpression expression) throws VilException
Description copied from interface:IMatchVisitorVisits an artifact match expression.- Specified by:
visitArtifactMatchExpressionin interfaceIMatchVisitor- Parameters:
expression- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitCollectionMatchExpression
public java.lang.Object visitCollectionMatchExpression(CollectionMatchExpression expression) throws VilException
Description copied from interface:IMatchVisitorVisits a collection match expression.- Specified by:
visitCollectionMatchExpressionin interfaceIMatchVisitor- Parameters:
expression- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitJoinExpression
public java.lang.Object visitJoinExpression(JoinExpression ex) throws VilException
Description copied from interface:IVisitorVisits a join expression.- Specified by:
visitJoinExpressionin interfaceIVisitor- Parameters:
ex- the join expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
evaluate
private Collection<java.lang.Object> evaluate(JoinVariableDeclaration var) throws VilException
Evaluates the condition for a variable.- Parameters:
var- the variable to be evaluated- Returns:
- the evaluation result
- Throws:
VilException- in case of expression evaluation errors
-
createCollectionArray
private static Collection<java.lang.Object>[] createCollectionArray(int length)
Creates an empty array of collections.- Parameters:
length- the length of the array to be created- Returns:
- the array instance
-
createIteratorArray
private static java.util.Iterator<java.lang.Object>[] createIteratorArray(int length)
Creates an empty array of iterators.- Parameters:
length- the length of the array to be created- Returns:
- the array instance
-
join
private java.lang.Object join(JoinExpression join) throws VilException
Performs the join operation.- Parameters:
join- the join expression to be evaluated- Returns:
- the join result
- Throws:
VilException- in case of execution problems
-
setJoinVariableValue
private void setJoinVariableValue(JoinExpression join, int index, java.lang.Object value) throws VilException
Sets the specified join variable.- Parameters:
join- the join expressionindex- the index of the variablevalue- the value- Throws:
VilException- in case that setting the variable fails
-
evaluateJoinCombination
private void evaluateJoinCombination(JoinExpression join, java.util.List<IVilType> simpleResult, java.util.List<IVilType[]> complexResult) throws VilException
Evaluates a join combination.- Parameters:
join- the join to be evaluatedsimpleResult- modified in case of 1-sided joinscomplexResult- modified in case of multi-sided joins- Throws:
VilException- in case that the evaluation fails
-
types
private static java.lang.Class<?>[] types(JoinExpression join)
Returns the types to be used to parameterize the return type.- Parameters:
join- the join expression- Returns:
- the types
-
visitJoinVariableDeclaration
public java.lang.Object visitJoinVariableDeclaration(JoinVariableDeclaration decl) throws VilException
Description copied from interface:IVisitorVisits a join variable declaration.- Specified by:
visitJoinVariableDeclarationin interfaceIVisitor- Parameters:
decl- the declaration- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitAlternativeExpression
public java.lang.Object visitAlternativeExpression(AlternativeExpression alt) throws VilException
Description copied from interface:IVisitorVisits an alternative.- Specified by:
visitAlternativeExpressionin interfaceIVisitor- Parameters:
alt- the alternative- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitMapExpression
public java.lang.Object visitMapExpression(MapExpression map) throws VilException
Description copied from interface:IVisitorVisits a map expression.- Specified by:
visitMapExpressionin interfaceIVisitor- Parameters:
map- the expression to be visited- Returns:
- the result of visiting the given expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
executeLoop
private java.lang.Object executeLoop(IEnumeratingLoop loop, boolean parallelize, java.util.List<java.lang.Object> result) throws VilException
Executes a loop.- Parameters:
loop- the loop to be executedparallelize- whether execution may happen in parallelresult- the result collector (may be null for no collection)- Returns:
- the last statement execution result
- Throws:
VilException- in case that expression evaluation fails
-
mapResult
private static java.lang.Object mapResult(TypeDescriptor<?> mapType, java.util.List<java.lang.Object> result, boolean failed)
Creates the actual result of executing aMapExpression.- Parameters:
mapType- the type of the map expressionresult- the collected results (may be null iftypeisTypeDescriptor#VOID)failed- whether the actual execution failed- Returns:
- the return object for the map
-
visitConstantExpression
public java.lang.Object visitConstantExpression(ConstantExpression cst) throws VilException
Description copied from interface:IExpressionVisitorVisits a constant node.- Specified by:
visitConstantExpressionin interfaceIExpressionVisitor- Overrides:
visitConstantExpressionin classEvaluationVisitor- Parameters:
cst- the node- Returns:
- the result of visiting this expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
dynamicDispatch
protected AbstractRule dynamicDispatch(AbstractRule operation, java.lang.Object[] args, IArgumentProvider argumentProvider, boolean enableParentScope)
Description copied from class:ExecutionVisitorPerforms the dynamic dispatch on the operation type.- Specified by:
dynamicDispatchin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- 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
-
handleParameterInSequence
protected void handleParameterInSequence(IResolvableModel<VariableDeclaration,Script> model, java.util.Map<java.lang.String,VariableDeclaration> varMap) throws VilException
Description copied from class:ExecutionVisitorHandles 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.- Overrides:
handleParameterInSequencein classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- 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
-
assignModelParameter
protected void assignModelParameter(IResolvableModel<VariableDeclaration,Script> targetModel, IResolvableModel<VariableDeclaration,Script> srcModel) throws VilException
Description copied from class:ExecutionVisitorAssigns the model parameters. Allows to use model-specific code.- Specified by:
assignModelParameterin classExecutionVisitor<Script,AbstractRule,VariableDeclaration,Resolver>- 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
-
setModelArgument
private void setModelArgument(IResolvableModel<VariableDeclaration,Script> srcModel, int index, java.lang.String name) throws VilException
Sets a model argument.- Parameters:
srcModel- the model to take the parameter fromindex- the index of the parameter to modify (for sequence-based assignment)name- the name of the parameter to modify (to retrieve the value, but also for name-based assignment)- Throws:
VilException- in case that assigning the parameter fails
-
resolveScript
private Script resolveScript(Project project, IVersionRestriction restrictions) throws VilException
Resolves the script for an instantiation expression.- Parameters:
project- the project to resolve the script onrestrictions- the version restrictions (may be null)- Returns:
- the resolved script
- Throws:
VilException- in case that the version is not valid or that the script cannot be found
-
visitInstantiateExpression
public java.lang.Object visitInstantiateExpression(InstantiateExpression inst) throws VilException
Description copied from interface:IVisitorVisits an instantiate expression.- Specified by:
visitInstantiateExpressionin interfaceIVisitor- Parameters:
inst- the instantiation expression- Returns:
- the result of visiting the given expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitCompoundMatchExpression
public java.lang.Object visitCompoundMatchExpression(CompoundMatchExpression expression) throws VilException
Description copied from interface:IMatchVisitorVisits a compound match expression.- Specified by:
visitCompoundMatchExpressionin interfaceIMatchVisitor- Parameters:
expression- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitResolvableOperationCallExpression
public java.lang.Object visitResolvableOperationCallExpression(ResolvableOperationCallExpression ex) throws VilException
Description copied from interface:IExpressionVisitorVisits resolvable operation call expression (function pointer call).- Specified by:
visitResolvableOperationCallExpressionin interfaceIExpressionVisitor- Overrides:
visitResolvableOperationCallExpressionin classEvaluationVisitor- Parameters:
ex- the expression- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitTypedef
public java.lang.Object visitTypedef(Typedef typedef) throws VilException
Description copied from interface:IVisitorVisits a typedef.- Specified by:
visitTypedefin interfaceIVisitor- Parameters:
typedef- the typedef- Returns:
- the result of visiting (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitWhileStatement
public java.lang.Object visitWhileStatement(WhileStatement stmt) throws VilException
Description copied from interface:IVisitorVisits a while statement.- Specified by:
visitWhileStatementin interfaceIVisitor- Parameters:
stmt- the statement to be visited- Returns:
- the result of visiting the given expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
visitForStatement
public java.lang.Object visitForStatement(ForStatement stmt) throws VilException
Description copied from interface:IVisitorVisits a for statement.- Specified by:
visitForStatementin interfaceIVisitor- Parameters:
stmt- the statement to be visited- Returns:
- the result of visiting the given expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
register
public void register(ITerminatable terminatable)
Description copied from interface:ITerminatorRegisters a terminatable.- Specified by:
registerin interfaceITerminator- Parameters:
terminatable- the terminatable
-
unregister
public void unregister(ITerminatable terminatable)
Description copied from interface:ITerminatorUnregisters a terminatable.- Specified by:
unregisterin interfaceITerminator- Parameters:
terminatable- the terminatable
-
visitCompound
public java.lang.Object visitCompound(Compound compound) throws VilException
Description copied from interface:IVisitorVisits a compound.- Specified by:
visitCompoundin interfaceIVisitor- Parameters:
compound- the compound- Returns:
- the result of visiting (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
-