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
@Experimental 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 ofNode
andAbstractNode
will be moved here for 7.0.0.This is experimental because it's expected to change for 7.0.0 in unforeseeable ways. Don't use it directly, use the node interfaces.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
id
-
Fields inherited from interface net.sourceforge.pmd.lang.ast.Node
COORDS_COMPARATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addChild(B child, int index)
Set the child at the given index to the given node.int
compareLocation(Node other)
Compare the coordinates of this node with the other one as if withNode.COORDS_COMPARATOR
.protected void
fitTokensToChildren(int index)
Ensures that the first (resp.JavaccToken
getFirstToken()
String
getImage()
Returns a string token, usually filled-in by the parser, which describes some textual characteristic of this node.JavaccToken
getLastToken()
TextRegion
getTextRegion()
Returns a region of text delimiting the node in the underlying text document.protected void
insertChild(B child, int index)
Insert a child at the given index, shifting all the following children to the right.protected void
jjtClose()
This method is called after all the child nodes have been added.protected void
jjtOpen()
This method is called after the node has been made the current node.protected void
setFirstToken(JavaccToken token)
protected void
setImage(String image)
protected void
setLastToken(JavaccToken token)
String
toString()
This toString implementation is only meant for debugging purposes.-
Methods inherited from class net.sourceforge.pmd.lang.ast.impl.AbstractNode
children, firstChild, getChild, getIndexInParent, getNumChildren, getParent, getUserMap, remove, removeChildAtIndex, setChild, setParent
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.GenericNode
ancestors, ancestorsOrSelf, asStream, children, descendants, descendantsOrSelf, getChild, getFirstChild, getLastChild, getNextSibling, getNthParent, getParent, getPreviousSibling
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode
tokens
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.Node
acceptVisitor, ancestors, children, descendants, findChildNodesWithXPath, findChildrenOfType, findDescendantsOfType, findDescendantsOfType, firstChild, getAstInfo, getBeginColumn, getBeginLine, getEndColumn, getEndLine, getFirstChildOfType, getFirstDescendantOfType, getFirstParentOfType, getIndexInParent, getLanguageVersion, getNumChildren, getParentsOfType, getReportLocation, getRoot, getTextDocument, getUserMap, getXPathAttributesIterator, getXPathNodeName, hasDescendantOfType, hasImageEqualTo, isFindBoundary
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.TextAvailableNode
getOriginalText, getText
-
-
-
-
Method Detail
-
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 returnsnull
.
-
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 thereport location
.- Specified by:
getTextRegion
in interfaceNode
- Specified by:
getTextRegion
in interfaceTextAvailableNode
-
compareLocation
public final int compareLocation(Node other)
Description copied from interface:Node
Compare the coordinates of this node with the other one as if withNode.COORDS_COMPARATOR
. The result is useless if both nodes are not from the same tree.- Specified by:
compareLocation
in interfaceNode
- 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 classAbstractNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>
- Parameters:
child
- The child to addindex
- 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 classAbstractNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>
- Parameters:
child
- New childindex
- Index (must be 0 <= index <= getNumChildren()), ie you can 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
-
getFirstToken
public JavaccToken getFirstToken()
- Specified by:
getFirstToken
in interfaceJjtreeNode<B extends AbstractJjtreeNode<B,N>>
-
getLastToken
public JavaccToken getLastToken()
- Specified by:
getLastToken
in interfaceJjtreeNode<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 classAbstractNode<B extends AbstractJjtreeNode<B,N>,N extends JjtreeNode<N>>
-
-