Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |

file stats: | LOC: | 263 |  | Methods: | 39
| NCLOC: | 183 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL
DocumentNavigator.java | 53.6% | 65.3% | 74.4% | 65.5% |

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 |  | */
4 |  | package net.sourceforge.pmd.jaxen;
5 |  |
6 |  | import net.sourceforge.pmd.ast.CompilationUnit;
7 |  | import net.sourceforge.pmd.ast.Node;
8 |  | import org.jaxen.DefaultNavigator;
9 |  | import org.jaxen.XPath;
10 |  | import org.jaxen.util.SingleObjectIterator;
11 |  |
12 |  | import java.util.ArrayList;
13 |  | import java.util.Iterator;
14 |  |
15 |  | /**
16 |  | * @author daniels
17 |  | */
18 |  | public class DocumentNavigator extends DefaultNavigator {
19 |  |
20 |  | private final static Iterator EMPTY_ITERATOR = new ArrayList().iterator();
21 |  |
22 | 8742 | public String getAttributeName(Object arg0) {
23 | 8742 | return ((Attribute) arg0).getName();
24 |  | }
25 |  |
26 | 8742 | public String getAttributeNamespaceUri(Object arg0) {
27 | 8742 | return null;
28 |  | }
29 |  |
30 | 0 | public String getAttributeQName(Object arg0) {
31 | 0 | return ((Attribute) arg0).getName();
32 |  | }
33 |  |
34 | 955 | public String getAttributeStringValue(Object arg0) {
35 | 955 | return ((Attribute) arg0).getValue();
36 |  | }
37 |  |
38 | 0 | public String getCommentStringValue(Object arg0) {
39 | 0 | return null;
40 |  | }
41 |  |
42 | 20863 | public String getElementName(Object node) {
43 | 20863 | return node.toString();
44 |  | }
45 |  |
46 | 20508 | public String getElementNamespaceUri(Object arg0) {
47 | 20508 | return null;
48 |  | }
49 |  |
50 | 355 | public String getElementQName(Object arg0) {
51 | 355 | return getElementName(arg0);
52 |  | }
53 |  |
54 | 0 | public String getElementStringValue(Object arg0) {
55 | 0 | return null;
56 |  | }
57 |  |
58 | 0 | public String getNamespacePrefix(Object arg0) {
59 | 0 | return null;
60 |  | }
61 |  |
62 | 0 | public String getNamespaceStringValue(Object arg0) {
63 | 0 | return null;
64 |  | }
65 |  |
66 | 0 | public String getTextStringValue(Object arg0) {
67 | 0 | return null;
68 |  | }
69 |  |
70 | 11717 | public boolean isAttribute(Object arg0) {
71 | 11717 | return arg0 instanceof Attribute;
72 |  | }
73 |  |
74 | 1712 | public boolean isComment(Object arg0) {
75 | 1712 | return false;
76 |  | }
77 |  |
78 | 3574 | public boolean isDocument(Object arg0) {
79 | 3574 | return arg0 instanceof CompilationUnit;
80 |  | }
81 |  |
82 | 32281 | public boolean isElement(Object arg0) {
83 | 32281 | return arg0 instanceof Node;
84 |  | }
85 |  |
86 | 1783 | public boolean isNamespace(Object arg0) {
87 | 1783 | return false;
88 |  | }
89 |  |
90 | 1712 | public boolean isProcessingInstruction(Object arg0) {
91 | 1712 | return false;
92 |  | }
93 |  |
94 | 13126 | public boolean isText(Object arg0) {
95 | 13126 | return false;
96 |  | }
97 |  |
98 | 0 | public XPath parseXPath(String arg0) {
99 | 0 | return null;
100 |  | }
101 |  |
102 | 3294 | public Object getParentNode(Object arg0) {
103 | 3294 | if (arg0 instanceof Node) {
104 | 3294 | return ((Node) arg0).jjtGetParent();
105 |  | }
106 | 0 | return ((Attribute) arg0).getParent();
107 |  | }
108 |  |
109 | 973 | public Iterator getAttributeAxisIterator(Object arg0) {
110 | 973 | return new AttributeAxisIterator((Node) arg0);
111 |  | }
112 |  |
113 |  | /**
114 |  | * Get an iterator over all of this node's children.
115 |  | *
116 |  | * @param contextNode The context node for the child axis.
117 |  | * @return A possibly-empty iterator (not null).
118 |  | */
119 | 36683 | public Iterator getChildAxisIterator(Object contextNode) {
120 | 36683 | return new NodeIterator((Node) contextNode) {
121 | 36683 | protected Node getFirstNode(Node node) {
122 | 36683 | return getFirstChild(node);
123 |  | }
124 |  |
125 | 35931 | protected Node getNextNode(Node node) {
126 | 35931 | return getNextSibling(node);
127 |  | }
128 |  | };
129 |  | }
130 |  |
131 |  | /**
132 |  | * Get a (single-member) iterator over this node's parent.
133 |  | *
134 |  | * @param contextNode the context node for the parent axis.
135 |  | * @return A possibly-empty iterator (not null).
136 |  | */
137 | 228 | public Iterator getParentAxisIterator(Object contextNode) {
138 | 228 | if (isAttribute(contextNode)) {
139 | 0 | return new SingleObjectIterator(((Attribute) contextNode).getParent());
140 |  | }
141 | 228 | Node parent = ((Node) contextNode).jjtGetParent();
142 | 228 | if (parent != null) {
143 | 227 | return new SingleObjectIterator(parent);
144 |  | } else {
145 | 1 | return EMPTY_ITERATOR;
146 |  | }
147 |  | }
148 |  |
149 |  | /**
150 |  | * Get an iterator over all following siblings.
151 |  | *
152 |  | * @param contextNode the context node for the sibling iterator.
153 |  | * @return A possibly-empty iterator (not null).
154 |  | */
155 | 79 | public Iterator getFollowingSiblingAxisIterator(Object contextNode) {
156 | 79 | return new NodeIterator((Node) contextNode) {
157 | 79 | protected Node getFirstNode(Node node) {
158 | 79 | return getNextNode(node);
159 |  | }
160 |  |
161 | 155 | protected Node getNextNode(Node node) {
162 | 155 | return getNextSibling(node);
163 |  | }
164 |  | };
165 |  | }
166 |  |
167 |  | /**
168 |  | * Get an iterator over all preceding siblings.
169 |  | *
170 |  | * @param contextNode The context node for the preceding sibling axis.
171 |  | * @return A possibly-empty iterator (not null).
172 |  | */
173 | 5 | public Iterator getPrecedingSiblingAxisIterator(Object contextNode) {
174 | 5 | return new NodeIterator((Node) contextNode) {
175 | 5 | protected Node getFirstNode(Node node) {
176 | 5 | return getNextNode(node);
177 |  | }
178 |  |
179 | 9 | protected Node getNextNode(Node node) {
180 | 9 | return getPreviousSibling(node);
181 |  | }
182 |  | };
183 |  | }
184 |  |
185 |  | /**
186 |  | * Get an iterator over all following nodes, depth-first.
187 |  | *
188 |  | * @param contextNode The context node for the following axis.
189 |  | * @return A possibly-empty iterator (not null).
190 |  | */
191 | 0 | public Iterator getFollowingAxisIterator(Object contextNode) {
192 | 0 | return new NodeIterator((Node) contextNode) {
193 | 0 | protected Node getFirstNode(Node node) {
194 | 0 | if (node == null)
195 | 0 | return null;
196 |  | else {
197 | 0 | Node sibling = getNextSibling(node);
198 | 0 | if (sibling == null)
199 | 0 | return getFirstNode(node.jjtGetParent());
200 |  | else
201 | 0 | return sibling;
202 |  | }
203 |  | }
204 |  |
205 | 0 | protected Node getNextNode(Node node) {
206 | 0 | if (node == null)
207 | 0 | return null;
208 |  | else {
209 | 0 | Node n = getFirstChild(node);
210 | 0 | if (n == null)
211 | 0 | n = getNextSibling(node);
212 | 0 | if (n == null)
213 | 0 | return getFirstNode(node.jjtGetParent());
214 |  | else
215 | 0 | return n;
216 |  | }
217 |  | }
218 |  | };
219 |  | }
220 |  |
221 |  | /**
222 |  | * Get an iterator over all preceding nodes, depth-first.
223 |  | *
224 |  | * @param contextNode The context node for the preceding axis.
225 |  | * @return A possibly-empty iterator (not null).
226 |  | */
227 | 3 | public Iterator getPrecedingAxisIterator(Object contextNode) {
228 | 3 | return new NodeIterator((Node) contextNode) {
229 | 14 | protected Node getFirstNode(Node node) {
230 | 14 | if (node == null)
231 | 3 | return null;
232 |  | else {
233 | 11 | Node sibling = getPreviousSibling(node);
234 | 11 | if (sibling == null)
235 | 9 | return getFirstNode(node.jjtGetParent());
236 |  | else
237 | 2 | return sibling;
238 |  | }
239 |  | }
240 |  |
241 | 4 | protected Node getNextNode(Node node) {
242 | 4 | if (node == null)
243 | 0 | return null;
244 |  | else {
245 | 4 | Node n = getLastChild(node);
246 | 4 | if (n == null)
247 | 2 | n = getPreviousSibling(node);
248 | 4 | if (n == null)
249 | 2 | return getFirstNode(node.jjtGetParent());
250 |  | else
251 | 2 | return n;
252 |  | }
253 |  | }
254 |  | };
255 |  | }
256 |  |
257 | 907 | public Object getDocumentNode(Object contextNode) {
258 | 907 | if (isDocument(contextNode)) {
259 | 507 | return contextNode;
260 |  | }
261 | 400 | return getDocumentNode(getParentNode(contextNode));
262 |  | }
263 |  | }