1 /***
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package test.net.sourceforge.pmd.symboltable;
5
6 import net.sourceforge.pmd.PMD;
7 import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
8 import net.sourceforge.pmd.ast.SimpleNode;
9 import net.sourceforge.pmd.symboltable.NameOccurrence;
10
11 public class AcceptanceTest extends STBBaseTst {
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public void testFieldFinder() {
54 System.out.println(TEST_FIELD);
55 parseCode(TEST_FIELD);
56 ASTVariableDeclaratorId declaration = (ASTVariableDeclaratorId)acu.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
57 NameOccurrence no = (NameOccurrence)declaration.getUsages().iterator().next();
58 SimpleNode location = no.getLocation();
59 System.out.println("variable " + declaration.getImage() + " is used here: " + location.getImage());
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 private static final String TEST_DEMO =
85 "public class Foo {" + PMD.EOL +
86 " void bar(ArrayList buz) { " + PMD.EOL +
87 " } " + PMD.EOL +
88 "}" + PMD.EOL;
89
90 private static final String TEST_EQ =
91 "public class Foo {" + PMD.EOL +
92 " boolean foo(String a, String b) { " + PMD.EOL +
93 " return a == b; " + PMD.EOL +
94 " } " + PMD.EOL +
95 "}" + PMD.EOL;
96
97 private static final String TEST1 =
98 "import java.io.*;" + PMD.EOL +
99 "public class Foo {" + PMD.EOL +
100 " void buz( ) {" + PMD.EOL +
101 " Object o = new Serializable() { int x; };" + PMD.EOL +
102 " Object o1 = new Serializable() { int x; };" + PMD.EOL +
103 " }" + PMD.EOL +
104 "}" + PMD.EOL;
105
106 private static final String TEST_INITIALIZERS =
107 "public class Foo {" + PMD.EOL +
108 " {} " + PMD.EOL +
109 " static {} " + PMD.EOL +
110 "}" + PMD.EOL;
111
112 private static final String TEST_CATCH_BLOCKS =
113 "public class Foo {" + PMD.EOL +
114 " void foo() { " + PMD.EOL +
115 " try { " + PMD.EOL +
116 " } catch (Exception e) { " + PMD.EOL +
117 " e.printStackTrace(); " + PMD.EOL +
118 " } " + PMD.EOL +
119 " } " + PMD.EOL +
120 "}" + PMD.EOL;
121
122 private static final String TEST_FIELD =
123 "public class MyClass {" + PMD.EOL +
124 " private int a; " + PMD.EOL +
125 " boolean b = MyClass.ASCENDING; " + PMD.EOL +
126 "}" + PMD.EOL;
127
128
129 }