Package com.github.javaparser
Interface HasParentNode<T>
-
- All Superinterfaces:
Observable
- All Known Implementing Classes:
AnnotationDeclaration
,AnnotationExpr
,AnnotationMemberDeclaration
,ArrayAccessExpr
,ArrayCreationExpr
,ArrayCreationLevel
,ArrayInitializerExpr
,ArrayType
,AssertStmt
,AssignExpr
,BinaryExpr
,BlockComment
,BlockStmt
,BodyDeclaration
,BooleanLiteralExpr
,BreakStmt
,CallableDeclaration
,CastExpr
,CatchClause
,CharLiteralExpr
,ClassExpr
,ClassOrInterfaceDeclaration
,ClassOrInterfaceType
,Comment
,CompactConstructorDeclaration
,CompilationUnit
,ConditionalExpr
,ConstructorDeclaration
,ContinueStmt
,DoStmt
,DoubleLiteralExpr
,EmptyStmt
,EnclosedExpr
,EnumConstantDeclaration
,EnumDeclaration
,ExplicitConstructorInvocationStmt
,Expression
,ExpressionStmt
,FieldAccessExpr
,FieldDeclaration
,ForEachStmt
,ForStmt
,IfStmt
,ImportDeclaration
,InitializerDeclaration
,InstanceOfExpr
,IntegerLiteralExpr
,IntersectionType
,JavadocComment
,LabeledStmt
,LambdaExpr
,LineComment
,LiteralExpr
,LiteralStringValueExpr
,LocalClassDeclarationStmt
,LocalRecordDeclarationStmt
,LongLiteralExpr
,MarkerAnnotationExpr
,MemberValuePair
,MethodCallExpr
,MethodDeclaration
,MethodReferenceExpr
,Modifier
,ModuleDeclaration
,ModuleDirective
,ModuleExportsDirective
,ModuleOpensDirective
,ModuleProvidesDirective
,ModuleRequiresDirective
,ModuleUsesDirective
,Name
,NameExpr
,Node
,NodeList
,NormalAnnotationExpr
,NullLiteralExpr
,ObjectCreationExpr
,PackageDeclaration
,Parameter
,PatternExpr
,PrimitiveType
,ReceiverParameter
,RecordDeclaration
,RecordPatternExpr
,ReferenceType
,ReturnStmt
,SimpleName
,SingleMemberAnnotationExpr
,Statement
,StringLiteralExpr
,SuperExpr
,SwitchEntry
,SwitchExpr
,SwitchStmt
,SynchronizedStmt
,TextBlockLiteralExpr
,ThisExpr
,ThrowStmt
,TryStmt
,Type
,TypeDeclaration
,TypeExpr
,TypeParameter
,TypePatternExpr
,UnaryExpr
,UnionType
,UnknownType
,UnparsableStmt
,VariableDeclarationExpr
,VariableDeclarator
,VarType
,VoidType
,WhileStmt
,WildcardType
,YieldStmt
public interface HasParentNode<T> extends Observable
An object that can have a parent node.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default <N> Optional<N>
findAncestor(Class<N>... types)
Walks the parents of this node and returns the first node of typetype
, orempty()
if none is found.default <N> Optional<N>
findAncestor(Class<N> type, Predicate<N> predicate)
Deprecated.This method is no longer acceptable to find ancestor.default <N> Optional<N>
findAncestor(Predicate<N> predicate, Class<N>... types)
Walks the parents of this node and returns the first node that matches one of typestypes
, orempty()
if none is found.Optional<Node>
getParentNode()
Returns the parent node, orOptional.empty
if no parent is set.Node
getParentNodeForChildren()
Returns the parent node from the perspective of the children of this node.default boolean
hasParentNode()
Returns true if the parent has a parentdefault boolean
isDescendantOf(Node ancestor)
Determines whether thisHasParentNode
node is a descendant of the given node.T
setParentNode(Node parentNode)
Sets the parent node.-
Methods inherited from interface com.github.javaparser.ast.observer.Observable
isRegistered, register, unregister
-
-
-
-
Method Detail
-
hasParentNode
default boolean hasParentNode()
Returns true if the parent has a parent
-
getParentNode
Optional<Node> getParentNode()
Returns the parent node, orOptional.empty
if no parent is set.
-
setParentNode
T setParentNode(Node parentNode)
Sets the parent node.- Parameters:
parentNode
- the parent node, ornull
to set no parent.- Returns:
this
-
getParentNodeForChildren
Node getParentNodeForChildren()
Returns the parent node from the perspective of the children of this node.That is, this method returns
this
for everything exceptNodeList
. ANodeList
returns its parent node instead. This is because aNodeList
sets the parent of all its children to its own parent node (seeNodeList
for details).
-
findAncestor
default <N> Optional<N> findAncestor(Class<N>... types)
Walks the parents of this node and returns the first node of typetype
, orempty()
if none is found. The given type may also be an interface type, such as one of theNodeWith...
interface types.
-
findAncestor
@Deprecated default <N> Optional<N> findAncestor(Class<N> type, Predicate<N> predicate)
Deprecated.This method is no longer acceptable to find ancestor.Use
findAncestor(Predicate, Class)
instead.Walks the parents of this node and returns the first node of typetype
that matchespredicate
, orempty()
if none is found. The given type may also be an interface type, such as one of theNodeWith...
interface types.
-
findAncestor
default <N> Optional<N> findAncestor(Predicate<N> predicate, Class<N>... types)
Walks the parents of this node and returns the first node that matches one of typestypes
, orempty()
if none is found. The given type may also be an interface type, such as one of theNodeWith...
interface types.- Type Parameters:
N
-
-
isDescendantOf
default boolean isDescendantOf(Node ancestor)
Determines whether thisHasParentNode
node is a descendant of the given node. A node is not a descendant of itself.- Parameters:
ancestor
- the node for which to determine whether it has this node as an ancestor.- Returns:
true
if this node is a descendant of the given node, andfalse
otherwise.- See Also:
Node.isAncestorOf(Node)
-
-