Package cn.nukkit.nbt.snbt
Interface Node
- All Superinterfaces:
Comparable<Node>
- All Known Implementing Classes:
BaseNode
,ByteArrayNBT
,CompoundNBT
,Delimiter
,IntArrayNBT
,InvalidToken
,KeyValuePair
,ListNBT
,Literal
,Root
,Token
,Value
,WHITESPACE
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
inserts a child Node at a specific index, displacing the nodes after the index by 1.void
appends a child node to this Nodedefault boolean
appendChild
(Node where, Node inserted) Insert a node right after a given Node.children()
children
(boolean includeUnparsedTokens) childrenOfType
(Class<T> clazz) void
Remove all the child nodesdefault void
close()
Life-cycle hook method called after all the child nodes have been added.default int
Used to order Nodes by location.default void
copyLocationInfo
(Node from) Copy the location info from another Nodedefault void
copyLocationInfo
(Node start, Node end) Copy the location info given a start and end Nodedescendants
(Class<T> clazz) descendants
(Class<T> clazz, Predicate<? super T> predicate) descendants
(Predicate<? super Node> predicate) descendantsOfType
(Class<T> clazz) default void
dump()
default void
default <T extends Node>
TfirstAncestorOfType
(Class<T> clazz) default Token
firstChildOfType
(SNBTConstants.TokenType tokenType) default <T extends Node>
TfirstChildOfType
(Class<T> clazz) default <T extends Node>
TfirstChildOfType
(Class<T> clazz, Predicate<T> pred) default Token
default <T extends Node>
TfirstDescendantOfType
(Class<T> clazz) getAllTokens
(boolean includeCommentTokens) default int
default int
int
getChild
(int i) int
default int
default int
int
default Node
Returns the first child of this node.default Token
default String
default Node
Returns the last child of the given node.default Token
default int
default String
default Node
getRoot()
default String
default SNBTConstants.TokenType
default boolean
Returns whether this node has any children.default int
default boolean
default ListIterator<Node>
iterator()
default Node
default void
open()
Life-cycle hook method called after the node has been made the current nodedefault boolean
prependChild
(Node where, Node inserted) Insert a Node right before a given Node.default Node
removeChild
(int i) Remove the node at index i.default boolean
removeChild
(Node n) Removes the Node from this node's childrendefault void
default boolean
replaceChild
(Node current, Node replacement) Replaces a child node with another one.void
setBeginOffset
(int beginOffset) Set the offset where the token begins, expressed in code units.void
Replace the node at index ivoid
setEndOffset
(int endOffet) Set the offset where the token ends, actually the location where the very next token should begin.void
void
setTokenSource
(SNBTLexer tokenSource) void
setUnparsed
(boolean b) Mark whether this Node is unparsed, i.e.
-
Method Details
-
open
default void open()Life-cycle hook method called after the node has been made the current node -
close
default void close()Life-cycle hook method called after all the child nodes have been added. -
getInputSource
- Returns:
- the input source (usually a filename) from which this Node came from
-
hasChildNodes
default boolean hasChildNodes()Returns whether this node has any children.- Returns:
- Returns
true
if this node has any children,false
otherwise.
-
setParent
- Parameters:
n
- The Node to set as the parent. Mostly used internally. The various addChild or appendChild sorts of methods should use this to set the node's parent.
-
getParent
Node getParent()- Returns:
- this node's parent Node
-
addChild
appends a child node to this Node- Parameters:
n
- the Node to append
-
addChild
inserts a child Node at a specific index, displacing the nodes after the index by 1.- Parameters:
i
- the (zero-based) index at which to insert the noden
- the Node to insert
-
getChild
- Parameters:
i
- the index of the Node to return- Returns:
- the Node at the specific offset
-
setChild
Replace the node at index i- Parameters:
i
- the indexn
- the node
-
removeChild
Remove the node at index i. Any Nodes after i are shifted to the left.- Parameters:
i
- the index at which to remove- Returns:
- the removed Node
-
removeChild
Removes the Node from this node's children- Parameters:
n
- the Node to remove- Returns:
- whether the Node was present
-
replaceChild
Replaces a child node with another one. It does nothing if the first parameter is not actually a child node.- Parameters:
current
- the Node to be replacedreplacement
- the Node to substitute- Returns:
- whether any replacement took place
-
prependChild
Insert a Node right before a given Node. It does nothing if the where Node is not actually a child node.- Parameters:
where
- the Node that is the location where to prependinserted
- the Node to prepend- Returns:
- whether a Node was prepended
-
appendChild
Insert a node right after a given Node. It does nothing if the where node is not actually a child node.- Parameters:
where
- the Node after which to appendinserted
- the Node to be inserted- Returns:
- whether a Node really was appended
-
indexOf
- Parameters:
child
- the Node to get the index of- Returns:
- the index of the child Node. Or -1 if it is not a child Node.
-
previousSibling
-
nextSibling
-
compareTo
Used to order Nodes by location.- Specified by:
compareTo
in interfaceComparable<Node>
- Parameters:
n
- the Node to compare to- Returns:
- typical Comparator semantics
-
clearChildren
void clearChildren()Remove all the child nodes -
getChildCount
int getChildCount()- Returns:
- the number of child nodes
-
children
- Returns:
- a List containing this node's child nodes The default implementation returns a copy, so modifying the list that is returned has no effect on this object. Most implementations of this should similarly return a copy or possibly immutable wrapper around the list.
-
children
-
getAllTokens
- Parameters:
includeCommentTokens
- Whether to include comment tokens- Returns:
- a List containing all the tokens in a Node
-
getRealTokens
- Returns:
- All the tokens in the node that are "real" (i.e. participate in parsing)
-
getTokenSource
SNBTLexer getTokenSource()- Returns:
- the #SNBTLexer from which this Node object originated. There is no guarantee that this doesn't return null. Most likely that would simply be because you constructed the Node yourself, i.e. it didn't really come about via the parsing/tokenizing machinery.
-
setTokenSource
-
getSource
- Returns:
- the original source content this Node came from a reference to the #SNBTLexer that stores the source code and the start/end location info stored in the Node object itself. This method could throw a NullPointerException if #getTokenSource returns null. Also, the return value could be spurious if the content of the source file was changed meanwhile. But this is just the default implementation of an API and it does not address this problem!
-
getLength
default int getLength() -
getBeginLine
default int getBeginLine()- Returns:
- the (1-based) line location where this Node starts
-
getEndLine
default int getEndLine()- Returns:
- the (1-based) line location where this Node ends
-
getBeginColumn
default int getBeginColumn()- Returns:
- the (1-based) column where this Node starts
-
getEndColumn
default int getEndColumn()- Returns:
- the (1-based) column offset where this Node ends
-
getBeginOffset
int getBeginOffset()- Returns:
- the offset in the input source where the token begins, expressed in code units.
-
getEndOffset
int getEndOffset()- Returns:
- the offset in the input source where the token ends, expressed in code units. This is actually the offset where the very next token would begin.
-
setBeginOffset
void setBeginOffset(int beginOffset) Set the offset where the token begins, expressed in code units. -
setEndOffset
void setEndOffset(int endOffet) Set the offset where the token ends, actually the location where the very next token should begin. -
getLocation
- Returns:
- a String that gives the starting location of this Node. This is a default implementation that could be overridden
-
isUnparsed
default boolean isUnparsed()- Returns:
- whether this Node was created by regular operations of the parsing machinery.
-
setUnparsed
void setUnparsed(boolean b) Mark whether this Node is unparsed, i.e. not the result of normal parsing- Parameters:
b
- whether to set the Node as unparsed or parsed.
-
firstChildOfType
-
firstChildOfType
-
firstDescendantOfType
-
firstChildOfType
-
firstDescendantOfType
-
childrenOfType
-
descendantsOfType
-
firstAncestorOfType
-
getTokenType
-
getFirstToken
- Returns:
- the very first token that is part of this node. It may be an unparsed (i.e. special) token.
-
getLastToken
-
copyLocationInfo
Copy the location info from another Node- Parameters:
from
- the Node to copy the info from
-
copyLocationInfo
Copy the location info given a start and end Node- Parameters:
start
- the start nodeend
- the end node
-
replace
-
getFirstChild
Returns the first child of this node. If there is no such node, this returnsnull
.- Returns:
- the first child of this node. If there is no such node, this returns
null
.
-
getLastChild
Returns the last child of the given node. If there is no such node, this returnsnull
.- Returns:
- the last child of the given node. If there is no such node, this
returns
null
.
-
getRoot
-
getTokens
-
getRealTokens
-
descendants
-
descendants
-
descendants
-
descendants
-
dump
-
dump
default void dump() -
iterator
-