public abstract class SyntaxNode<Tag extends java.lang.Enum<Tag>>
extends java.lang.Object
implements java.lang.Cloneable
SyntaxNode
represents a basic node of an abstract syntax tree (AST).SymbolTable
Modifier and Type | Class and Description |
---|---|
static class |
SyntaxNode.Kind
SyntaxNode.Kind classifies nodes according to the has-name and has-scope flags. |
Modifier | Constructor and Description |
---|---|
protected |
SyntaxNode(java.lang.Class<Tag> tagType,
Tag tag,
java.util.EnumSet<Tag> childrenTags,
SyntaxNode.Kind kind) |
protected |
SyntaxNode(java.lang.Class<Tag> tagType,
Tag tag,
java.util.EnumSet<Tag> childrenTags,
SyntaxNode.Kind kind,
java.lang.String name,
SyntaxNode<Tag> parent)
Creates an AST node.
|
protected |
SyntaxNode(java.lang.Class<Tag> tagType,
Tag tag,
java.util.EnumSet<Tag> childrenTags,
SyntaxNode.Kind kind,
SyntaxNode<Tag> parent) |
protected |
SyntaxNode(java.lang.Class<Tag> tagType,
Tag tag,
SyntaxNode.Kind kind) |
protected |
SyntaxNode(SyntaxNode<Tag> r) |
Modifier and Type | Method and Description |
---|---|
void |
add(SyntaxNode<Tag> child)
Adds a child to the node.
|
boolean |
containsAttribute(java.lang.String key)
Checks whether the node contains the given attribute.
|
SyntaxNode<Tag> |
find(java.lang.String name)
Searches for a child with the given name in the current scope.
|
SyntaxNode<Tag> |
findRecursively(java.lang.String name)
Searches for a child with the given name in the current and upper scopes.
|
java.lang.Object |
getAttribute(java.lang.String key)
Returns the attribute value.
|
java.util.Collection<SyntaxNode<Tag>> |
getChildren()
Returns the collection of the children.
|
java.util.Collection<SyntaxNode<Tag>> |
getChildren(Tag tag)
Returns the collection of the children of the given tag.
|
SyntaxNode.Kind |
getKind()
Returns the kind of the node.
|
java.lang.String |
getName()
Returns the name of the node.
|
SyntaxNode<Tag> |
getParent()
Returns the parent of the node or
null if the node is a root. |
Tag |
getTag()
Returns the tag of the node.
|
java.lang.Class<Tag> |
getTagType()
Returns the type of the node tag.
|
boolean |
hasName()
Checks whether the node has name.
|
boolean |
hasScope()
Checks whether the node has scope.
|
void |
setAttribute(java.lang.String key,
java.lang.Object value)
Sets the attribute value.
|
void |
setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Sets the attribute values.
|
void |
setName(java.lang.String name)
Sets the name of the node.
|
void |
setParent(SyntaxNode<Tag> parent)
Sets the parent of the node.
|
protected void |
setRedefinitionHandler(ErrorHandler<Tag> handler)
Sets the redefinition handler.
|
protected SyntaxNode(java.lang.Class<Tag> tagType, Tag tag, java.util.EnumSet<Tag> childrenTags, SyntaxNode.Kind kind, java.lang.String name, SyntaxNode<Tag> parent)
tagType
- the node tag type.tag
- the node tag.childrenTags
- the admissible tags of the node's children.kind
- the node kind.name
- the node name.parent
- the node parent.protected SyntaxNode(java.lang.Class<Tag> tagType, Tag tag, java.util.EnumSet<Tag> childrenTags, SyntaxNode.Kind kind, SyntaxNode<Tag> parent)
protected SyntaxNode(java.lang.Class<Tag> tagType, Tag tag, java.util.EnumSet<Tag> childrenTags, SyntaxNode.Kind kind)
protected SyntaxNode(java.lang.Class<Tag> tagType, Tag tag, SyntaxNode.Kind kind)
protected SyntaxNode(SyntaxNode<Tag> r)
public final java.lang.Class<Tag> getTagType()
public final Tag getTag()
public final SyntaxNode.Kind getKind()
public final boolean containsAttribute(java.lang.String key)
key
- the attribute key.true
if the node contains the attribute; false
otherwise.public final java.lang.Object getAttribute(java.lang.String key)
key
- the attribute key.null
if the attribute has not been set.public final void setAttribute(java.lang.String key, java.lang.Object value)
key
- the attribute key.value
- the attribute valuepublic final void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
attributes
- the attributes to be set.public final boolean hasName()
true
if the node has name; false
otherwise.public final boolean hasScope()
true
if the node has scope; false
otherwise.public final java.lang.String getName()
public final void setName(java.lang.String name)
name
- the node name.public final SyntaxNode<Tag> getParent()
null
if the node is a root.public final void setParent(SyntaxNode<Tag> parent)
parent
- the node parent.public final java.util.Collection<SyntaxNode<Tag>> getChildren()
public final java.util.Collection<SyntaxNode<Tag>> getChildren(Tag tag)
tag
- the child tag.public final SyntaxNode<Tag> find(java.lang.String name)
name
- the child name.null
.public final SyntaxNode<Tag> findRecursively(java.lang.String name)
name
- the child name.null
.public final void add(SyntaxNode<Tag> child)
child
- the child to be added.protected final void setRedefinitionHandler(ErrorHandler<Tag> handler)
handler
- the handler to be set.