net.sourceforge.pmd.lang.ast

## Class AbstractNode

- java.lang.Object
- - net.sourceforge.pmd.lang.ast.AbstractNode

- All Implemented Interfaces:
    Node
  Direct Known Subclasses:
    AbstractEcmascriptNode, AbstractJavaNode, AbstractJspNode, Comment, JavadocElement

      public abstract class AbstractNode
      extends Object
      implements Node

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `beginColumn`
    `protected int` | `beginLine`
    `protected Node[]` | `children`
    `protected int` | `endColumn`
    `protected int` | `endLine`
    `protected int` | `id`
    `protected Node` | `parent`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractNode(int id)`
    `AbstractNode(int id, int theBeginLine, int theEndLine, int theBeginColumn, int theEndColumn)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `appendElement(Node parentNode)`
    `List` | `findChildNodesWithXPath(String xpathString)` Returns all the nodes matching the xpath expression.
    `<T> List<T>` | `findChildrenOfType(Class<T> targetType)` 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 crossBoundaries)` 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)` Traverses up the tree to find the first parent instance of type parentType
    `String` | `getImage()`
    `Node` | `getNthParent(int n)` Returns the n-th parent or null if there are not `n` ancestors
    `<T> List<T>` | `getParentsOfType(Class<T> parentType)` Traverses up the tree to find all of the parent instances of type parentType
    `Object` | `getUserData()` Get the user data associated with this node.
    `boolean` | `hasDecendantOfAnyType(Class<?>... types)`
    `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()`
    `boolean` | `isSingleLine()`
    `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` | `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` | `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.
    `void` | `testingOnly__setBeginColumn(int i)`
    `void` | `testingOnly__setBeginLine(int i)`
    `void` | `testingOnly__setEndColumn(int i)`
    `void` | `testingOnly__setEndLine(int i)`
    `abstract String` | `toString()` Subclasses should implement this method to return a name usable with XPathRule for evaluating Element Names.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### parent

          protected Node parent

    - #### children

          protected Node[] children

    - #### id

          protected int id

    - #### beginLine

          protected int beginLine

    - #### endLine

          protected int endLine

    - #### beginColumn

          protected int beginColumn

    - #### endColumn

          protected int endColumn

  - ### Constructor Detail

    - #### AbstractNode

          public AbstractNode(int id)

    - #### AbstractNode

          public AbstractNode(int id,
                      int theBeginLine,
                      int theEndLine,
                      int theBeginColumn,
                      int theEndColumn)

  - ### Method Detail

    - #### isSingleLine

          public boolean isSingleLine()

    - #### jjtOpen

          public void jjtOpen()

      Description copied from interface: `Node`
      This method is called after the node has been made the current node. It indicates that child nodes can now be added to it.
      Specified by:
        `jjtOpen` in interface `Node`

    - #### jjtClose

          public void jjtClose()

      Description copied from interface: `Node`
      This method is called after all the child nodes have been added.
      Specified by:
        `jjtClose` in interface `Node`

    - #### jjtSetParent

          public void jjtSetParent(Node parent)

      Description copied from interface: `Node`
      This pair of methods are used to inform the node of its parent.
      Specified by:
        `jjtSetParent` in interface `Node`

    - #### jjtGetParent

          public Node jjtGetParent()

      Specified by:
        `jjtGetParent` in interface `Node`

    - #### jjtAddChild

          public void jjtAddChild(Node child,
                         int index)

      Description copied from interface: `Node`
      This method tells the node to add its argument to the node's list of children.
      Specified by:
        `jjtAddChild` in interface `Node`

    - #### jjtGetChild

          public Node jjtGetChild(int index)

      Description copied from interface: `Node`
      This method returns a child node. The children are numbered from zero, left to right.
      Specified by:
        `jjtGetChild` in interface `Node`
      Parameters:
        `index` - the child index. Must be nonnegative and less than `Node.jjtGetNumChildren()`.

    - #### jjtGetNumChildren

          public int jjtGetNumChildren()

      Description copied from interface: `Node`
      Return the number of children the node has.
      Specified by:
        `jjtGetNumChildren` in interface `Node`

    - #### jjtGetId

          public int jjtGetId()

      Specified by:
        `jjtGetId` in interface `Node`

    - #### toString

          public abstract String toString()

      Subclasses should implement this method to return a name usable with XPathRule for evaluating Element Names.
      Overrides:
        `toString` in class `Object`

    - #### getImage

          public String getImage()

      Specified by:
        `getImage` in interface `Node`

    - #### setImage

          public void setImage(String image)

      Specified by:
        `setImage` in interface `Node`

    - #### hasImageEqualTo

          public boolean hasImageEqualTo(String image)

      Specified by:
        `hasImageEqualTo` in interface `Node`

    - #### getBeginLine

          public int getBeginLine()

      Specified by:
        `getBeginLine` in interface `Node`

    - #### testingOnly__setBeginLine

          public void testingOnly__setBeginLine(int i)

    - #### getBeginColumn

          public int getBeginColumn()

      Specified by:
        `getBeginColumn` in interface `Node`

    - #### testingOnly__setBeginColumn

          public void testingOnly__setBeginColumn(int i)

    - #### getEndLine

          public int getEndLine()

      Specified by:
        `getEndLine` in interface `Node`

    - #### testingOnly__setEndLine

          public void testingOnly__setEndLine(int i)

    - #### getEndColumn

          public int getEndColumn()

      Specified by:
        `getEndColumn` in interface `Node`

    - #### testingOnly__setEndColumn

          public void testingOnly__setEndColumn(int i)

    - #### getDataFlowNode

          public DataFlowNode getDataFlowNode()

      Specified by:
        `getDataFlowNode` in interface `Node`

    - #### setDataFlowNode

          public void setDataFlowNode(DataFlowNode dataFlowNode)

      Specified by:
        `setDataFlowNode` in interface `Node`

    - #### getNthParent

          public Node getNthParent(int n)

      Returns the n-th parent or null if there are not `n` ancestors
      Specified by:
        `getNthParent` in interface `Node`
      Parameters:
        `n` - how many ancestors to iterate over.
      Returns:
        the n-th parent or null.
      Throws:
        `IllegalArgumentException` - if `n` is not positive.

    - #### getFirstParentOfType

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

      Traverses up the tree to find the first parent instance of type parentType
      Specified by:
        `getFirstParentOfType` in interface `Node`
      Parameters:
        `parentType` - class which you want to find.
      Returns:
        Node of type parentType. Returns null if none found.

    - #### getParentsOfType

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

      Traverses up the tree to find all of the parent instances of type parentType
      Specified by:
        `getParentsOfType` in interface `Node`
      Parameters:
        `parentType` - classes which you want to find.
      Returns:
        List of parentType instances found.

    - #### findDescendantsOfType

          public <T> List<T> findDescendantsOfType(Class<T> targetType)

      Traverses down the tree to find all the descendant instances of type descendantType.
      Specified by:
        `findDescendantsOfType` in interface `Node`
      Parameters:
        `targetType` - class which you want to find.
      Returns:
        List of all children of type targetType. Returns an empty list if none found.

    - #### findDescendantsOfType

          public <T> void findDescendantsOfType(Class<T> targetType,
                                       List<T> results,
                                       boolean crossBoundaries)

      Traverses down the tree to find all the descendant instances of type descendantType.
      Specified by:
        `findDescendantsOfType` in interface `Node`
      Parameters:
        `targetType` - class which you want to find.
        `results` - list to store the matching descendants
        `crossBoundaries` - if `false`, recursion stops for nodes for which `Node.isFindBoundary()` is `true`

    - #### findChildrenOfType

          public <T> List<T> findChildrenOfType(Class<T> targetType)

      Traverses the children to find all the instances of type childType.
      Specified by:
        `findChildrenOfType` in interface `Node`
      Parameters:
        `targetType` - 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.`

    - #### isFindBoundary

          public boolean isFindBoundary()

      Specified by:
        `isFindBoundary` in interface `Node`

    - #### getAsDocument

          public Document getAsDocument()

      Description copied from interface: `Node`
      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.
      Specified by:
        `getAsDocument` in interface `Node`

    - #### appendElement

          protected void appendElement(Node parentNode)

    - #### getFirstDescendantOfType

          public <T> T getFirstDescendantOfType(Class<T> descendantType)

      Traverses down the tree to find the first descendant instance of type descendantType.
      Specified by:
        `getFirstDescendantOfType` in interface `Node`
      Parameters:
        `descendantType` - class which you want to find.
      Returns:
        Node of type descendantType. Returns `null` if none found.

    - #### getFirstChildOfType

          public <T> T getFirstChildOfType(Class<T> childType)

      Traverses the children to find the first instance of type childType.
      Specified by:
        `getFirstChildOfType` in interface `Node`
      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.`

    - #### hasDescendantOfType

          public final <T> boolean hasDescendantOfType(Class<T> type)

      Finds if this node contains a descendant of the given type.
      Specified by:
        `hasDescendantOfType` in interface `Node`
      Parameters:
        `type` - the node type to search
      Returns:
        `true` if there is at least one descendant of the given type

    - #### hasDecendantOfAnyType

          public final boolean hasDecendantOfAnyType(Class<?>... types)

      Parameters:
        `types` -
      Returns:
        boolean

    - #### findChildNodesWithXPath

          public List findChildNodesWithXPath(String xpathString)
                                       throws org.jaxen.JaxenException

      Returns all the nodes matching the xpath expression.
      Specified by:
        `findChildNodesWithXPath` in interface `Node`
      Parameters:
        `xpathString` - the expression to check
      Returns:
        List of all matching nodes. Returns an empty list if none found.
      Throws:
        `org.jaxen.JaxenException`

    - #### hasDescendantMatchingXPath

          public boolean hasDescendantMatchingXPath(String xpathString)

      Checks whether at least one descendant matches the xpath expression.
      Specified by:
        `hasDescendantMatchingXPath` in interface `Node`
      Parameters:
        `xpathString` - the expression to check
      Returns:
        true if there is a match

    - #### getUserData

          public Object getUserData()

      Get the user data associated with this node. By default there is no data, unless it has been set via `Node.setUserData(Object)`.
      Specified by:
        `getUserData` in interface `Node`
      Returns:
        The user data set on this node.

    - #### setUserData

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

      Specified by:
        `setUserData` in interface `Node`
      Parameters:
        `userData` - The data to set on this node.

Copyright © 2002-2013 InfoEther. All Rights Reserved.