Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
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 | 3542 | public NameFinder(ASTPrimaryExpression node) {
23 | 3542 | ASTPrimaryPrefix prefix = (ASTPrimaryPrefix) node.jjtGetChild(0);
24 | 3542 | if (prefix.usesSuperModifier()) {
25 | 29 | add(new NameOccurrence(prefix, "super"));
26 | 3513 | } else if (prefix.usesThisModifier()) {
27 | 44 | add(new NameOccurrence(prefix, "this"));
28 |  | }
29 | 3542 | for (int i = 0; i < node.jjtGetNumChildren(); i++) {
30 | 4587 | checkForNameChild((SimpleNode) node.jjtGetChild(i));
31 |  | }
32 |  | }
33 |  |
34 | 3548 | public List getNames() {
35 | 3548 | return names;
36 |  | }
37 |  |
38 | 4587 | private void checkForNameChild(SimpleNode node) {
39 | 4587 | if (node.getImage() != null) {
40 | 136 | add(new NameOccurrence(node, node.getImage()));
41 |  | }
42 | 4587 | if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
43 | 1716 | ASTName grandchild = (ASTName) node.jjtGetChild(0);
44 | 1716 | for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens();) {
45 | 2313 | add(new NameOccurrence(grandchild, st.nextToken()));
46 |  | }
47 |  | }
48 | 4587 | if (node instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) node).isArguments()) {
49 | 896 | NameOccurrence occurrence = (NameOccurrence) names.getLast();
50 | 896 | occurrence.setIsMethodOrConstructorInvocation();
51 | 896 | ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0);
52 | 896 | occurrence.setArgumentCount(args.getArgumentCount());
53 |  |
54 |  | }
55 |  | }
56 |  |
57 | 2522 | private void add(NameOccurrence name) {
58 | 2522 | names.add(name);
59 | 2522 | if (names.size() > 1) {
60 | 710 | NameOccurrence qualifiedName = (NameOccurrence) names.get(names.size() - 2);
61 | 710 | 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 |  | }