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
,ReferenceType
,ReturnStmt
,SimpleName
,SingleMemberAnnotationExpr
,Statement
,StringLiteralExpr
,SuperExpr
,SwitchEntry
,SwitchExpr
,SwitchStmt
,SynchronizedStmt
,TextBlockLiteralExpr
,ThisExpr
,ThrowStmt
,TryStmt
,Type
,TypeDeclaration
,TypeExpr
,TypeParameter
,UnaryExpr
,UnionType
,UnknownType
,UnparsableStmt
,VariableDeclarationExpr
,VariableDeclarator
,VarType
,VoidType
,WhileStmt
,WildcardType
,YieldStmt
An object that can have a parent node.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <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.Returns the parent node, orOptional.empty
if no parent is set.Returns the parent node from the perspective of the children of this node.default boolean
Returns true if the parent has a parentdefault boolean
isDescendantOf(Node ancestor)
Determines whether thisHasParentNode
node is a descendant of the given node.setParentNode(Node parentNode)
Sets the parent node.Methods inherited from interface com.github.javaparser.ast.observer.Observable
isRegistered, register, unregister
-
Method Details
-
hasParentNode
default boolean hasParentNode()Returns true if the parent has a parent -
getParentNode
Returns the parent node, orOptional.empty
if no parent is set. -
setParentNode
Sets the parent node.- Parameters:
parentNode
- the parent node, ornull
to set no parent.- Returns:
- return
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
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.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
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
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)
-