GlobalScopeTest xref

View Javadoc
1 package net.sourceforge.pmd.symboltable;
2 
3 import static org.junit.Assert.assertEquals;
4 
5 import java.util.Map;
6 
7 import net.sourceforge.pmd.PMD;
8 import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
9 import net.sourceforge.pmd.lang.java.symboltable.ClassNameDeclaration;
10 import net.sourceforge.pmd.lang.symboltable.Scope;
11 
12 import org.junit.Test;
13 
14 public class GlobalScopeTest extends STBBaseTst {
15 
16 @Test
17 public void testClassDeclAppears() {
18 parseCode(TEST1);
19 ASTCompilationUnit decl = acu;
20 Scope scope = decl.getScope();
21 Map m = scope.getDeclarations();
22 ClassNameDeclaration classNameDeclaration = (ClassNameDeclaration) m.keySet().iterator().next();
23 assertEquals(classNameDeclaration.getImage(), "Foo");
24 }
25 
26 @Test
27 public void testEnums() {
28 parseCode15(TEST2);
29 }
30 
31 private static final String TEST1 =
32 "public class Foo {}" + PMD.EOL;
33 
34 private static final String TEST2 =
35 "public enum Bar {" + PMD.EOL +
36 " FOO1 { " + PMD.EOL +
37 " private static final String FIELD_NAME = \"\";" + PMD.EOL +
38 " }," + PMD.EOL +
39 " FOO2 { " + PMD.EOL +
40 " private static final String FIELD_NAME = \"\";" + PMD.EOL +
41 " }" + PMD.EOL +
42 "}" + PMD.EOL;
43 
44 public static junit.framework.Test suite() {
45 return new junit.framework.JUnit4TestAdapter(GlobalScopeTest.class);
46 }
47 }

AltStyle によって変換されたページ (->オリジナル) /