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

public interface HasParentNode<T> extends Observable
An object that can have a parent node.
  • Method Summary

    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 type type, or empty() 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 types types, or empty() if none is found.
    Returns the parent node, or Optional.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 parent
    default boolean
    isDescendantOf​(Node ancestor)
    Determines whether this HasParentNode 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

      Optional<Node> getParentNode()
      Returns the parent node, or Optional.empty if no parent is set.
    • setParentNode

      T setParentNode(Node parentNode)
      Sets the parent node.
      Parameters:
      parentNode - the parent node, or null 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 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 NodeList for details).

    • findAncestor

      default <N> Optional<N> findAncestor(Class<N>... types)
      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.
    • 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 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.
    • 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 types types, or empty() if none is found. The given type may also be an interface type, such as one of the NodeWith... interface types.
      Type Parameters:
      N -
    • isDescendantOf

      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 - 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, and false otherwise.
      See Also:
      Node.isAncestorOf(Node)