1 package test.net.sourceforge.pmd.symboltable;
2
3 import junit.framework.TestCase;
4 import net.sourceforge.pmd.ast.ASTBlock;
5 import net.sourceforge.pmd.ast.ASTClassBodyDeclaration;
6 import net.sourceforge.pmd.ast.ASTCompilationUnit;
7 import net.sourceforge.pmd.ast.ASTConstructorDeclaration;
8 import net.sourceforge.pmd.ast.ASTForStatement;
9 import net.sourceforge.pmd.ast.ASTIfStatement;
10 import net.sourceforge.pmd.ast.ASTMethodDeclaration;
11 import net.sourceforge.pmd.ast.ASTTryStatement;
12 import net.sourceforge.pmd.ast.ASTUnmodifiedClassDeclaration;
13 import net.sourceforge.pmd.ast.ASTUnmodifiedInterfaceDeclaration;
14 import net.sourceforge.pmd.symboltable.BasicScopeFactory;
15 import net.sourceforge.pmd.symboltable.ClassScope;
16 import net.sourceforge.pmd.symboltable.GlobalScope;
17 import net.sourceforge.pmd.symboltable.LocalScope;
18 import net.sourceforge.pmd.symboltable.MethodScope;
19 import net.sourceforge.pmd.symboltable.ScopeFactory;
20
21 import java.util.Stack;
22
23 public class BasicScopeFactoryTest extends TestCase {
24
25 public void testGlobalScope() {
26 ScopeFactory sf = new BasicScopeFactory();
27 Stack s = new Stack();
28 sf.openScope(s, new ASTCompilationUnit(1));
29 assertEquals(1, s.size());
30 assertTrue(s.get(0) instanceof GlobalScope);
31 }
32
33 public void testClassScope() {
34 ScopeFactory sf = new BasicScopeFactory();
35 Stack s = new Stack();
36 sf.openScope(s, new ASTCompilationUnit(1));
37 sf.openScope(s, new ASTUnmodifiedClassDeclaration(2));
38 assertTrue(s.get(1) instanceof ClassScope);
39 sf.openScope(s, new ASTUnmodifiedInterfaceDeclaration(1));
40 assertTrue(s.get(2) instanceof ClassScope);
41 sf.openScope(s, new ASTClassBodyDeclaration(1));
42 assertTrue(s.get(3) instanceof ClassScope);
43 }
44
45 public void testMethodScope() {
46 ScopeFactory sf = new BasicScopeFactory();
47 Stack s = new Stack();
48 sf.openScope(s, new ASTCompilationUnit(1));
49 sf.openScope(s, new ASTMethodDeclaration(2));
50 assertTrue(s.get(1) instanceof MethodScope);
51 sf.openScope(s, new ASTConstructorDeclaration(1));
52 assertTrue(s.get(2) instanceof MethodScope);
53 }
54
55 public void testLocalScope() {
56 ScopeFactory sf = new BasicScopeFactory();
57 Stack s = new Stack();
58 sf.openScope(s, new ASTCompilationUnit(1));
59 sf.openScope(s, new ASTBlock(2));
60 assertTrue(s.get(1) instanceof LocalScope);
61 sf.openScope(s, new ASTTryStatement(1));
62 assertTrue(s.get(2) instanceof LocalScope);
63 sf.openScope(s, new ASTForStatement(1));
64 assertTrue(s.get(3) instanceof LocalScope);
65 sf.openScope(s, new ASTIfStatement(1));
66 assertTrue(s.get(4) instanceof LocalScope);
67 }
68 }
This page was automatically generated by Maven