Class InPlaceCommand<I extends VariableDeclaration>

  • Type Parameters:
    I - the variable declaration type
    Direct Known Subclasses:
    InPlaceForCommand, InPlaceIfCommand, InPlaceImportCommand, InPlaceVarDeclCommand

    public abstract class InPlaceCommand<I extends VariableDeclaration>
    extends Expression
    Replaces an in-place command/expression within a string/content expression. Implementing classes are intended to incrementally build up an expression or to return all collected sub-expressions in case that the specification in the string/content expression was incomplete. An in-place command is a (temporary) expression so that it can be later replaced in the parent in-place command when the real expression was created through the IStringParserFactory.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • InPlaceCommand

        public InPlaceCommand()
    • Method Detail

      • append

        protected abstract void append​(Expression ex)
        Appends a sub-expression. An in-place command can have multiple sub-structures, that are sequentially switched to active via advanceState().
        Parameters:
        ex - the expression to append
      • advanceState

        protected void advanceState()
        Changes among different states of sub-structures, e.g., then-part and else-part. Override if needed, else the respective call is just ignored.
      • close

        protected abstract Expression close​(IStringParserFactory<I> factory)
                                     throws VilException
        Closes this in-place command by creating the real expression.
        Parameters:
        factory - the factory used to create the real expression
        Returns:
        the real expression, may be null if optional / none shall be created
        Throws:
        VilException - if the provided information is not sufficient for creating an expression
      • append

        protected abstract void append​(java.util.List<Expression> exprs)
        Appends the sub-expressions in parse sequence to exprs leaving out this command as fallback.
        Parameters:
        exprs - the expressions to add the sub-expressions to
      • replace

        protected abstract void replace​(InPlaceCommand<I> cmd,
                                        Expression expr)
        Replaces cmd by expr.
        Parameters:
        cmd - the command to be replaced
        expr - the replacing expression
      • replace

        protected boolean replace​(java.util.List<Expression> exprs,
                                  InPlaceCommand<I> cmd,
                                  Expression expr)
        Replaces cmd by expr in exprs.
        Parameters:
        exprs - the expressions list to be searched / modified
        cmd - the command to be replaced
        expr - the expression to replace cmd
        Returns:
        true if replacement was done, false else
      • inferType

        public TypeDescriptor<?> inferType()
                                    throws VilException
        Description copied from class: Expression
        Infers the type of this expression including the type of the contained sub-expressions.
        Specified by:
        inferType in class Expression
        Returns:
        the type of this expression
        Throws:
        VilException - in case that inferring the type fails
      • accept

        public java.lang.Object accept​(IExpressionVisitor visitor)
                                throws VilException
        Description copied from class: Expression
        Visits the expression.
        Specified by:
        accept in class Expression
        Parameters:
        visitor - the visitor
        Returns:
        the result of visiting this expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • holdsResolverLevel

        protected boolean holdsResolverLevel()
        Whether a cleanup of an erroneous parse stack requires cleaning up a resolver level.
        Returns:
        true for cleanup, false else