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.NgetChild(int index)Returns the child of this node at the given index.default @Nullable NgetFirstChild()Returns the first child of this node, or null if it doesn't exist.default @Nullable NgetLastChild()Returns the first last of this node, or null if it doesn't exist.default @Nullable NgetNextSibling()Returns the next sibling of this node, or null if it does not exist.NgetParent()Returns the parent of this node, or null if this is the root of the tree.default @Nullable NgetPreviousSibling()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:NodeReturns the child of this node at the given index.
-
getParent
N getParent()
Description copied from interface:NodeReturns the parent of this node, or null if this is the root of the tree.
-
getFirstChild
default @Nullable N getFirstChild()
Description copied from interface:NodeReturns the first child of this node, or null if it doesn't exist.- Specified by:
getFirstChildin interfaceNode
-
getLastChild
default @Nullable N getLastChild()
Description copied from interface:NodeReturns the first last of this node, or null if it doesn't exist.- Specified by:
getLastChildin interfaceNode
-
asStream
default NodeStream<N> asStream()
Description copied from interface:NodeReturns a node stream containing only this node.NodeStream.of(Node)is a null-safe version of this method.- Specified by:
asStreamin interfaceNode- Returns:
- A node stream containing only this node
- See Also:
NodeStream.of(Node)
-
children
default NodeStream<N> children()
Description copied from interface:NodeReturns 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:
childrenin interfaceNode- See Also:
NodeStream.children(Class)
-
descendants
default NodeStream.DescendantNodeStream<N> descendants()
Description copied from interface:NodeReturns a node stream containing all the descendants of this node. SeeNodeStream.DescendantNodeStreamfor details.- Specified by:
descendantsin 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:NodeReturns a node stream containing this node, then all its descendants. SeeNodeStream.DescendantNodeStreamfor details.- Specified by:
descendantsOrSelfin 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:NodeReturns a node stream containing this node and its ancestors. The nodes of the returned stream are yielded in a depth-first fashion.- Specified by:
ancestorsOrSelfin interfaceNode- Returns:
- A stream of ancestors
- See Also:
NodeStream.ancestorsOrSelf()
-
ancestors
default NodeStream<N> ancestors()
Description copied from interface:NodeReturns 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:
ancestorsin interfaceNode- Returns:
- A node stream of the ancestors of this node
- See Also:
NodeStream.ancestors()
-
getPreviousSibling
default @Nullable N getPreviousSibling()
Description copied from interface:NodeReturns the previous sibling of this node, or null if it does not exist.- Specified by:
getPreviousSiblingin interfaceNode
-
getNextSibling
default @Nullable N getNextSibling()
Description copied from interface:NodeReturns the next sibling of this node, or null if it does not exist.- Specified by:
getNextSiblingin interfaceNode
-
-