1 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 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 76 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 } 130 | Popular Tags |