Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 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%

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.ASTArguments;
7 |  | import net.sourceforge.pmd.ast.ASTName;
8 |  | import net.sourceforge.pmd.ast.ASTPrimaryExpression;
9 |  | import net.sourceforge.pmd.ast.ASTPrimaryPrefix;
10 |  | import net.sourceforge.pmd.ast.ASTPrimarySuffix;
11 |  | import net.sourceforge.pmd.ast.SimpleNode;
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 | 2945 | public NameFinder(ASTPrimaryExpression node) {
23 | 2945 | ASTPrimaryPrefix prefix = (ASTPrimaryPrefix) node.jjtGetChild(0);
24 | 2945 | if (prefix.usesSuperModifier()) {
25 | 25 | add(new NameOccurrence(prefix, "super"));
26 | 2920 | } else if (prefix.usesThisModifier()) {
27 | 32 | add(new NameOccurrence(prefix, "this"));
28 |  | }
29 | 2945 | for (int i = 0; i < node.jjtGetNumChildren(); i++) {
30 | 3806 | checkForNameChild((SimpleNode) node.jjtGetChild(i));
31 |  | }
32 |  | }
33 |  |
34 | 2951 | public List getNames() {
35 | 2951 | return names;
36 |  | }
37 |  |
38 | 3806 | private void checkForNameChild(SimpleNode node) {
39 | 3806 | if (node.getImage() != null) {
40 | 114 | add(new NameOccurrence(node, node.getImage()));
41 |  | }
42 | 3806 | if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
43 | 1388 | ASTName grandchild = (ASTName) node.jjtGetChild(0);
44 | 1388 | for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens();) {
45 | 1920 | add(new NameOccurrence(grandchild, st.nextToken()));
46 |  | }
47 |  | }
48 | 3806 | if (node instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) node).isArguments()) {
49 | 737 | NameOccurrence occurrence = (NameOccurrence) names.getLast();
50 | 737 | occurrence.setIsMethodOrConstructorInvocation();
51 | 737 | ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0);
52 | 737 | occurrence.setArgumentCount(args.getArgumentCount());
53 |  |
54 |  | }
55 |  | }
56 |  |
57 | 2091 | private void add(NameOccurrence name) {
58 | 2091 | names.add(name);
59 | 2091 | if (names.size() > 1) {
60 | 624 | NameOccurrence qualifiedName = (NameOccurrence) names.get(names.size() - 2);
61 | 624 | 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 |  | }