1 package test.net.sourceforge.pmd.symboltable; 2 3 import net.sourceforge.pmd.PMD; 4 import net.sourceforge.pmd.ast.ASTMethodDeclaration; 5 import net.sourceforge.pmd.symboltable.MethodScope; 6 import net.sourceforge.pmd.symboltable.NameOccurrence; 7 import net.sourceforge.pmd.symboltable.VariableNameDeclaration; 8 9 import java.util.List ; 10 import java.util.Map ; 11 12 public class MethodScopeTest extends STBBaseTst { 13 14 public void testMethodParameterOccurrenceRecorded() { 15 parseCode(TEST1); 16 Map m = ((ASTMethodDeclaration) (acu.findChildrenOfType(ASTMethodDeclaration.class)).get(0)).getScope().getVariableDeclarations(); 17 VariableNameDeclaration vnd = (VariableNameDeclaration) m.keySet().iterator().next(); 18 assertEquals("bar", vnd.getImage()); 19 List occs = (List ) m.get(vnd); 20 NameOccurrence occ = (NameOccurrence) occs.get(0); 21 assertEquals(3, occ.getLocation().getBeginLine()); 22 } 23 24 public void testMethodName() { 25 parseCode(TEST1); 26 ASTMethodDeclaration meth = (ASTMethodDeclaration) (acu.findChildrenOfType(ASTMethodDeclaration.class)).get(0); 27 MethodScope ms = (MethodScope) meth.getScope(); 28 assertEquals(ms.getName(), "foo"); 29 } 30 31 public static final String TEST1 = 32 "public class Foo {" + PMD.EOL + 33 " void foo(int bar) {" + PMD.EOL + 34 " bar = 2;" + PMD.EOL + 35 " }" + PMD.EOL + 36 "}"; 37 38 } 39 | Popular Tags |