Class ContainerInitializerExpression
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.Expression
-
- net.ssehub.easy.instantiation.core.model.expressions.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
-
-
Field Summary
Fields Modifier and Type Field Description private Expression[]initExpressionsprivate TypeDescriptor<?>type
-
Constructor Summary
Constructors Modifier Constructor Description ContainerInitializerExpression()Creates a new empty container initializer expression.ContainerInitializerExpression(Expression[] initExpressions)Creates a new container initializer expression.protectedContainerInitializerExpression(Expression[] initExpressions, TypeDescriptor<?> type)Internal constructor for set initialization.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IExpressionVisitor visitor)Visits the expression.protected ContainerInitializerExpressioncreateInitExpression(Expression[] initExpressions, TypeDescriptor<?> type)Creates a container initializer instance fortoSet().ExpressiongetInitExpression(int index)Returns the specified initializer expression.intgetInitExpressionsCount()Returns the number of initializer expressions.TypeDescriptor<?>inferType()Infers the type of this expression including the type of the contained sub-expressions.booleanisImplicit()Returns whether this initializer expression is implicit and shall not be printed.private static TypeDescriptor<?>moreCommon(TypeDescriptor<?> t1, TypeDescriptor<?> t2)Returns the more common type.voidsetInitExpression(int index, Expression expr)Replaces the specified expression.ContainerInitializerExpressiontoSet()Converts this container initializer to a set.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.expressions.Expression
getFormattingHint, replaceEmptyLine
-
-
-
-
Field Detail
-
initExpressions
private Expression[] initExpressions
-
type
private TypeDescriptor<?> type
-
-
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 expressiontype- 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- ifindex < 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 expressionexpr- the replacing expression- Throws:
java.lang.IndexOutOfBoundsException- ifindex<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 typet2- the second type- Returns:
- the more common type or "Any"
-
inferType
public TypeDescriptor<?> inferType() throws VilException
Description copied from class:ExpressionInfers the type of this expression including the type of the contained sub-expressions.- Specified by:
inferTypein classExpression- 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:ExpressionVisits the expression.- Specified by:
acceptin classExpression- 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:
truefor implicit,falseelse
-
createInitExpression
protected ContainerInitializerExpression createInitExpression(Expression[] initExpressions, TypeDescriptor<?> type)
Creates a container initializer instance fortoSet(). May be overridden.- Parameters:
initExpressions- the init expressiontype- the type descriptor- Returns:
- the initializer instance
-
toSet
public ContainerInitializerExpression toSet() throws VilException
Converts this container initializer to a set.- Returns:
- the corresponding set initializer
- Throws:
VilException- in case that conversion fails- See Also:
createInitExpression(Expression[], TypeDescriptor)
-
-