net.sourceforge.pmd.lang.ast
Interface Node

All Known Subinterfaces:
DFAGraphMethod, ScopedNode
All Known Implementing Classes:
AbstractNode

public interface Node


Method Summary
 List<? extends Node> findChildNodesWithXPath(String xpathString)
          Returns all the nodes matching the xpath expression.
<T> List<T>
findChildrenOfType(Class<T> childType)
          Traverses the children to find all the instances of type childType.
<T> List<T>
findDescendantsOfType(Class<T> targetType)
          Traverses down the tree to find all the descendant instances of type descendantType.
<T> void
findDescendantsOfType(Class<T> targetType, List<T> results, boolean crossFindBoundaries)
          Traverses down the tree to find all the descendant instances of type descendantType.
 Document getAsDocument()
          Get a DOM Document which contains Elements and Attributes representative of this Node and it's children.
 int getBeginColumn()
           
 int getBeginLine()
           
 DataFlowNode getDataFlowNode()
           
 int getEndColumn()
           
 int getEndLine()
           
<T> T
getFirstChildOfType(Class<T> childType)
          Traverses the children to find the first instance of type childType.
<T> T
getFirstDescendantOfType(Class<T> descendantType)
          Traverses down the tree to find the first descendant instance of type descendantType.
<T> T
getFirstParentOfType(Class<T> parentType)
           
 String getImage()
           
 Node getNthParent(int n)
           
<T> List<T>
getParentsOfType(Class<T> parentType)
           
 Object getUserData()
          Get the user data associated with this node.
 boolean hasDescendantMatchingXPath(String xpathString)
          Checks whether at least one descendant matches the xpath expression.
<T> boolean
hasDescendantOfType(Class<T> type)
          Finds if this node contains a descendant of the given type.
 boolean hasImageEqualTo(String image)
           
 boolean isFindBoundary()
           
 void jjtAddChild(Node child, int index)
          This method tells the node to add its argument to the node's list of children.
 void jjtClose()
          This method is called after all the child nodes have been added.
 Node jjtGetChild(int index)
          This method returns a child node.
 int jjtGetChildIndex()
           
 int jjtGetId()
           
 int jjtGetNumChildren()
          Return the number of children the node has.
 Node jjtGetParent()
           
 void jjtOpen()
          This method is called after the node has been made the current node.
 void jjtSetChildIndex(int index)
          Sets the index of this node from the perspective of its parent.
 void jjtSetParent(Node parent)
          This pair of methods are used to inform the node of its parent.
 void setDataFlowNode(DataFlowNode dataFlowNode)
           
 void setImage(String image)
           
 void setUserData(Object userData)
          Set the user data associated with this node.
 

Method Detail

jjtOpen

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

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


jjtSetParent

void jjtSetParent(Node parent)
This pair of methods are used to inform the node of its parent.


jjtGetParent

Node jjtGetParent()

jjtAddChild

void jjtAddChild(Node child,
                 int index)
This method tells the node to add its argument to the node's list of children.


jjtSetChildIndex

void jjtSetChildIndex(int index)
Sets the index of this node from the perspective of its parent. This means: this.jjtGetParent().jjtGetChild(index) == this.

Parameters:
index - the child index

jjtGetChildIndex

int jjtGetChildIndex()

jjtGetChild

Node jjtGetChild(int index)
This method returns a child node. The children are numbered from zero, left to right.

Parameters:
index - the child index. Must be nonnegative and less than jjtGetNumChildren().

jjtGetNumChildren

int jjtGetNumChildren()
Return the number of children the node has.


jjtGetId

int jjtGetId()

getImage

String getImage()

setImage

void setImage(String image)

hasImageEqualTo

boolean hasImageEqualTo(String image)

getBeginLine

int getBeginLine()

getBeginColumn

int getBeginColumn()

getEndLine

int getEndLine()

getEndColumn

int getEndColumn()

getDataFlowNode

DataFlowNode getDataFlowNode()

setDataFlowNode

void setDataFlowNode(DataFlowNode dataFlowNode)

isFindBoundary

boolean isFindBoundary()

getNthParent

Node getNthParent(int n)

getFirstParentOfType

<T> T getFirstParentOfType(Class<T> parentType)

getParentsOfType

<T> List<T> getParentsOfType(Class<T> parentType)

findChildrenOfType

<T> List<T> findChildrenOfType(Class<T> childType)
Traverses the children to find all the instances of type childType.

Parameters:
childType - class which you want to find.
Returns:
List of all children of type childType. Returns an empty list if none found.
See Also:
if traversal of the entire tree is needed.

findDescendantsOfType

<T> List<T> findDescendantsOfType(Class<T> targetType)
Traverses down the tree to find all the descendant instances of type descendantType.

Parameters:
targetType - class which you want to find.
Returns:
List of all children of type targetType. Returns an empty list if none found.

findDescendantsOfType

<T> void findDescendantsOfType(Class<T> targetType,
                               List<T> results,
                               boolean crossFindBoundaries)
Traverses down the tree to find all the descendant instances of type descendantType.

Parameters:
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

getFirstChildOfType

<T> T getFirstChildOfType(Class<T> childType)
Traverses the children to find the first instance of type childType.

Parameters:
childType - class which you want to find.
Returns:
Node of type childType. Returns null if none found.
See Also:
if traversal of the entire tree is needed.

getFirstDescendantOfType

<T> T getFirstDescendantOfType(Class<T> descendantType)
Traverses down the tree to find the first descendant instance of type descendantType.

Parameters:
descendantType - class which you want to find.
Returns:
Node of type descendantType. Returns null if none found.

hasDescendantOfType

<T> boolean hasDescendantOfType(Class<T> type)
Finds if this node contains a descendant of the given type.

Parameters:
type - the node type to search
Returns:
true if there is at least one descendant of the given type

findChildNodesWithXPath

List<? extends Node> findChildNodesWithXPath(String xpathString)
                                             throws org.jaxen.JaxenException
Returns all the nodes matching the xpath expression.

Parameters:
xpathString - the expression to check
Returns:
List of all matching nodes. Returns an empty list if none found.
Throws:
org.jaxen.JaxenException

hasDescendantMatchingXPath

boolean hasDescendantMatchingXPath(String xpathString)
Checks whether at least one descendant matches the xpath expression.

Parameters:
xpathString - the expression to check
Returns:
true if there is a match

getAsDocument

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.


getUserData

Object getUserData()
Get the user data associated with this node. By default there is no data, unless it has been set via setUserData(Object).

Returns:
The user data set on this node.

setUserData

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.

Parameters:
userData - The data to set on this node.


Copyright © 2002-2015 InfoEther. All Rights Reserved.