Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 89   Methods: 9
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeIterator.java 83.3% 90.3% 88.9% 87.9%
coverage coverage
 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.Node;
 7   
 8    import java.util.Iterator;
 9    import java.util.NoSuchElementException;
 10   
 11    /**
 12    * @author daniels
 13    */
 14    public abstract class NodeIterator implements Iterator {
 15   
 16    private Node node;
 17   
 18  22274 public NodeIterator(Node contextNode) {
 19  22274 this.node = getFirstNode(contextNode);
 20    }
 21   
 22  63325 public boolean hasNext() {
 23  63325 return node != null;
 24    }
 25   
 26  21775 public Object next() {
 27  21775 if (node == null)
 28  0 throw new NoSuchElementException();
 29  21775 Node ret = node;
 30  21775 node = getNextNode(node);
 31  21775 return ret;
 32    }
 33   
 34  0 public void remove() {
 35  0 throw new UnsupportedOperationException();
 36    }
 37   
 38    protected abstract Node getFirstNode(Node contextNode);
 39   
 40    protected abstract Node getNextNode(Node contextNode);
 41   
 42  21 protected Node getPreviousSibling(Node contextNode) {
 43  21 Node parentNode = contextNode.jjtGetParent();
 44  21 if (parentNode != null) {
 45  18 int prevPosition = getPositionFromParent(contextNode) - 1;
 46  18 if (prevPosition >= 0) {
 47  6 return parentNode.jjtGetChild(prevPosition);
 48    }
 49    }
 50  15 return null;
 51    }
 52   
 53  21834 private int getPositionFromParent(Node contextNode) {
 54  21834 Node parentNode = contextNode.jjtGetParent();
 55  27488 for (int i = 0; i < parentNode.jjtGetNumChildren(); i++) {
 56  27488 if (parentNode.jjtGetChild(i) == contextNode) {
 57  21834 return i;
 58    }
 59    }
 60  0 throw new RuntimeException("Node was not a child of it's parent ???");
 61    }
 62   
 63  21816 protected Node getNextSibling(Node contextNode) {
 64  21816 Node parentNode = contextNode.jjtGetParent();
 65  21816 if (parentNode != null) {
 66  21816 int nextPosition = getPositionFromParent(contextNode) + 1;
 67  21816 if (nextPosition < parentNode.jjtGetNumChildren()) {
 68  4296 return parentNode.jjtGetChild(nextPosition);
 69    }
 70    }
 71  17520 return null;
 72    }
 73   
 74  22218 protected Node getFirstChild(Node contextNode) {
 75  22218 if (contextNode.jjtGetNumChildren() > 0) {
 76  17487 return contextNode.jjtGetChild(0);
 77    } else {
 78  4731 return null;
 79    }
 80    }
 81   
 82  4 protected Node getLastChild(Node contextNode) {
 83  4 if (contextNode.jjtGetNumChildren() > 0) {
 84  2 return contextNode.jjtGetChild(contextNode.jjtGetNumChildren() - 1);
 85    } else {
 86  2 return null;
 87    }
 88    }
 89    }