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> type)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)Walks the parents of this node and returns the first node of typetypethat matchespredicate, orempty()if none is found.Returns the parent node, orOptional.emptyif no parent is set.Returns the parent node from the perspective of the children of this node.default booleanReturns true if the parent has a parentdefault booleanisDescendantOf(Node ancestor)Determines whether thisHasParentNodenode 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.emptyif no parent is set. -
setParentNode
Sets the parent node.- Parameters:
parentNode- the parent node, ornullto 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
thisfor everything exceptNodeList. ANodeListreturns its parent node instead. This is because aNodeListsets the parent of all its children to its own parent node (seeNodeListfor 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
Walks the parents of this node and returns the first node of typetypethat matchespredicate, orempty()if none is found. The given type may also be an interface type, such as one of theNodeWith...interface types. -
isDescendantOf
Determines whether thisHasParentNodenode 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:
trueif this node is a descendant of the given node, andfalseotherwise.- See Also:
Node.isAncestorOf(Node)
-