Class SwitchStatement
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.templateModel.AbstractTemplateElement
-
- net.ssehub.easy.instantiation.core.model.templateModel.SwitchStatement
-
- All Implemented Interfaces:
ILanguageElement,ITemplateElement,ITemplateLangElement
public class SwitchStatement extends AbstractTemplateElement
Implements a value switch.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSwitchStatement.AlternativeA switch alternative.
-
Field Summary
Fields Modifier and Type Field Description private SwitchStatement.Alternative[]alternativesprivate VariableDeclarationimplicitVarprivate ExpressionswitchExpression
-
Constructor Summary
Constructors Constructor Description SwitchStatement()Constructor for serialization.SwitchStatement(Expression switchExpression, VariableDeclaration implicitVar, java.util.List<SwitchStatement.Alternative> alternatives)Creates a new switch expression.SwitchStatement(Expression switchExpression, VariableDeclaration implicitVar, SwitchStatement.Alternative[] alternatives)Creates a new switch expression.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IVisitor visitor)Accepts the visitor for visiting.booleanendsWithContentStatement()Returns whether this element ends with a content statement.SwitchStatement.AlternativegetAlternative(int index)Get the alternative of this statement at the specified index.intgetAlternativeCount()Get the number of alternatives of this switch statement.VariableDeclarationgetImplicitVariable()Returns the implicit variable defined by this switch statement.ExpressiongetSwitchExpression()Returns the switch expression.TypeDescriptor<?>inferType()Infers the type of this language element.booleanisBlock()Returns whether this element is a block (opposite is a single statement).protected voidsetParent(ILanguageElement parent)Changes the parent.static SwitchStatement.Alternative[]toArray(java.util.List<SwitchStatement.Alternative> alternatives)Transforms the given alternatives into an array.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.templateModel.AbstractTemplateElement
getParent, isLoop
-
-
-
-
Field Detail
-
switchExpression
private Expression switchExpression
-
alternatives
private SwitchStatement.Alternative[] alternatives
-
implicitVar
private VariableDeclaration implicitVar
-
-
Constructor Detail
-
SwitchStatement
SwitchStatement()
Constructor for serialization.
-
SwitchStatement
public SwitchStatement(Expression switchExpression, VariableDeclaration implicitVar, java.util.List<SwitchStatement.Alternative> alternatives) throws VilException
Creates a new switch expression.- Parameters:
switchExpression- the switch expressionimplicitVar- the implicit variable representing the actual value of the switch expressionalternatives- the alternatives in the switch including an optional default alternative- Throws:
VilException- in case of semantic problems while creating this instance
-
SwitchStatement
public SwitchStatement(Expression switchExpression, VariableDeclaration implicitVar, SwitchStatement.Alternative[] alternatives) throws VilException
Creates a new switch expression.- Parameters:
switchExpression- the switch expressionimplicitVar- the implicit variable representing the actual value of the switch expressionalternatives- the alternatives in the switch including an optional default alternative- Throws:
VilException- in case of semantic problems while creating this instance
-
-
Method Detail
-
toArray
public static final SwitchStatement.Alternative[] toArray(java.util.List<SwitchStatement.Alternative> alternatives)
Transforms the given alternatives into an array.- Parameters:
alternatives- the alternatives, may be null- Returns:
- the alternatives as an array, null if the input was null
-
getSwitchExpression
public Expression getSwitchExpression()
Returns the switch expression.- Returns:
- the switch expression
-
getAlternativeCount
public int getAlternativeCount()
Get the number of alternatives of this switch statement.- Returns:
- The number of alternatives of this switch statement.
-
getAlternative
public SwitchStatement.Alternative getAlternative(int index)
Get the alternative of this statement at the specified index.- Parameters:
index- The 0-based index of the alternative to be returned.- Returns:
- The alternative at the given index.
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getAlternativeCount()
-
getImplicitVariable
public VariableDeclaration getImplicitVariable()
Returns the implicit variable defined by this switch statement.- Returns:
- the implicit variable
-
accept
public java.lang.Object accept(IVisitor visitor) throws VilException
Description copied from interface:ITemplateLangElementAccepts the visitor for visiting.- Parameters:
visitor- the visitor to be used- Returns:
- the result of visiting this instance (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
isBlock
public boolean isBlock()
Description copied from interface:ITemplateElementReturns whether this element is a block (opposite is a single statement).- Returns:
trueif it is a block,falseelse
-
inferType
public TypeDescriptor<?> inferType() throws VilException
Description copied from interface:ITemplateElementInfers the type of this language element.- Returns:
- the type of this language element
- Throws:
VilException- in case that type errors occur
-
setParent
protected void setParent(ILanguageElement parent)
Description copied from class:AbstractTemplateElementChanges the parent. Please override if children must be adjusted according. Shall be called only once per instance, but there is no limitation.- Overrides:
setParentin classAbstractTemplateElement- Parameters:
parent- the parent
-
endsWithContentStatement
public boolean endsWithContentStatement()
Description copied from interface:ITemplateElementReturns whether this element ends with a content statement.- Returns:
truefor end with content statement,falseelse
-
-