Class VariableDeclaration
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.common.VariableDeclaration
-
- All Implemented Interfaces:
IVariable,IModifierHolder,IResolvable,IMetaParameterDeclaration
- Direct Known Subclasses:
VariableDeclaration,VariableDeclaration
public abstract class VariableDeclaration extends java.lang.Object implements IMetaParameterDeclaration, IModifierHolder
Represents a variable declaration.- Author:
- Christian Kröher, Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private Expressionexpressionprivate booleanhasExplicitTypeprivate booleanisConstantprivate java.util.List<IModifier>modifiersprivate java.lang.Stringnameprivate TypeDescriptor<?>type
-
Constructor Summary
Constructors Constructor Description VariableDeclaration(java.lang.String name, TypeDescriptor<?> type)Creates a new variable declaration.VariableDeclaration(java.lang.String name, TypeDescriptor<?> type, boolean isConstant, Expression expression)Creates a new variable declaration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IVisitor visitor)Accepts the given visitor for visiting this instance.voidaddModifier(IModifier modifier)Adds the specified modifier.ExpressiongetExpression()Get the value of this variable.IModifiergetModifier(int index)Returns the specified modifier.intgetModifierCount()Returns the number of modifiers.java.lang.StringgetName()Get the name of this project element.static <V extends VariableDeclaration>
VgetParameter(java.util.Map<java.lang.String,V> named, java.lang.String name, V[] params)Returns a named parameter.static <V extends VariableDeclaration>
intgetRequiredParameterCount(java.util.Map<java.lang.String,V> named, V[] decls)Returns the number of required parameters.TypeDescriptor<?>getType()Returns the type of this variable.booleanhasExplicitType()Returns the formatting hint whether this declaration has an explicit type.booleanhasModifier(IModifier modifier)Returns whether this variable declaration has a givenmodifier.booleanisConstant()Returns whether this variable is constant or not.booleanisImplicit()Returns whether this variable declaration is implicit.static <V extends VariableDeclaration>
java.util.Map<java.lang.String,V>mapDefaultedParameters(java.util.Map<java.lang.String,V> result, V[] decls)Adds all parameters with default values toresult.voidresolveOperation(TypeDescriptor<?> type, IMetaOperation operation)Resolves a (temporary) initialization expression to aResolvableOperationExpression("function pointer").voidsetHasExplicitType(boolean hasExplicitType)Changes the formatting hint whether this declaration has an explicit type.voidsetIsConstant(boolean isConstant)Define this variable as constant.java.lang.StringtoString()
-
-
-
Field Detail
-
name
private java.lang.String name
-
type
private TypeDescriptor<?> type
-
isConstant
private boolean isConstant
-
expression
private Expression expression
-
hasExplicitType
private boolean hasExplicitType
-
modifiers
private java.util.List<IModifier> modifiers
-
-
Constructor Detail
-
VariableDeclaration
public VariableDeclaration(java.lang.String name, TypeDescriptor<?> type)Creates a new variable declaration. Explicit type is assumed.- Parameters:
name- the name of the variabletype- the type of the variable- See Also:
hasExplicitType()
-
VariableDeclaration
public VariableDeclaration(java.lang.String name, TypeDescriptor<?> type, boolean isConstant, Expression expression)Creates a new variable declaration. Explicit type is assumed.- Parameters:
name- the name of the variabletype- the type of the variableisConstant- whether this variable is a constantexpression- an expression denoting the initial value (may be null)- See Also:
hasExplicitType()
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the name of this project element.- Specified by:
getNamein interfaceIResolvable- Returns:
- The name of this project element.
-
getType
public TypeDescriptor<?> getType()
Returns the type of this variable.- Specified by:
getTypein interfaceIMetaParameterDeclaration- Returns:
- the type of this variable
-
setIsConstant
public void setIsConstant(boolean isConstant)
Define this variable as constant. By default, a variable is always not constant.- Parameters:
isConstant- true if this variable is a constant. False otherwise.
-
isConstant
public boolean isConstant()
Returns whether this variable is constant or not. By default, a variable is always not constant.- Returns:
- True if this variable is a constant. False otherwise.
-
getExpression
public Expression getExpression()
Get the value of this variable.- Specified by:
getExpressionin interfaceIMetaParameterDeclaration- Returns:
- The value of this variable of null if this variable is unassigned.
-
accept
public java.lang.Object accept(IVisitor visitor) throws VilException
Accepts the given visitor for visiting this instance.- Parameters:
visitor- the visitor- Returns:
- the result of visiting the given statement (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
setHasExplicitType
public void setHasExplicitType(boolean hasExplicitType)
Changes the formatting hint whether this declaration has an explicit type.- Parameters:
hasExplicitType- the new status of the formatting hint
-
hasExplicitType
public boolean hasExplicitType()
Returns the formatting hint whether this declaration has an explicit type.- Returns:
- whether this declaration has an explicit type
-
addModifier
public void addModifier(IModifier modifier)
Adds the specified modifier.- Parameters:
modifier- the modifier to be added
-
getModifierCount
public int getModifierCount()
Description copied from interface:IModifierHolderReturns the number of modifiers.- Specified by:
getModifierCountin interfaceIModifierHolder- Returns:
- the number of modifiers
-
getModifier
public IModifier getModifier(int index)
Description copied from interface:IModifierHolderReturns the specified modifier.- Specified by:
getModifierin interfaceIModifierHolder- Parameters:
index- the 0-based index of the modifier to return- Returns:
- the specified modifier
-
hasModifier
public boolean hasModifier(IModifier modifier)
Description copied from interface:IModifierHolderReturns whether this variable declaration has a givenmodifier.- Specified by:
hasModifierin interfaceIModifierHolder- Parameters:
modifier- the modifier to search for- Returns:
trueif this variable declaration has themodifierattached,falseelse
-
resolveOperation
public void resolveOperation(TypeDescriptor<?> type, IMetaOperation operation)
Resolves a (temporary) initialization expression to aResolvableOperationExpression("function pointer").- Parameters:
type- the declared type (of the function pointer)operation- the resolved base operation
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isImplicit
public boolean isImplicit()
Returns whether this variable declaration is implicit.- Returns:
truefor implicit,falseelse
-
mapDefaultedParameters
public static <V extends VariableDeclaration> java.util.Map<java.lang.String,V> mapDefaultedParameters(java.util.Map<java.lang.String,V> result, V[] decls)
Adds all parameters with default values toresult. Createsresultif it does not exist but is required for storing data.- Type Parameters:
V- the variable declaration type- Parameters:
result- the map to be modifieddecls- the declarations to be (conditionally) mapped- Returns:
resultor a new map (only if needed)
-
getRequiredParameterCount
public static <V extends VariableDeclaration> int getRequiredParameterCount(java.util.Map<java.lang.String,V> named, V[] decls)
Returns the number of required parameters.- Type Parameters:
V- the variable declaration type- Parameters:
named- the named parameters (may be null)decls- the declared parameters (may be null)- Returns:
- the number of required parameters
-
getParameter
public static <V extends VariableDeclaration> V getParameter(java.util.Map<java.lang.String,V> named, java.lang.String name, V[] params)
Returns a named parameter.- Type Parameters:
V- the variable declaration type- Parameters:
named- the named parameters (may be null)name- the parameter name (may be null)params- all paraams (fallback, may be null)- Returns:
- the requested parameter or null
-
-