Class BaseAntlrNode<A extends BaseAntlrNode.AntlrToPmdParseTreeAdapter<N>,N extends AntlrNode<N>>
- java.lang.Object
-
- net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrNode<A,N>
-
- Type Parameters:
A
- Type of the underlying antlr nodeN
- Public interface (eg SwiftNode)
- All Implemented Interfaces:
AntlrNode<N>
,GenericNode<N>
,Node
,Reportable
- Direct Known Subclasses:
BaseAntlrInnerNode
,BaseAntlrTerminalNode
public abstract class BaseAntlrNode<A extends BaseAntlrNode.AntlrToPmdParseTreeAdapter<N>,N extends AntlrNode<N>> extends Object implements AntlrNode<N>
Base class for an antlr node. This implements the PMD interfaces only, not the antlr ones. It wraps an antlr node (they are linked both ways). Antlr primarily distinguishesParserRuleContext
for inner nodes,TerminalNode
for nodes that wrap tokens (and can have no children), andErrorNode
, a subtype ofTerminalNode
. These each have a base class here, which refines the type of the underlying antlr node:BaseAntlrInnerNode
,BaseAntlrTerminalNode
andBaseAntlrErrorNode
. These must be implemented in each language module with a class that also implements<N>
.During tree construction, the antlr runtime does its thing with the underlying antlr nodes. The PMD nodes are just wrappers around those, that respect the contract of
GenericNode
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
BaseAntlrNode.AntlrToPmdParseTreeAdapter<N extends AntlrNode<N>>
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.lang.ast.Node
COORDS_COMPARATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseAntlrNode()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected abstract A
asAntlrNode()
int
getBeginColumn()
Gets the column offset from the start of the begin line where the token's region beginsint
getBeginLine()
Gets the line where the token's region beginsint
getEndColumn()
Gets the column offset from the start of the end line where the token's region endsint
getEndLine()
Gets the line where the token's region endsabstract org.antlr.v4.runtime.Token
getFirstAntlrToken()
int
getIndexInParent()
Returns the index of this node in its parent's children.abstract org.antlr.v4.runtime.Token
getLastAntlrToken()
N
getParent()
Returns the parent of this node, or null if this is the root of the tree.TextRegion
getTextRegion()
Returns a region of text delimiting the node in the underlying text document.DataMap<DataMap.DataKey<?,?>>
getUserMap()
Returns a data map used to store additional information on this node.String
joinTokenText()
Deprecated.Some rules depend on it and have not been rewritten-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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, getPreviousSibling
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.Node
acceptVisitor, ancestors, children, compareLocation, descendants, findChildNodesWithXPath, findChildrenOfType, findDescendantsOfType, findDescendantsOfType, firstChild, getAstInfo, getFirstChildOfType, getFirstDescendantOfType, getFirstParentOfType, getImage, getLanguageVersion, getNumChildren, getParentsOfType, getReportLocation, getRoot, getTextDocument, getXPathAttributesIterator, getXPathNodeName, hasDescendantOfType, hasImageEqualTo, isFindBoundary
-
-
-
-
Method Detail
-
joinTokenText
@Deprecated public String joinTokenText()
Deprecated.Some rules depend on it and have not been rewrittenRecurses over the text of all terminal descendants to build the text of this node (without spaces). This is extremely inefficient and should not be used to write rules. The antlr impl doesn't even use a single stringbuilder.
-
getFirstAntlrToken
public abstract org.antlr.v4.runtime.Token getFirstAntlrToken()
-
getLastAntlrToken
public abstract org.antlr.v4.runtime.Token getLastAntlrToken()
-
getTextRegion
public 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
-
getParent
public N getParent()
Description copied from interface:Node
Returns the parent of this node, or null if this is the root of the tree.- Specified by:
getParent
in interfaceGenericNode<A extends BaseAntlrNode.AntlrToPmdParseTreeAdapter<N>>
- Specified by:
getParent
in interfaceNode
- Returns:
- The parent of this node
-
getBeginLine
public int getBeginLine()
Description copied from interface:Reportable
Gets the line where the token's region begins- Specified by:
getBeginLine
in interfaceNode
- Specified by:
getBeginLine
in interfaceReportable
-
getEndLine
public int getEndLine()
Description copied from interface:Reportable
Gets the line where the token's region ends- Specified by:
getEndLine
in interfaceNode
- Specified by:
getEndLine
in interfaceReportable
-
getBeginColumn
public int getBeginColumn()
Description copied from interface:Reportable
Gets the column offset from the start of the begin line where the token's region begins- Specified by:
getBeginColumn
in interfaceNode
- Specified by:
getBeginColumn
in interfaceReportable
-
getEndColumn
public int getEndColumn()
Description copied from interface:Reportable
Gets the column offset from the start of the end line where the token's region ends- Specified by:
getEndColumn
in interfaceNode
- Specified by:
getEndColumn
in interfaceReportable
-
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 interfaceNode
- Returns:
- The index of this node in its parent's children
-
getUserMap
public DataMap<DataMap.DataKey<?,?>> getUserMap()
Description copied from interface:Node
Returns a data map used to store additional information on this node.- Specified by:
getUserMap
in interfaceNode
- Returns:
- The user data map of this node
-
asAntlrNode
protected abstract A asAntlrNode()
-
-