Node.java
001 /* Generated By:JJTree: Do not edit this line. Node.java */
002 
003 package net.sourceforge.pmd.lang.ast;
004 
005 import java.util.List;
006 
007 import net.sourceforge.pmd.lang.dfa.DataFlowNode;
008 
009 import org.jaxen.JaxenException;
010 import org.w3c.dom.Document;
011 
012 /* All AST nodes must implement this interface.  It provides basic
013    machinery for constructing the parent and child relationships
014    between nodes. */
015 
016 public interface Node {
017 
018     /**
019      * This method is called after the node has been made the current
020      * node.  It indicates that child nodes can now be added to it.
021      */
022     void jjtOpen();
023 
024     /**
025      * This method is called after all the child nodes have been
026      * added.
027      */
028     void jjtClose();
029 
030     /**
031      * This pair of methods are used to inform the node of its
032      * parent.
033      */
034     void jjtSetParent(Node parent);
035 
036     Node jjtGetParent();
037 
038     /**
039      * This method tells the node to add its argument to the node's
040      * list of children.
041      */
042     void jjtAddChild(Node child, int index);
043 
044     /**
045      * This method returns a child node.  The children are numbered
046      * from zero, left to right.
047      *
048      @param index the child index. Must be nonnegative and less than
049      *          {@link #jjtGetNumChildren}.
050      */
051     Node jjtGetChild(int index);
052 
053     /**
054      * Return the number of children the node has.
055      */
056     int jjtGetNumChildren();
057 
058     int jjtGetId();
059 
060     String getImage();
061 
062     void setImage(String image);
063 
064     boolean hasImageEqualTo(String image);
065 
066     int getBeginLine();
067 
068     int getBeginColumn();
069 
070     int getEndLine();
071 
072     int getEndColumn();
073 
074     DataFlowNode getDataFlowNode();
075 
076     void setDataFlowNode(DataFlowNode dataFlowNode);
077 
078     boolean isFindBoundary();
079 
080     Node getNthParent(int n);
081 
082     <T> T getFirstParentOfType(Class<T> parentType);
083 
084     <T> List<T> getParentsOfType(Class<T> parentType);
085 
086     /**
087      * Traverses the children to find all the instances of type childType.
088      *
089      @see #findDescendantsOfType(Class) if traversal of the entire tree is needed.
090      *
091      @param childType class which you want to find.
092      @return List of all children of type childType. Returns an empty list if none found.
093      */
094     <T> List<T> findChildrenOfType(Class<T> childType);
095 
096     /**
097      * Traverses down the tree to find all the descendant instances of type descendantType.
098      *
099      @param targetType class which you want to find.
100      @return List of all children of type targetType. Returns an empty list if none found.
101      */
102     <T> List<T> findDescendantsOfType(Class<T> targetType);
103 
104     /**
105      * Traverses down the tree to find all the descendant instances of type descendantType.
106      *
107      @param targetType class which you want to find.
108      @param results list to store the matching descendants
109      @param crossFindBoundaries if <code>false</code>, recursion stops for nodes for which {@link #isFindBoundary()} is <code>true</code>
110      */
111     <T> void findDescendantsOfType(Class<T> targetType, List<T> results, boolean crossFindBoundaries);
112 
113     /**
114      * Traverses the children to find the first instance of type childType.
115      *
116      @see #getFirstDescendantOfType(Class) if traversal of the entire tree is needed.
117      *
118      @param childType class which you want to find.
119      @return Node of type childType. Returns <code>null</code> if none found.
120      */
121     <T> T getFirstChildOfType(Class<T> childType);
122 
123     /**
124      * Traverses down the tree to find the first descendant instance of type descendantType.
125      *
126      @param descendantType class which you want to find.
127      @return Node of type descendantType. Returns <code>null</code> if none found.
128      */
129     <T> T getFirstDescendantOfType(Class<T> descendantType);
130 
131     /**
132      * Finds if this node contains a descendant of the given type.
133      *
134      @param type the node type to search
135      @return <code>true</code> if there is at least one descendant of the given type
136      */
137     <T> boolean hasDescendantOfType(Class<T> type);
138 
139     /**
140      * Returns all the nodes matching the xpath expression.
141      *
142      @param xpathString the expression to check
143      @return List of all matching nodes. Returns an empty list if none found.
144      @throws JaxenException
145      */
146     List<? extends Node> findChildNodesWithXPath(String xpathStringthrows JaxenException;
147 
148     /**
149      * Checks whether at least one descendant matches the xpath expression.
150      *
151      @param xpathString the expression to check
152      @return true if there is a match
153      */
154     boolean hasDescendantMatchingXPath(String xpathString);
155 
156     /**
157      * Get a DOM Document which contains Elements and Attributes representative
158      * of this Node and it's children.  Essentially a DOM tree representation of
159      * the Node AST, thereby allowing tools which can operate upon DOM to
160      * also indirectly operate on the AST.
161      */
162     Document getAsDocument();
163 }