View Javadoc
1 package test.net.sourceforge.pmd.symboltable; 2 3 import junit.framework.TestCase; 4 import net.sourceforge.pmd.ast.ASTName; 5 import net.sourceforge.pmd.ast.ASTPrimaryPrefix; 6 import net.sourceforge.pmd.ast.ASTVariableDeclaratorId; 7 import net.sourceforge.pmd.symboltable.LocalScope; 8 import net.sourceforge.pmd.symboltable.NameOccurrence; 9 import net.sourceforge.pmd.symboltable.VariableNameDeclaration; 10 11 public class LocalScopeTest extends TestCase { 12 13 private class MyASTVariableDeclaratorId extends ASTVariableDeclaratorId { 14 public MyASTVariableDeclaratorId(int x) { 15 super(x); 16 } 17 18 public boolean isExceptionBlockParameter() { 19 return true; 20 } 21 } 22 23 public void testNameWithThisOrSuperIsNotFlaggedAsUnused() { 24 LocalScope scope = new LocalScope(); 25 ASTName name = new ASTName(1); 26 name.setImage("foo"); 27 ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2); 28 prefix.setUsesThisModifier(); 29 name.jjtAddChild(prefix, 1); 30 NameOccurrence occ = new NameOccurrence(name, "foo"); 31 scope.addVariableNameOccurrence(occ); 32 assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext()); 33 } 34 35 public void testNameWithSuperIsNotFlaggedAsUnused() { 36 LocalScope scope = new LocalScope(); 37 ASTName name = new ASTName(1); 38 name.setImage("foo"); 39 ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2); 40 prefix.setUsesSuperModifier(); 41 name.jjtAddChild(prefix, 1); 42 NameOccurrence occ = new NameOccurrence(name, "foo"); 43 scope.addVariableNameOccurrence(occ); 44 assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext()); 45 } 46 47 public void testExceptionParamNameIsDiscarded() { 48 ASTVariableDeclaratorId node = new MyASTVariableDeclaratorId(1); 49 VariableNameDeclaration decl = new VariableNameDeclaration(node); 50 LocalScope scope = new LocalScope(); 51 scope.addDeclaration(decl); 52 assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext()); 53 } 54 55 }

This page was automatically generated by Maven