Class AbstractJjtreeNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>

java.lang.Object
net.sourceforge.pmd.lang.ast.impl.AbstractNode<B,N>
net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<B,N>
All Implemented Interfaces:
GenericNode<N>, JjtreeNode<N>, Node, TextAvailableNode, Reportable

public abstract class AbstractJjtreeNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>> extends AbstractNode<B,N> implements JjtreeNode<N>
Base class for node produced by JJTree. JJTree specific functionality present on the API of Node and AbstractNode has been moved here for 7.0.0 (e.g. jjtClose methods).
  • Field Details

    • id

      protected final int id
  • Constructor Details

    • AbstractJjtreeNode

      protected AbstractJjtreeNode(int id)
      The id is an index in the constant names array generated by jjtree, it must be set to some value that depends on the node type, not some arbitrary "1" or "2", and not necessarily a unique value.
  • Method Details

    • 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.

      Note: This method will be deprecated in the future (#4787). It will be replaced with methods that have more specific names in node classes. In some cases, there are already alternatives available that should be used.

      Specified by:
      getImage in interface Node
    • setImage

      protected void setImage(String image)
    • getTextRegion

      public final TextRegion getTextRegion()
      Description copied from interface: Node
      Returns a region of text delimiting the node in the underlying text document. This does not necessarily match the report location.
      Specified by:
      getTextRegion in interface Node
      Specified by:
      getTextRegion in interface TextAvailableNode
    • compareLocation

      public final int compareLocation(Node other)
      Description copied from interface: Node
      Compare the coordinates of this node with the other one as if with Node.COORDS_COMPARATOR. The result is useless if both nodes are not from the same tree.
      Specified by:
      compareLocation in interface Node
      Parameters:
      other - Other node
      Returns:
      A positive integer if this node comes AFTER the other, 0 if they have the same position, a negative integer if this node comes BEFORE the other
    • jjtOpen

      protected void jjtOpen()
      This method is called after the node has been made the current node. It indicates that child nodes can now be added to it.
    • jjtClose

      protected void jjtClose()
      This method is called after all the child nodes have been added.
    • addChild

      protected void addChild(B child, int index)
      Description copied from class: AbstractNode
      Set the child at the given index to the given node. This resizes the children array to be able to contain the given index. Implementations must take care that this does not leave any "holes" in the array. This method throws if there is already a child at the given index.

      Note that it is more efficient to add children in reverse (from right to left), because the array is resized only the first time.

      This method also calls AbstractNode.setParent(AbstractNode).

      Overrides:
      addChild in class AbstractNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>
      Parameters:
      child - The child to add
      index - The index to which the child will be added
    • insertChild

      protected void insertChild(B child, int index)
      Description copied from class: AbstractNode
      Insert a child at the given index, shifting all the following children to the right.
      Overrides:
      insertChild in class AbstractNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>
      Parameters:
      child - New child
      index - Index (must be 0 <= index <= getNumChildren()), i.e. you cannot insert a node beyond the end, because that would leave holes in the array
    • fitTokensToChildren

      protected void fitTokensToChildren(int index)
      Ensures that the first (resp. last) token of this node is before (resp. after) the first (resp. last) token of the child at the given index. The index
    • enlargeLeft

      protected void enlargeLeft(JavaccToken childFst)
    • getFirstToken

      public JavaccToken getFirstToken()
      Specified by:
      getFirstToken in interface JjtreeNode<B extends AbstractJjtreeNode<B,N>>
    • getLastToken

      public JavaccToken getLastToken()
      Specified by:
      getLastToken in interface JjtreeNode<B extends AbstractJjtreeNode<B,N>>
    • setLastToken

      protected void setLastToken(JavaccToken token)
    • setFirstToken

      protected void setFirstToken(JavaccToken token)
    • toString

      public String toString()
      This toString implementation is only meant for debugging purposes.
      Overrides:
      toString in class AbstractNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>