@PublicApi public interface Node<T extends Node> extends java.io.Serializable
Serializable
and hence it can be serialised and placed into a distributed cache. However we
are not aiming to provide long term compatibility and do not intend for you to place this serialised data into permanent storage,
with times frames that cross graphql-java versions. While we don't change things unnecessarily, we may inadvertently break
the serialised compatibility across versions.
Every Node is immutableModifier and Type | Method and Description |
---|---|
TraversalControl |
accept(TraverserContext<Node> context,
NodeVisitor visitor)
Double-dispatch entry point.
|
T |
deepCopy() |
java.util.Map<java.lang.String,java.lang.String> |
getAdditionalData()
A node can have a map of additional data associated with it.
|
java.util.List<Node> |
getChildren() |
java.util.List<Comment> |
getComments()
Nodes can have comments made on them, the following is one comment per line before a node.
|
IgnoredChars |
getIgnoredChars()
The chars which are ignored by the parser.
|
NodeChildrenContainer |
getNamedChildren()
Alternative to
getChildren() where the children are not all in one list regardless of type
but grouped by name/type of the child. |
SourceLocation |
getSourceLocation() |
boolean |
isEqualTo(Node node)
Compares just the content and not the children.
|
T |
withNewChildren(NodeChildrenContainer newChildren)
Replaces the specified children and returns a new Node.
|
java.util.List<Node> getChildren()
NodeChildrenContainer getNamedChildren()
getChildren()
where the children are not all in one list regardless of type
but grouped by name/type of the child.T withNewChildren(NodeChildrenContainer newChildren)
newChildren
- must be empty for Nodes without childrenSourceLocation getSourceLocation()
java.util.List<Comment> getComments()
IgnoredChars getIgnoredChars()
java.util.Map<java.lang.String,java.lang.String> getAdditionalData()
NOTE: The reason this is a map of strings is so the Node can stay an immutable object, which Map<String,Object> would not allow say.
boolean isEqualTo(Node node)
node
- the other node to compare toT deepCopy()
TraversalControl accept(TraverserContext<Node> context, NodeVisitor visitor)
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)