Top Description Methods
com.github.javaparser

public Interface HasParentNode<T>

extends Observable
Known Direct Implementers
com.github.javaparser.ast.Node, com.github.javaparser.ast.NodeList
Imports
com.github.javaparser.ast.Node, com.github.javaparser.ast.observer.Observable, java.util.Optional, java.util.function.Predicate

An object that can have a parent node.

Method Summary

Modifier and TypeMethod and Description
public default <N> Optional<N>
findAncestor(Class<N> type)

Walks the parents of this node and returns the first node of type type, or empty() if none is found.

public default <N> Optional<N>
findAncestor(Class<N> type, Predicate<N> predicate)

Walks the parents of this node and returns the first node of type type that matches predicate, or empty() if none is found.

public Optional<Node>
getParentNode()

Returns the parent node, or Optional.empty if no parent is set.

public Node
getParentNodeForChildren()

Returns the parent node from the perspective of the children of this node.

public default boolean

Returns:

true if this node is a descendant of the given node, and false otherwise.
isDescendantOf
(Node
the node for which to determine whether it has this node as an ancestor.
ancestor
)

Determines whether this HasParentNode node is a descendant of the given node.

public T

Returns:

return this
setParentNode
(Node
the parent node, or null to set no parent.
parentNode
)

Sets the parent node.

Inherited from com.github.javaparser.ast.observer.Observable:
isRegisteredregisterunregister

Method Detail

findAncestorback to summary
public default <N> Optional<N> findAncestor(Class<N> type)

Walks the parents of this node and returns the first node of type type, or empty() if none is found. The given type may also be an interface type, such as one of the NodeWith... interface types.

findAncestorback to summary
public default <N> Optional<N> findAncestor(Class<N> type, Predicate<N> predicate)

Walks the parents of this node and returns the first node of type type that matches predicate, or empty() if none is found. The given type may also be an interface type, such as one of the NodeWith... interface types.

getParentNodeback to summary
public Optional<Node> getParentNode()

Returns the parent node, or Optional.empty if no parent is set.

getParentNodeForChildrenback to summary
public Node getParentNodeForChildren()

Returns the parent node from the perspective of the children of this node.

That is, this method returns this for everything except NodeList. A NodeList returns its parent node instead. This is because a NodeList sets the parent of all its children to its own parent node (see com.github.javaparser.ast.NodeList for details).

isDescendantOfback to summary
public default boolean isDescendantOf(Node ancestor)

Determines whether this HasParentNode node is a descendant of the given node. A node is not a descendant of itself.

Parameters
ancestor:Node

the node for which to determine whether it has this node as an ancestor.

Returns:boolean

true if this node is a descendant of the given node, and false otherwise.

See Also
Node#isAncestorOf(Node)
setParentNodeback to summary
public T setParentNode(Node parentNode)

Sets the parent node.

Parameters
parentNode:Node

the parent node, or null to set no parent.

Returns:T

return this