01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package test.net.sourceforge.pmd.ast;
04:
05: import static org.junit.Assert.assertEquals;
06: import static org.junit.Assert.assertTrue;
07: import net.sourceforge.pmd.PMD;
08: import net.sourceforge.pmd.ast.ASTBlock;
09: import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
10: import net.sourceforge.pmd.ast.ASTCompilationUnit;
11: import net.sourceforge.pmd.ast.ASTTryStatement;
12: import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
13:
14: import org.junit.Test;
15:
16: import test.net.sourceforge.pmd.testframework.ParserTst;
17:
18: public class ASTVariableDeclaratorIdTest extends ParserTst {
19:
20: @Test
21: public void testIsExceptionBlockParameter() {
22: ASTTryStatement tryNode = new ASTTryStatement(1);
23: ASTBlock block = new ASTBlock(2);
24: ASTVariableDeclaratorId v = new ASTVariableDeclaratorId(3);
25: v.jjtSetParent(block);
26: block.jjtSetParent(tryNode);
27: assertTrue(v.isExceptionBlockParameter());
28: }
29:
30: @Test
31: public void testTypeNameNode() throws Throwable {
32: ASTCompilationUnit acu = super .getNodes(
33: ASTCompilationUnit.class, TYPE_NAME_NODE).iterator()
34: .next();
35: ASTVariableDeclaratorId id = acu.findChildrenOfType(
36: ASTVariableDeclaratorId.class).get(0);
37:
38: ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) id
39: .getTypeNameNode().jjtGetChild(0);
40: assertEquals("String", name.getImage());
41: }
42:
43: @Test
44: public void testAnnotations() throws Throwable {
45: ASTCompilationUnit acu = super .getNodes(
46: ASTCompilationUnit.class, TEST_ANNOTATIONS).iterator()
47: .next();
48: ASTVariableDeclaratorId id = acu.findChildrenOfType(
49: ASTVariableDeclaratorId.class).get(0);
50:
51: ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) id
52: .getTypeNameNode().jjtGetChild(0);
53: assertEquals("String", name.getImage());
54: }
55:
56: private static final String TYPE_NAME_NODE = "public class Test {"
57: + PMD.EOL + " private String bar;" + PMD.EOL + "}";
58:
59: private static final String TEST_ANNOTATIONS = "public class Foo {"
60: + PMD.EOL + " public void bar(@A1 @A2 String s) {}"
61: + PMD.EOL + "}";
62:
63: public static junit.framework.Test suite() {
64: return new junit.framework.JUnit4TestAdapter(
65: ASTVariableDeclaratorIdTest.class);
66: }
67: }
|