Class ContainerInitializerExpression

  • Direct Known Subclasses:
    ImplicitContainerInitializerExpression

    public class ContainerInitializerExpression
    extends Expression
    Represents a container initializer expression consisting of various entries all in the same dimension.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • ContainerInitializerExpression

        public ContainerInitializerExpression()
        Creates a new empty container initializer expression.
      • ContainerInitializerExpression

        public ContainerInitializerExpression​(Expression[] initExpressions)
        Creates a new container initializer expression. Currently, this constructor expects that the input is valid (appropriate dimensions)
        Parameters:
        initExpressions - the initializer expressions, either logical expressions or container initializer expression
      • ContainerInitializerExpression

        protected ContainerInitializerExpression​(Expression[] initExpressions,
                                                 TypeDescriptor<?> type)
        Internal constructor for set initialization.
        Parameters:
        initExpressions - the initializer expressions, either logical expressions or container initializer expression
        type - the type of the expression
    • Method Detail

      • getInitExpression

        public Expression getInitExpression​(int index)
        Returns the specified initializer expression.
        Parameters:
        index - the index of the specified expression
        Returns:
        the specified expression
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= getInitExpressionsCount()
      • setInitExpression

        public void setInitExpression​(int index,
                                      Expression expr)
        Replaces the specified expression. Handle with care!
        Parameters:
        index - the 0-based index of the expression
        expr - the replacing expression
        Throws:
        java.lang.IndexOutOfBoundsException - if index<0 || index>=getInitExpressionsCount()
      • getInitExpressionsCount

        public int getInitExpressionsCount()
        Returns the number of initializer expressions.
        Returns:
        the number of initializer expressions
      • moreCommon

        private static TypeDescriptor<?> moreCommon​(TypeDescriptor<?> t1,
                                                    TypeDescriptor<?> t2)
        Returns the more common type.
        Parameters:
        t1 - the first type
        t2 - the second type
        Returns:
        the more common type or "Any"
      • 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)
      • isImplicit

        public boolean isImplicit()
        Returns whether this initializer expression is implicit and shall not be printed.
        Returns:
        true for implicit, false else
      • createInitExpression

        protected ContainerInitializerExpression createInitExpression​(Expression[] initExpressions,
                                                                      TypeDescriptor<?> type)
        Creates a container initializer instance for toSet(). May be overridden.
        Parameters:
        initExpressions - the init expression
        type - the type descriptor
        Returns:
        the initializer instance