DFAGraphMethod
, QualifiableNode
, RootNode
, ScopedNode
, SignedNode<N>
AbstractJjtreeNode
, AbstractNode
, PlainTextLanguage.PlainTextFile
public interface Node
Root interface for all AST nodes. This interface provides only the API shared by all AST implementations in PMD language modules. This includes for now:
getParent()
and getFirstChildOfType(Class)
getXPathNodeName()
, getXPathAttributesIterator()
getBeginLine()
, getBeginColumn()
Additionally, the
user data mapis an extensibility mechanism with which any client can independently associate values to AST nodes.
Every language implementation must publish a sub-interface of Node which serves as a supertype for all nodes of that language (e.g. pmd-java provides JavaNode, pmd-apex provides ApexNode, etc.). It is assumed in many places that the getChild(int)
and getParent()
method return an instance of this sub-interface. For example, no JSP node should have a Java node as its child. Embedding nodes from different languages will not be done via these methods, and conforming implementations should ensure that every node returned by these methods are indeed of the same type. Possibly, a type parameter will be added to the Node interface in 7.0.0 to enforce it at compile-time.
A number of methods are deprecated and will be removed in 7.0.0. Most of them are implementation details that clutter this API and make implementation more difficult. Some methods prefixed with jjt
have a more conventional counterpart (e.g. jjtGetParent()
and getParent()
) that should be preferred.
@Deprecated 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.
@Deprecated void jjtClose()
This method is called after all the child nodes have been added.
@Deprecated void jjtSetParent(Node parent)
Sets the parent of this node.
parent
- The parent
@Deprecated Node jjtGetParent()
Returns the parent of this node.
@Deprecated void jjtAddChild(Node child, int index)
This method tells the node to add its argument to the node's list of children.
child
- The child to add
index
- The index to which the child will be added
@Deprecated void jjtSetChildIndex(int index)
Sets the index of this node from the perspective of its parent. This means: this.getParent().getChild(index) == this.
index
- the child index
@Deprecated int jjtGetChildIndex()
Gets the index of this node in the children of its parent.
@Deprecated Node jjtGetChild(int index)
This method returns a child node. The children are numbered from zero, left to right.
index
- the child index. Must be nonnegative and less than jjtGetNumChildren()
.
@Deprecated int jjtGetNumChildren()
Returns the number of children the node has.
@Deprecated int jjtGetId()
String getImage()
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
.
@InternalApi @Deprecated void setImage(String image)
boolean hasImageEqualTo(String image)
Returns true if this node's image is equal to the given string.
image
- The image to check
int getBeginLine()
int getBeginColumn()
int getEndLine()
int getEndColumn()
@Deprecated DataFlowNode getDataFlowNode()
@Deprecated void setDataFlowNode(DataFlowNode dataFlowNode)
@DeprecatedAttribute boolean isFindBoundary()
Returns true if this node is considered a boundary by traversal methods. Traversal methods such as
getFirstDescendantOfType(Class)
don't look past such boundaries by default, which is usually the expected thing to do. For example, in Java, lambdas and nested classes are considered find boundaries.
Note: This attribute is deprecated for XPath queries. It is not useful for XPath queries and will be removed with PMD 7.0.0.
Node getNthParent(int n)
Returns the n-th parent or null if there are less than n
ancestors.
n
- how many ancestors to iterate over.
IllegalArgumentException
- if n
is negative or zero.
<T> T getFirstParentOfType(Class<T> parentType)
Traverses up the tree to find the first parent instance of type parentType or one of its subclasses.
T
- The type you want to find
parentType
- Class literal of the type you want to find
<T> List<T> getParentsOfType(Class<T> parentType)
Traverses up the tree to find all of the parent instances of type parentType or one of its subclasses. The nodes are ordered deepest-first.
T
- The type you want to find
parentType
- Class literal of the type you want to find
@Deprecated <T> T getFirstParentOfAnyType(Class<? extends T>... parentTypes)
Gets the first parent that's an instance of any of the given types.
T
- Most specific common type of the parameters
parentTypes
- Types to look for
<T> List<T> findChildrenOfType(Class<T> childType)
Traverses the children to find all the instances of type childType or one of its subclasses.
childType
- class which you want to find.
if traversal of the entire tree is needed.
<T> List<T> findDescendantsOfType(Class<? extends T> targetType)
Traverses down the tree to find all the descendant instances of type descendantType without crossing find boundaries.
targetType
- class which you want to find.
@Deprecated <T> void findDescendantsOfType(Class<T> targetType, List<T> results, boolean crossFindBoundaries)
Traverses down the tree to find all the descendant instances of type descendantType.
targetType
- class which you want to find.
results
- list to store the matching descendants
crossFindBoundaries
- if false
, recursion stops for nodes for which isFindBoundary()
is true
<T> List<T> findDescendantsOfType(Class<T> targetType, boolean crossFindBoundaries)
Traverses down the tree to find all the descendant instances of type descendantType.
targetType
- class which you want to find.
crossFindBoundaries
- if false
, recursion stops for nodes for which isFindBoundary()
is true
<T> T getFirstChildOfType(Class<T> childType)
Traverses the children to find the first instance of type childType.
childType
- class which you want to find.
null
if none found.
if traversal of the entire tree is needed.
<T> T getFirstDescendantOfType(Class<T> descendantType)
Traverses down the tree to find the first descendant instance of type descendantType without crossing find boundaries.
descendantType
- class which you want to find.
null
if none found.
<T> boolean hasDescendantOfType(Class<T> type)
Finds if this node contains a descendant of the given type without crossing find boundaries.
type
- the node type to search
true
if there is at least one descendant of the given type
@Deprecated List<? extends Node> findChildNodesWithXPath(String xpathString) throws org.jaxen.JaxenException
Returns all the nodes matching the xpath expression.
xpathString
- the expression to check
org.jaxen.JaxenException
- if the xpath is incorrect or fails altogether
@Deprecated boolean hasDescendantMatchingXPath(String xpathString)
Checks whether at least one descendant matches the xpath expression.
xpathString
- the expression to check
@Deprecated Document getAsDocument()
Get a DOM Document which contains Elements and Attributes representative of this Node and it's children. Essentially a DOM tree representation of the Node AST, thereby allowing tools which can operate upon DOM to also indirectly operate on the AST.
@Deprecated Object getUserData()
Get the user data associated with this node. By default there is no data, unless it has been set via
setUserData(Object)
.
@Deprecated void setUserData(Object userData)
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.
userData
- The data to set on this node.
@Deprecated @InternalApi void remove()
Remove the current node from its parent.
@Deprecated @InternalApi void removeChildAtIndex(int childIndex)
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.
childIndex
- The index of the child to be removed
DataMap<DataMap.DataKey<?,?>> getUserMap()
Node getParent()
Returns the parent of this node, or null if this is the
rootof the tree.
This method should be preferred to jjtGetParent()
.
Node getChild(int index)
Returns the child of this node at the given index.
IndexOutOfBoundsException
- if the index is negative or greater than getNumChildren()
.
int getNumChildren()
Returns the number of children of this node.
int getIndexInParent()
Returns the index of this node in its parent's children. If this node is a
root node, returns -1.
This method replaces jjtGetChildIndex()
, whose name was JJTree-specific.
String getXPathNodeName()
Gets the name of the node that is used to match it with XPath queries.
Iterator<Attribute> getXPathAttributesIterator()
Returns an iterator enumerating all the attributes that are available from XPath for this node.
Iterable<? extends Node> children()
Returns an iterable enumerating the children of this node. Use it with a foreach loop:
for (Node child : node.children()) {
// process child
}
This method's return type will be changed to NodeStream in PMD 7, which is a more powerful kind of iterable. The change will be source compatible.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4