Class AbstractNode

  • All Implemented Interfaces:
    Node
    Direct Known Subclasses:
    AbstractJjtreeNode

    public abstract class AbstractNode
    extends Object
    implements Node
    Base class for all implementations of the Node interface.

    Please use the Node interface wherever possible and not this class, unless you're compelled to do so.

    Note that nearly all methods of the Node interface will have default implementations with PMD 7.0.0, so that it will not be necessary to extend this class directly.

    • Field Detail

      • children

        protected Node[] children
      • beginLine

        @Deprecated
        protected int beginLine
        Deprecated.
        This will be removed to delegate to the tokens for nodes that are backed by tokens.
      • endLine

        @Deprecated
        protected int endLine
        Deprecated.
        This will be removed to delegate to the tokens for nodes that are backed by tokens.
      • beginColumn

        @Deprecated
        protected int beginColumn
        Deprecated.
        This will be removed to delegate to the tokens for nodes that are backed by tokens.
      • endColumn

        @Deprecated
        protected int endColumn
        Deprecated.
        This will be removed to delegate to the tokens for nodes that are backed by tokens.
    • Constructor Detail

      • AbstractNode

        public AbstractNode​(int id)
      • AbstractNode

        public AbstractNode​(int id,
                            int theBeginLine,
                            int theEndLine,
                            int theBeginColumn,
                            int theEndColumn)
    • Method Detail

      • getParent

        public Node getParent()
        Description copied from interface: Node
        Returns the parent of this node, or null if this is the root of the tree.

        This method should be preferred to Node.jjtGetParent().

        Specified by:
        getParent in interface Node
        Returns:
        The parent of this node
      • getIndexInParent

        public int getIndexInParent()
        Description copied from interface: Node
        Returns the index of this node in its parent's children. If this node is a root node, returns -1.
        Specified by:
        getIndexInParent in interface Node
        Returns:
        The index of this node in its parent's children
      • getChild

        public Node getChild​(int index)
        Description copied from interface: Node
        Returns the child of this node at the given index.
        Specified by:
        getChild in interface Node
      • getNumChildren

        public int getNumChildren()
        Description copied from interface: Node
        Returns the number of children of this node.
        Specified by:
        getNumChildren in interface Node
      • isSingleLine

        @Deprecated
        public boolean isSingleLine()
        Deprecated.
        This is never used and is trivial, will be removed from this class.
      • jjtOpen

        @Deprecated
        @InternalApi
        public void jjtOpen()
        Deprecated.
        Description copied from interface: Node
        This method is called after the node has been made the current node. It indicates that child nodes can now be added to it.
        Specified by:
        jjtOpen in interface Node
      • jjtClose

        @Deprecated
        @InternalApi
        public void jjtClose()
        Deprecated.
        Description copied from interface: Node
        This method is called after all the child nodes have been added.
        Specified by:
        jjtClose in interface Node
      • jjtSetParent

        @Deprecated
        @InternalApi
        public void jjtSetParent​(Node parent)
        Deprecated.
        Description copied from interface: Node
        Sets the parent of this node.
        Specified by:
        jjtSetParent in interface Node
        Parameters:
        parent - The parent
      • jjtGetParent

        @Deprecated
        public Node jjtGetParent()
        Deprecated.
        Description copied from interface: Node
        Returns the parent of this node.
        Specified by:
        jjtGetParent in interface Node
        Returns:
        The parent of the node
      • jjtAddChild

        @Deprecated
        @InternalApi
        public void jjtAddChild​(Node child,
                                int index)
        Deprecated.
        Description copied from interface: Node
        This method tells the node to add its argument to the node's list of children.
        Specified by:
        jjtAddChild in interface Node
        Parameters:
        child - The child to add
        index - The index to which the child will be added
      • jjtSetChildIndex

        @Deprecated
        @InternalApi
        public void jjtSetChildIndex​(int index)
        Deprecated.
        Description copied from interface: Node
        Sets the index of this node from the perspective of its parent. This means: this.getParent().getChild(index) == this.
        Specified by:
        jjtSetChildIndex in interface Node
        Parameters:
        index - the child index
      • jjtGetChild

        @Deprecated
        public Node jjtGetChild​(int index)
        Deprecated.
        Description copied from interface: Node
        This method returns a child node. The children are numbered from zero, left to right.
        Specified by:
        jjtGetChild in interface Node
        Parameters:
        index - the child index. Must be nonnegative and less than Node.jjtGetNumChildren().
      • jjtGetNumChildren

        @Deprecated
        public int jjtGetNumChildren()
        Deprecated.
        Description copied from interface: Node
        Returns the number of children the node has.
        Specified by:
        jjtGetNumChildren in interface Node
      • jjtGetId

        @Deprecated
        public int jjtGetId()
        Deprecated.
        Will be made protected with 7.0.0.
        Specified by:
        jjtGetId in interface Node
      • getImage

        public String getImage()
        Description copied from interface: Node
        Returns a string token, usually filled-in by the parser, which describes some textual characteristic of this node. This is usually an identifier, but you should check that using the Designer. On most nodes though, this method returns null.
        Specified by:
        getImage in interface Node
      • hasImageEqualTo

        public boolean hasImageEqualTo​(String image)
        Description copied from interface: Node
        Returns true if this node's image is equal to the given string.
        Specified by:
        hasImageEqualTo in interface Node
        Parameters:
        image - The image to check
      • getBeginLine

        public int getBeginLine()
        Specified by:
        getBeginLine in interface Node
      • testingOnlySetBeginLine

        @Deprecated
        @InternalApi
        public void testingOnlySetBeginLine​(int i)
        Deprecated.
        This will be removed with 7.0.0
      • getBeginColumn

        public int getBeginColumn()
        Specified by:
        getBeginColumn in interface Node
      • testingOnlySetBeginColumn

        @Deprecated
        @InternalApi
        public void testingOnlySetBeginColumn​(int i)
        Deprecated.
        This will be removed with 7.0.0
      • getEndLine

        public int getEndLine()
        Specified by:
        getEndLine in interface Node
      • testingOnlySetEndLine

        @Deprecated
        @InternalApi
        public void testingOnlySetEndLine​(int i)
        Deprecated.
        This will be removed with 7.0.0
      • getEndColumn

        public int getEndColumn()
        Specified by:
        getEndColumn in interface Node
      • testingOnlySetEndColumn

        @Deprecated
        @InternalApi
        public void testingOnlySetEndColumn​(int i)
        Deprecated.
        This will be removed with 7.0.0
      • hasDescendantOfAnyType

        @Deprecated
        public final boolean hasDescendantOfAnyType​(Class<? extends Node>... types)
        Deprecated.
        This is implemented inefficiently, with PMD 7 Node streams will provide a better alternative. We cannot ensure binary compatibility because the methods on 7.0 expect at least one class type, by requiring one Class parameter before the varargs (Effective Java 2nd ed., Item 42).
        Returns true if this node has a descendant of any type among the provided types.
        Parameters:
        types - Types to test
      • getUserData

        @Deprecated
        public Object getUserData()
        Deprecated.
        Description copied from interface: Node
        Get the user data associated with this node. By default there is no data, unless it has been set via Node.setUserData(Object).
        Specified by:
        getUserData in interface Node
        Returns:
        The user data set on this node.
      • setUserData

        @Deprecated
        public void setUserData​(Object userData)
        Deprecated.
        Description copied from interface: Node
        Set the user data associated with this node.

        PMD itself will never set user data onto a node. Nor should any Rule implementation, as the AST nodes are shared between concurrently executing Rules (i.e. it is not thread-safe).

        This API is most useful for external applications looking to leverage PMD's robust support for AST structures, in which case application specific annotations on the AST nodes can be quite useful.

        Specified by:
        setUserData in interface Node
        Parameters:
        userData - The data to set on this node.
      • jjtGetFirstToken

        @Deprecated
        public GenericToken jjtGetFirstToken()
        Deprecated.
        Not all nodes are based on tokens, and this is an implementation detail
      • jjtSetFirstToken

        @Deprecated
        public void jjtSetFirstToken​(GenericToken token)
        Deprecated.
        This is JJTree-specific and will be removed from this superclass.
      • jjtGetLastToken

        @Deprecated
        public GenericToken jjtGetLastToken()
        Deprecated.
        Not all nodes are based on tokens, and this is an implementation detail
      • jjtSetLastToken

        @Deprecated
        public void jjtSetLastToken​(GenericToken token)
        Deprecated.
        This is JJTree-specific and will be removed from this superclass.
      • remove

        @Deprecated
        @InternalApi
        public void remove()
        Deprecated.
        This is internal API
        Description copied from interface: Node
        Remove the current node from its parent.
        Specified by:
        remove in interface Node
      • removeChildAtIndex

        @Deprecated
        @InternalApi
        public void removeChildAtIndex​(int childIndex)
        Deprecated.
        This is internal API
        Description copied from interface: Node
        This method tells the node to remove the child node at the given index from the node's list of children, if any; if not, no changes are done.
        Specified by:
        removeChildAtIndex in interface Node
        Parameters:
        childIndex - The index of the child to be removed