@PublicApi public class Document extends AbstractNode<Document>
Modifier and Type | Class and Description |
---|---|
static class |
Document.Builder |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CHILD_DEFINITIONS |
Modifier | Constructor and Description |
---|---|
|
Document(java.util.List<Definition> definitions)
alternative to using a Builder for convenience
|
protected |
Document(java.util.List<Definition> definitions,
SourceLocation sourceLocation,
java.util.List<Comment> comments,
IgnoredChars ignoredChars,
java.util.Map<java.lang.String,java.lang.String> additionalData) |
Modifier and Type | Method and Description |
---|---|
TraversalControl |
accept(TraverserContext<Node> context,
NodeVisitor visitor)
Double-dispatch entry point.
|
Document |
deepCopy() |
java.util.List<Node> |
getChildren() |
java.util.List<Definition> |
getDefinitions() |
<T extends Definition> |
getDefinitionsOfType(java.lang.Class<T> definitionClass)
Returns a list of definitions of the specific type.
|
NodeChildrenContainer |
getNamedChildren()
Alternative to
Node.getChildren() where the children are not all in one list regardless of type
but grouped by name/type of the child. |
boolean |
isEqualTo(Node o)
Compares just the content and not the children.
|
static Document.Builder |
newDocument() |
java.lang.String |
toString() |
Document |
transform(java.util.function.Consumer<Document.Builder> builderConsumer) |
Document |
withNewChildren(NodeChildrenContainer newChildren)
Replaces the specified children and returns a new Node.
|
deepCopy, deepCopy, getAdditionalData, getComments, getIgnoredChars, getSourceLocation
public static final java.lang.String CHILD_DEFINITIONS
protected Document(java.util.List<Definition> definitions, SourceLocation sourceLocation, java.util.List<Comment> comments, IgnoredChars ignoredChars, java.util.Map<java.lang.String,java.lang.String> additionalData)
public Document(java.util.List<Definition> definitions)
definitions
- the definitions that make up this documentpublic java.util.List<Definition> getDefinitions()
public <T extends Definition> java.util.List<T> getDefinitionsOfType(java.lang.Class<T> definitionClass)
Class.isAssignableFrom(Class)
for the testT
- the type of definitiondefinitionClass
- the definition classpublic java.util.List<Node> getChildren()
public NodeChildrenContainer getNamedChildren()
Node
Node.getChildren()
where the children are not all in one list regardless of type
but grouped by name/type of the child.public Document withNewChildren(NodeChildrenContainer newChildren)
Node
newChildren
- must be empty for Nodes without childrenpublic boolean isEqualTo(Node o)
Node
o
- the other node to compare topublic Document deepCopy()
public java.lang.String toString()
toString
in class java.lang.Object
public TraversalControl accept(TraverserContext<Node> context, NodeVisitor visitor)
Node
instanceOf
check when decision based on the actual
type of Node is needed, which happens redundantly during traversing AST.
Additional advantage of this pattern is to decouple tree traversal mechanism
from the code that needs to be executed when traversal "visits" a particular Node
in the tree. This leads to a better code re-usability and maintainability.context
- TraverserContext bound to this Node objectvisitor
- Visitor instance that performs actual processing on the Nodes(s)public static Document.Builder newDocument()
public Document transform(java.util.function.Consumer<Document.Builder> builderConsumer)