Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 74   Methods: 5
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NameFinder.java 88.9% 82.1% 80% 84.3%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd.symboltable;
 5   
 6    import net.sourceforge.pmd.ast.ASTName;
 7    import net.sourceforge.pmd.ast.ASTPrimaryExpression;
 8    import net.sourceforge.pmd.ast.ASTPrimaryPrefix;
 9    import net.sourceforge.pmd.ast.ASTPrimarySuffix;
 10    import net.sourceforge.pmd.ast.SimpleNode;
 11    import net.sourceforge.pmd.ast.ASTArguments;
 12   
 13    import java.util.Iterator;
 14    import java.util.LinkedList;
 15    import java.util.List;
 16    import java.util.StringTokenizer;
 17   
 18    public class NameFinder {
 19   
 20    private LinkedList names = new LinkedList();
 21   
 22  1690 public NameFinder(ASTPrimaryExpression node) {
 23  1690 ASTPrimaryPrefix prefix = (ASTPrimaryPrefix) node.jjtGetChild(0);
 24  1690 if (prefix.usesSuperModifier()) {
 25  22 add(new NameOccurrence(prefix, "super"));
 26  1668 } else if (prefix.usesThisModifier()) {
 27  32 add(new NameOccurrence(prefix, "this"));
 28    }
 29  1690 for (int i = 0; i < node.jjtGetNumChildren(); i++) {
 30  2088 checkForNameChild((SimpleNode)node.jjtGetChild(i));
 31    }
 32    }
 33   
 34  1696 public List getNames() {
 35  1696 return names;
 36    }
 37   
 38  2088 private void checkForNameChild(SimpleNode node) {
 39  2088 if (node.getImage() != null) {
 40  80 add(new NameOccurrence(node, node.getImage()));
 41    }
 42  2088 if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
 43  805 ASTName grandchild = (ASTName) node.jjtGetChild(0);
 44  805 for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens();) {
 45  959 add(new NameOccurrence(grandchild, st.nextToken()));
 46    }
 47    }
 48  2088 if (node instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) node).isArguments()) {
 49  327 NameOccurrence occurrence = (NameOccurrence)names.getLast();
 50  327 occurrence.setIsMethodOrConstructorInvocation();
 51  327 ASTArguments args = (ASTArguments)((ASTPrimarySuffix) node).jjtGetChild(0);
 52  327 occurrence.setArgumentCount(args.getArgumentCount());
 53   
 54    }
 55    }
 56   
 57  1093 private void add(NameOccurrence name) {
 58  1093 names.add(name);
 59  1093 if (names.size() > 1) {
 60  215 NameOccurrence qualifiedName = (NameOccurrence) names.get(names.size() - 2);
 61  215 qualifiedName.setNameWhichThisQualifies(name);
 62    }
 63    }
 64   
 65   
 66  0 public String toString() {
 67  0 StringBuffer result = new StringBuffer();
 68  0 for (Iterator i = names.iterator(); i.hasNext();) {
 69  0 NameOccurrence occ = (NameOccurrence) i.next();
 70  0 result.append(occ.getImage());
 71    }
 72  0 return result.toString();
 73    }
 74    }