Interface GenericNode<N extends GenericNode<N>>
-
- Type Parameters:
N
- Self type (eg JavaNode)
- All Superinterfaces:
Node
,Reportable
- All Known Subinterfaces:
AntlrNode<N>
,JjtreeNode<N>
- All Known Implementing Classes:
AbstractJjtreeNode
,AbstractNode
,BaseAntlrErrorNode
,BaseAntlrInnerNode
,BaseAntlrNode
,BaseAntlrTerminalNode
,PlainTextLanguage.PlainTextFile
public interface GenericNode<N extends GenericNode<N>> extends Node
Interface that binds the return type of some node methods to a type parameter. This enforces that eg all children of such a node are from the same hierarchy (eg Java nodes only have Java nodes as parent, or as children).Although subinterfaces like JavaNode profit from the added type information, the Node interface and its usages in language-independent code would suffer from adding a type parameter directly to
Node
.Type safety of the unchecked casts here is the responsibility of the implementation, it should check that methods like setParent or addChild add an instance of
<N>
.
-
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.lang.ast.Node
COORDS_COMPARATOR
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default NodeStream<N>
ancestors()
Returns a node stream containing all the strict ancestors of this node, in innermost to outermost order.default NodeStream<N>
ancestorsOrSelf()
Returns a node stream containing this node and its ancestors.default NodeStream<N>
asStream()
Returns a node stream containing only this node.default NodeStream<N>
children()
Returns a node stream containing all the children of this node.default NodeStream.DescendantNodeStream<N>
descendants()
Returns a node stream containing all the descendants of this node.default NodeStream.DescendantNodeStream<N>
descendantsOrSelf()
Returns a node stream containing this node, then all its descendants.N
getChild(int index)
Returns the child of this node at the given index.default @Nullable N
getFirstChild()
Returns the first child of this node, or null if it doesn't exist.default @Nullable N
getLastChild()
Returns the first last of this node, or null if it doesn't exist.default @Nullable N
getNextSibling()
Returns the next sibling of this node, or null if it does not exist.N
getParent()
Returns the parent of this node, or null if this is the root of the tree.default @Nullable N
getPreviousSibling()
Returns the previous sibling of this node, or null if it does not exist.-
Methods inherited from interface net.sourceforge.pmd.lang.ast.Node
acceptVisitor, ancestors, children, compareLocation, descendants, firstChild, getAstInfo, getBeginColumn, getBeginLine, getEndColumn, getEndLine, getImage, getIndexInParent, getLanguageVersion, getNumChildren, getReportLocation, getRoot, getTextDocument, getTextRegion, getUserMap, getXPathAttributesIterator, getXPathNodeName, hasImageEqualTo, isFindBoundary
-
-
-
-
Method Detail
-
getChild
N getChild(int index)
Description copied from interface:Node
Returns the child of this node at the given index.
-
getParent
N getParent()
Description copied from interface:Node
Returns the parent of this node, or null if this is the root of the tree.
-
getFirstChild
default @Nullable N getFirstChild()
Description copied from interface:Node
Returns the first child of this node, or null if it doesn't exist.- Specified by:
getFirstChild
in interfaceNode
-
getLastChild
default @Nullable N getLastChild()
Description copied from interface:Node
Returns the first last of this node, or null if it doesn't exist.- Specified by:
getLastChild
in interfaceNode
-
asStream
default NodeStream<N> asStream()
Description copied from interface:Node
Returns a node stream containing only this node.NodeStream.of(Node)
is a null-safe version of this method.- Specified by:
asStream
in interfaceNode
- Returns:
- A node stream containing only this node
- See Also:
NodeStream.of(Node)
-
children
default NodeStream<N> children()
Description copied from interface:Node
Returns a node stream containing all the children of this node. This method does not provide much type safety, you'll probably want to useNode.children(Class)
.- Specified by:
children
in interfaceNode
- See Also:
NodeStream.children(Class)
-
descendants
default NodeStream.DescendantNodeStream<N> descendants()
Description copied from interface:Node
Returns a node stream containing all the descendants of this node. SeeNodeStream.DescendantNodeStream
for details.- Specified by:
descendants
in interfaceNode
- Returns:
- A node stream of the descendants of this node
- See Also:
NodeStream.descendants()
-
descendantsOrSelf
default NodeStream.DescendantNodeStream<N> descendantsOrSelf()
Description copied from interface:Node
Returns a node stream containing this node, then all its descendants. SeeNodeStream.DescendantNodeStream
for details.- Specified by:
descendantsOrSelf
in interfaceNode
- Returns:
- A node stream of the whole subtree topped by this node
- See Also:
NodeStream.descendantsOrSelf()
-
ancestorsOrSelf
default NodeStream<N> ancestorsOrSelf()
Description copied from interface:Node
Returns a node stream containing this node and its ancestors. The nodes of the returned stream are yielded in a depth-first fashion.- Specified by:
ancestorsOrSelf
in interfaceNode
- Returns:
- A stream of ancestors
- See Also:
NodeStream.ancestorsOrSelf()
-
ancestors
default NodeStream<N> ancestors()
Description copied from interface:Node
Returns a node stream containing all the strict ancestors of this node, in innermost to outermost order. The returned stream doesn't contain this node, and is empty if this node has no parent.- Specified by:
ancestors
in interfaceNode
- Returns:
- A node stream of the ancestors of this node
- See Also:
NodeStream.ancestors()
-
getPreviousSibling
default @Nullable N getPreviousSibling()
Description copied from interface:Node
Returns the previous sibling of this node, or null if it does not exist.- Specified by:
getPreviousSibling
in interfaceNode
-
getNextSibling
default @Nullable N getNextSibling()
Description copied from interface:Node
Returns the next sibling of this node, or null if it does not exist.- Specified by:
getNextSibling
in interfaceNode
-
-