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
,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
,LongLiteralExpr
,MarkerAnnotationExpr
,MemberValuePair
,MethodCallExpr
,MethodDeclaration
,MethodReferenceExpr
,Modifier
,ModuleDeclaration
,ModuleDirective
,ModuleExportsDirective
,ModuleOpensDirective
,ModuleProvidesDirective
,ModuleRequiresDirective
,ModuleUsesDirective
,Name
,NameExpr
,Node
,NodeList
,NormalAnnotationExpr
,NullLiteralExpr
,ObjectCreationExpr
,PackageDeclaration
,Parameter
,PrimitiveType
,ReceiverParameter
,ReferenceType
,ReturnStmt
,SimpleName
,SingleMemberAnnotationExpr
,Statement
,StringLiteralExpr
,SuperExpr
,SwitchEntryStmt
,SwitchExpr
,SwitchStmt
,SynchronizedStmt
,ThisExpr
,ThrowStmt
,TryStmt
,Type
,TypeDeclaration
,TypeExpr
,TypeParameter
,UnaryExpr
,UnionType
,UnknownType
,UnparsableStmt
,VariableDeclarationExpr
,VariableDeclarator
,VarType
,VoidType
,WhileStmt
,WildcardType
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> 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 typetype
that matchespredicate
, orempty()
if none is found.default <N> Optional<N>
findParent(Class<N> type)
Deprecated.usefindAncestor(Class)
.default <N> Optional<N>
getAncestorOfType(Class<N> classType)
Deprecated.usefindAncestor(Class)
.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.T
setParentNode(Node parentNode)
Sets the parent node.-
Methods inherited from interface com.github.javaparser.ast.observer.Observable
isRegistered, register, unregister
-
-
-
-
Method Detail
-
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:
- 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).
-
getAncestorOfType
@Deprecated default <N> Optional<N> getAncestorOfType(Class<N> classType)
Deprecated.usefindAncestor(Class)
.
-
findParent
@Deprecated default <N> Optional<N> findParent(Class<N> type)
Deprecated.usefindAncestor(Class)
.
-
findAncestor
default <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. The given type may also be an interface type, such as one of theNodeWith...
interface types.
-
findAncestor
default <N> Optional<N> findAncestor(Class<N> type, Predicate<N> predicate)
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.
-
-