Class TemplateLangExecution

    • Field Detail

      • DEFAULT_MAIN_TEMPLATE

        public static final java.lang.String DEFAULT_MAIN_TEMPLATE
        The name of the default main template (called "main").
        See Also:
        Constant Field Values
      • PARAM_CONFIG

        public static final java.lang.String PARAM_CONFIG
        Denotes the default name of the configuration parameter (may be overwritten by user values).
        See Also:
        Constant Field Values
      • PARAM_TARGET

        public static final java.lang.String PARAM_TARGET
        Denotes the default name of the target artifact parameter (may be overwritten by user values).
        See Also:
        Constant Field Values
      • INTERNAL_PARAM_PREFIX

        public static final java.lang.String INTERNAL_PARAM_PREFIX
        Denotes a prefix for internal parameter which must be set in addition.
        See Also:
        Constant Field Values
      • PARAM_CONFIG_SURE

        public static final java.lang.String PARAM_CONFIG_SURE
        Denotes the default name of the configuration parameter always containing the source configuration.
        See Also:
        Constant Field Values
      • PARAM_TARGET_SURE

        public static final java.lang.String PARAM_TARGET_SURE
        Denotes the default name of the target artifact parameter always containing the target artifact.
        See Also:
        Constant Field Values
      • DEFAULT_EXTENSIONS

        private static final java.util.List<JavaExtension> DEFAULT_EXTENSIONS
      • mainOut

        private java.io.Writer mainOut
      • out

        private java.io.PrintWriter out
      • mainName

        private java.lang.String mainName
      • stop

        private boolean stop
      • contentNestingLevel

        private int contentNestingLevel
      • lastContentNestingLevel

        private int lastContentNestingLevel
      • lastContentFormatted

        private boolean lastContentFormatted
      • defContentStack

        private java.util.Stack<java.lang.String> defContentStack
    • Constructor Detail

      • TemplateLangExecution

        public TemplateLangExecution​(ITracer tracer,
                                     java.io.Writer out,
                                     java.util.Map<java.lang.String,​java.lang.Object> parameter)
        Creates a new evaluation visitor.
        Parameters:
        tracer - the tracer instance for testing
        out - where to put the output to
        parameter - the top-level parameter for the script to be executed
      • TemplateLangExecution

        public TemplateLangExecution​(ITracer tracer,
                                     java.io.Writer out,
                                     java.lang.String mainName,
                                     java.util.Map<java.lang.String,​java.lang.Object> parameter)
        Creates a new evaluation visitor.
        Parameters:
        tracer - the tracer instance for testing
        out - where to put the output to
        mainName - the name of the sub-template to be executed
        parameter - the top-level parameter for the script to be executed
      • TemplateLangExecution

        TemplateLangExecution​(RuntimeEnvironment environment)
        Creates a new execution visitor for import expression evaluation.
        Parameters:
        environment - the runtime environment to be used for expression evaluation
    • Method Detail

      • release

        public void release​(boolean releaseDefault)
        Description copied from class: ExecutionVisitor
        Releases the resources allocated by this execution.
        Overrides:
        release in class ExecutionVisitor<Template,​Def,​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.
      • registerDefaultExtension

        public static void registerDefaultExtension​(java.lang.Class<?> extension)
        Register a default Java extension.
        Parameters:
        extension - the extension to be registered
      • getDefaultExtensionCount

        public static int getDefaultExtensionCount()
        Returns the number of default extensions.
        Returns:
        the number of default extensions
      • getDefaultExtension

        public static JavaExtension getDefaultExtension​(int index)
        Returns the specified default extension.
        Parameters:
        index - the 0-based index of the default extension
        Returns:
        the default extension
        Throws:
        java.lang.IndexOutOfBoundsException - in case that index < 0 || index >=getDefaultExtensionCount()
      • visitTemplate

        public java.lang.Object visitTemplate​(Template template)
                                       throws VilException
        Description copied from interface: IVisitor
        Visits a template.
        Specified by:
        visitTemplate in interface IVisitor
        Parameters:
        template - the template to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitDef

        public java.lang.Object visitDef​(Def def)
                                  throws VilException
        Description copied from interface: IVisitor
        Visits a sub-template definition.
        Specified by:
        visitDef in interface IVisitor
        Parameters:
        def - the sub-template definition to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • increaseIndentation

        private void increaseIndentation​(ITemplateElement element)
        Increases the current indentation level depending on the specified element. This information is required for content formatting.
        Parameters:
        element - the element to be considered
      • decreaseIndentation

        private void decreaseIndentation​(ITemplateElement element)
        Decreases the current indentation level depending on the specified element. This information is required for content formatting.
        Parameters:
        element - the element to be considered
      • visitTemplateBlock

        public java.lang.Object visitTemplateBlock​(TemplateBlock block)
                                            throws VilException
        Description copied from interface: IVisitor
        Visits a template block.
        Specified by:
        visitTemplateBlock in interface IVisitor
        Parameters:
        block - the template block to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitAlternative

        public java.lang.Object visitAlternative​(AlternativeStatement alternative)
                                          throws VilException
        Description copied from interface: IVisitor
        Visits an alternative statement.
        Specified by:
        visitAlternative in interface IVisitor
        Parameters:
        alternative - the alternative to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • getSeparatorFromExpression

        private java.lang.String getSeparatorFromExpression​(Expression expression)
                                                     throws VilException
        Turns the expression into a separator.
        Parameters:
        expression - the expression (may be null)
        Returns:
        the separator (or null)
        Throws:
        VilException - in case of evaluation problems
      • visitLoop

        public java.lang.Object visitLoop​(LoopStatement loop)
                                   throws VilException
        Description copied from interface: IVisitor
        Visits a loop statement.
        Specified by:
        visitLoop in interface IVisitor
        Parameters:
        loop - the loop statement to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • checkContentStatement

        private java.lang.Object checkContentStatement​(java.lang.Object currentValue,
                                                       java.lang.Object noValue,
                                                       ITemplateElement check)
        Checks the current value for the need of correction with respect to the last content statement.
        Parameters:
        currentValue - the current value
        noValue - the object indicating no value in this context
        check - the template element/statement to check for a content statement
        Returns:
        currentValue or EMPTY_CONTENT
      • checkContentStatement

        private java.lang.Object checkContentStatement​(java.lang.Object currentValue,
                                                       java.lang.Object noValue,
                                                       boolean isContentStatement)
        Checks the current value for the need of correction with respect to the last content statement.
        Parameters:
        currentValue - the current value
        noValue - the object indicating no value in this context
        isContentStatement - whether the relevant element is a content statement
        Returns:
        currentValue or EMPTY_CONTENT
      • isContentStatement

        private static final boolean isContentStatement​(ITemplateElement elt)
        Returns whether the template element or the last statement within is a content statement.
        Parameters:
        elt - the element (may be null)
        Returns:
        true for content statement, false else (also if elt is null)
      • appendContent

        private void appendContent​(java.lang.String string)
        Adds content to the current top element of defContentStack.
        Parameters:
        string - the string to add to the current content.
      • visitSwitch

        public java.lang.Object visitSwitch​(SwitchStatement swtch)
                                     throws VilException
        Description copied from interface: IVisitor
        Visits a switch statement.
        Specified by:
        visitSwitch in interface IVisitor
        Parameters:
        swtch - the switch statement to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • equals

        private boolean equals​(java.lang.Object condValue,
                               java.lang.Object exprValue)
        Checks for equality among the given condValue (condition value) and the given exprValue, whereby exprValue may be an IvmlElement and, thus, implicitly casted to the right value. This method is intended where common object values need to be compared and no VIL/VTL casts may happen.
        Parameters:
        condValue - the condition value
        exprValue - the expression value
        Returns:
        true if the values are equal false else
      • visitContentStatement

        public java.lang.Object visitContentStatement​(ContentStatement cnt)
                                               throws VilException
        Description copied from interface: IVisitor
        Visits a content statement.
        Specified by:
        visitContentStatement in interface IVisitor
        Parameters:
        cnt - the content statement
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • lastContentReplaceEmptyLine

        protected boolean lastContentReplaceEmptyLine()
        Description copied from class: EvaluationVisitor
        Returns whether the last content commands that empty lines (itself empty, following line breaks) shall be removed.
        Overrides:
        lastContentReplaceEmptyLine in class EvaluationVisitor
        Returns:
        true for remove, false else
      • cleanLineEnd

        private static java.lang.String cleanLineEnd​(java.lang.String content,
                                                     boolean includeIndentation)
        Removes the empty line marker EMPTY_CONTENT and considers surrounding indentation for removal.
        Parameters:
        content - the content to be considered
        includeIndentation - whether indentation shall be taken into account
        Returns:
        the modified content
      • appendInCompositeExpression

        protected java.lang.String appendInCompositeExpression​(java.lang.String s1,
                                                               Expression e1,
                                                               java.lang.Object v1,
                                                               java.lang.String s2,
                                                               Expression e2)
        Description copied from class: EvaluationVisitor
        Appends s2 to s2 originating from the respective expressions. This allows to potentially consider indentation formatting.
        Overrides:
        appendInCompositeExpression in class EvaluationVisitor
        Parameters:
        s1 - the first string
        e1 - the expression causing s1
        v1 - the value causting s1
        s2 - the string to append
        e2 - the expression causing s2
        Returns:
        the appended string
      • getAdditionalIndentation

        private int getAdditionalIndentation()
        Returns the additional indentation as configured.
        Returns:
        the additional indentation or 0 if no configuration is present
      • getTabEmulation

        private int getTabEmulation()
      • getIndentationStep

        private int getIndentationStep()
      • getLineEnd

        private java.lang.String getLineEnd()
        Returns the current line end based on the formatting configuration of the actual context model.
        Returns:
        the actual line end (fallback is the Java line end)
      • visitJavaExtension

        public java.lang.Object visitJavaExtension​(JavaExtension ext)
                                            throws VilException
        Description copied from interface: IVisitor
        Visits a java extension.
        Specified by:
        visitJavaExtension in interface IVisitor
        Parameters:
        ext - the java extension
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitTemplateCallExpression

        public java.lang.Object visitTemplateCallExpression​(TemplateCallExpression call)
                                                     throws VilException
        Description copied from interface: IVisitor
        Visits a template call expression.
        Specified by:
        visitTemplateCallExpression in interface IVisitor
        Parameters:
        call - the call expression
        Returns:
        the result of visiting the given expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • executeModelCall

        protected java.lang.Object executeModelCall​(Def def)
                                             throws VilException
        Description copied from class: ExecutionVisitor
        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.
        Specified by:
        executeModelCall in class ExecutionVisitor<Template,​Def,​VariableDeclaration,​Resolver>
        Parameters:
        def - the operation to be executed
        Returns:
        the execution result
        Throws:
        VilException - in case that execution fails
      • dynamicDispatch

        protected Def dynamicDispatch​(Def operation,
                                      java.lang.Object[] args,
                                      IArgumentProvider argumentProvider,
                                      boolean enableParentScope)
        Description copied from class: ExecutionVisitor
        Performs the dynamic dispatch on the operation type.
        Specified by:
        dynamicDispatch in class ExecutionVisitor<Template,​Def,​VariableDeclaration,​Resolver>
        Parameters:
        operation - the operation to be dispatched
        args - the actual arguments
        argumentProvider - access to the argument expressions
        enableParentScope - enable the parent declaration scopes for dynamic dispatch, shall not be done in case of explicit super calls due to potential endless recursion
        Returns:
        operation or the more actual operation
      • visitTypedef

        public java.lang.Object visitTypedef​(Typedef typedef)
                                      throws VilException
        Description copied from interface: IVisitor
        Visits a typedef.
        Specified by:
        visitTypedef in interface IVisitor
        Parameters:
        typedef - the typedef
        Returns:
        the result of visiting (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitWhile

        public java.lang.Object visitWhile​(WhileStatement stmt)
                                    throws VilException
        Description copied from interface: IVisitor
        Visits a while statement.
        Specified by:
        visitWhile in interface IVisitor
        Parameters:
        stmt - the while statement to visit
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitFlush

        public java.lang.Object visitFlush​(FlushStatement stmt)
                                    throws VilException
        Description copied from interface: IVisitor
        Visits a flush statement.
        Specified by:
        visitFlush in interface IVisitor
        Parameters:
        stmt - the flush statement
        Returns:
        the result visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • storeContent

        public void storeContent()
                          throws VilException
        Explicitly stores the concatenated results of the content statements to the target artifact.
        Throws:
        VilException - if storing the content fails for some reason
      • storeContent

        public static void storeContent​(IArtifact target,
                                        java.io.StringWriter out)
                                 throws VilException
        Explicitly stores the concatenated results of the content statements to the target artifact.
        Parameters:
        target - the target artifact
        out - the output writer to take the produced content from
        Throws:
        VilException - if storing the content fails for some reason
      • evaluateSeparator

        private java.lang.String evaluateSeparator​(Expression ex,
                                                   java.lang.String deflt)
                                            throws VilException
        Evaluates a separator expression.
        Parameters:
        ex - the expression (may be null)
        deflt - the default value to be used as result if ex is null
        Returns:
        the separator, deflt if ex is null or the evaluation leads to undefined, the separator string else
        Throws:
        VilException - in case that the evaluation fails
      • visitContentLoopExpression

        public java.lang.Object visitContentLoopExpression​(ContentLoopExpression ex)
                                                    throws VilException
        Description copied from interface: IVisitor
        Visits a content loop expression.
        Specified by:
        visitContentLoopExpression in interface IVisitor
        Parameters:
        ex - the expression
        Returns:
        the result visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitContentVarDeclExpression

        public java.lang.Object visitContentVarDeclExpression​(ContentVarDeclExpression ex)
                                                       throws VilException
        Description copied from interface: IVisitor
        Visits a content variable declaration expression.
        Specified by:
        visitContentVarDeclExpression in interface IVisitor
        Parameters:
        ex - the expression
        Returns:
        the result visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • getFallbackBaseURI

        protected java.net.URI getFallbackBaseURI()
        Returns the base URI for template resolution in this execution if there is no template to obtain it from.
        Returns:
        the base URI
      • visitCompound

        public java.lang.Object visitCompound​(Compound compound)
                                       throws VilException
        Description copied from interface: IVisitor
        Visits a compound.
        Specified by:
        visitCompound in interface IVisitor
        Parameters:
        compound - the compound
        Returns:
        the result of visiting (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)