Class FieldDecl
- java.lang.Object
-
- com.tonic.analysis.source.ast.decl.FieldDecl
-
-
Constructor Summary
Constructors Constructor Description FieldDecl(String name, SourceType type)Creates a field declaration at an unknown location.FieldDecl(String name, SourceType type, SourceLocation location)Creates a field declaration without an initializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.FieldDecladdAnnotation(AnnotationExpr annotation)Adds an annotation.FieldDecladdModifier(Modifier modifier)Adds a modifier.NodeList<AnnotationExpr>getAnnotations()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetInitializer()SourceLocationgetLocation()Gets the source location of this node.Set<Modifier>getModifiers()StringgetName()ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetType()booleanhasInitializer()booleanisFinal()booleanisPrivate()booleanisProtected()booleanisPublic()booleanisStatic()booleanisTransient()booleanisVolatile()voidsetInitializer(Expression initializer)Sets the initializer expression.voidsetName(String name)Sets the field name.voidsetParent(ASTNode parent)Sets the parent node.voidsetType(SourceType type)Sets the field type.StringtoString()FieldDeclwithInitializer(Expression initializer)Replaces the initializer, adopting the new expression and releasing the old one.FieldDeclwithModifiers(Set<Modifier> modifiers)Replaces all modifiers with the given set.FieldDeclwithName(String name)Sets the field name.FieldDeclwithType(SourceType type)Sets the field type.-
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
-
FieldDecl
public FieldDecl(String name, SourceType type, SourceLocation location)
Creates a field declaration without an initializer.- Parameters:
name- the field nametype- the field typelocation- the source location, or null for unknown
-
FieldDecl
public FieldDecl(String name, SourceType type)
Creates a field declaration at an unknown location.- Parameters:
name- the field nametype- the field type
-
-
Method Detail
-
getName
public String getName()
- Returns:
- the name
-
setName
public void setName(String name)
Sets the field name.- Parameters:
name- the field name
-
getAnnotations
public NodeList<AnnotationExpr> getAnnotations()
- Returns:
- the annotations
-
getType
public SourceType getType()
- Returns:
- the type
-
setType
public void setType(SourceType type)
Sets the field type.- Parameters:
type- the field type
-
getInitializer
public Expression getInitializer()
- Returns:
- the initializer
-
setInitializer
public void setInitializer(Expression initializer)
Sets the initializer expression.- Parameters:
initializer- the initial value, or null for none
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the source location, or null if unknown
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Sets the parent node.
-
withName
public FieldDecl withName(String name)
Sets the field name.- Parameters:
name- the field name- Returns:
- this declaration
-
withType
public FieldDecl withType(SourceType type)
Sets the field type.- Parameters:
type- the field type- Returns:
- this declaration
-
withModifiers
public FieldDecl withModifiers(Set<Modifier> modifiers)
Replaces all modifiers with the given set.- Parameters:
modifiers- the modifiers to apply- Returns:
- this declaration
-
addModifier
public FieldDecl addModifier(Modifier modifier)
Adds a modifier.- Parameters:
modifier- the modifier to add- Returns:
- this declaration
-
addAnnotation
public FieldDecl addAnnotation(AnnotationExpr annotation)
Adds an annotation.- Parameters:
annotation- the annotation to add- Returns:
- this declaration
-
withInitializer
public FieldDecl withInitializer(Expression initializer)
Replaces the initializer, adopting the new expression and releasing the old one.- Parameters:
initializer- the initial value, or null for none- Returns:
- this declaration
-
hasInitializer
public boolean hasInitializer()
- Returns:
- true if the field has an initializer
-
isPublic
public boolean isPublic()
- Returns:
- true if the public modifier is present
-
isProtected
public boolean isProtected()
- Returns:
- true if the protected modifier is present
-
isPrivate
public boolean isPrivate()
- Returns:
- true if the private modifier is present
-
isStatic
public boolean isStatic()
- Returns:
- true if the static modifier is present
-
isFinal
public boolean isFinal()
- Returns:
- true if the final modifier is present
-
isTransient
public boolean isTransient()
- Returns:
- true if the transient modifier is present
-
isVolatile
public boolean isVolatile()
- Returns:
- true if the volatile modifier is present
-
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.
-
-