Class VarDeclStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.VarDeclStmt
-
-
Constructor Summary
Constructors Constructor Description VarDeclStmt(SourceType type, String name)Creates a non-final declaration with no initializer and an unknown location.VarDeclStmt(SourceType type, String name, Expression initializer)Creates a non-final declaration with an explicit type and an unknown location.VarDeclStmt(SourceType type, String name, Expression initializer, boolean useVarKeyword, boolean isFinal, SourceLocation location)Creates a declaration, adopting the initializer as a child.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetInitializer()SourceLocationgetLocation()Gets the source location of this node.StringgetName()ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetType()booleanhasInitializer()booleanisFinal()booleanisSynthetic()booleanisUseVarKeyword()voidmarkSynthetic()Flags this declaration as a recovery-made carrier rather than a real local.voidsetFinal(boolean isFinal)voidsetInitializer(Expression initializer)Replaces the initializer through withInitializer, so parent links are maintained.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetName(String name)voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetType(SourceType type)voidsetUseVarKeyword(boolean useVarKeyword)StringtoString()VarDeclStmtwithInitializer(Expression initializer)Replaces the initializer, reparenting the new one and releasing the old child link.static VarDeclStmtwithVar(SourceType inferredType, String name, Expression initializer)Creates a declaration printed with the var keyword.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
VarDeclStmt
public VarDeclStmt(SourceType type, String name, Expression initializer, boolean useVarKeyword, boolean isFinal, SourceLocation location)
Creates a declaration, adopting the initializer as a child.- Parameters:
type- declared typename- variable nameinitializer- initial value, or nulluseVarKeyword- whether to print "var" instead of the typeisFinal- whether the declaration is finallocation- source position, null becoming UNKNOWN- Throws:
NullPointerException- if the type or name is null
-
VarDeclStmt
public VarDeclStmt(SourceType type, String name, Expression initializer)
Creates a non-final declaration with an explicit type and an unknown location.- Parameters:
type- declared typename- variable nameinitializer- initial value, or null- Throws:
NullPointerException- if the type or name is null
-
VarDeclStmt
public VarDeclStmt(SourceType type, String name)
Creates a non-final declaration with no initializer and an unknown location.- Parameters:
type- declared typename- variable name- Throws:
NullPointerException- if the type or name is null
-
-
Method Detail
-
isSynthetic
public boolean isSynthetic()
- Returns:
- whether synthetic
-
markSynthetic
public void markSynthetic()
Flags this declaration as a recovery-made carrier rather than a real local.
-
getType
public SourceType getType()
- Returns:
- the type
-
setType
public void setType(SourceType type)
- Parameters:
type- new declared type
-
getName
public String getName()
- Returns:
- the name
-
setName
public void setName(String name)
- Parameters:
name- new variable name
-
getInitializer
public Expression getInitializer()
- Returns:
- the initializer
-
setInitializer
public void setInitializer(Expression initializer)
Replaces the initializer through withInitializer, so parent links are maintained.- Parameters:
initializer- new initializer, or null to drop it
-
isUseVarKeyword
public boolean isUseVarKeyword()
- Returns:
- whether use var keyword
-
setUseVarKeyword
public void setUseVarKeyword(boolean useVarKeyword)
- Parameters:
useVarKeyword- whether to print "var" instead of the declared type
-
isFinal
public boolean isFinal()
- Returns:
- whether final
-
setFinal
public void setFinal(boolean isFinal)
- Parameters:
isFinal- whether the declaration carries the final modifier
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
withVar
public static VarDeclStmt withVar(SourceType inferredType, String name, Expression initializer)
Creates a declaration printed with the var keyword.- Parameters:
inferredType- type the var stands forname- variable nameinitializer- initial value- Returns:
- the new declaration
-
hasInitializer
public boolean hasInitializer()
- Returns:
- true if an initializer is present
-
withInitializer
public VarDeclStmt withInitializer(Expression initializer)
Replaces the initializer, reparenting the new one and releasing the old child link.- Parameters:
initializer- new initializer, or null to drop it- Returns:
- this statement
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
setLocation
public void setLocation(SourceLocation location)
Description copied from interface:StatementSets this statement's source location.- Specified by:
setLocationin interfaceStatement- Parameters:
location- the provenance to stamp, or null forSourceLocation.UNKNOWN
-
-