    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.ast;
    5
    6   import net.sourceforge.pmd.PMD;
    7   import net.sourceforge.pmd.ast.ASTBlock;
    8   import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
    9   import net.sourceforge.pmd.ast.ASTCompilationUnit;
    10  import net.sourceforge.pmd.ast.ASTTryStatement;
    11  import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
    12  import test.net.sourceforge.pmd.testframework.ParserTst;
    13
    14  public class ASTVariableDeclaratorIdTest extends ParserTst {
    15
    16      public void testIsExceptionBlockParameter() {
    17          ASTTryStatement tryNode = new ASTTryStatement(1);
    18          ASTBlock block = new ASTBlock(2);
    19          ASTVariableDeclaratorId v = new ASTVariableDeclaratorId(3);
    20          v.jjtSetParent(block);
    21          block.jjtSetParent(tryNode);
    22          assertTrue(v.isExceptionBlockParameter());
    23      }
    24
    25      public void testTypeNameNode() throws Throwable {
    26          ASTCompilationUnit acu = (ASTCompilationUnit) (super.getNodes(ASTCompilationUnit.class, TYPE_NAME_NODE).iterator().next());
    27          ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) acu.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
    28
    29          ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) id.getTypeNameNode().jjtGetChild(0);
    30          assertEquals("String", name.getImage());
    31      }
    32
    33      private static final String TYPE_NAME_NODE =
    34              "public class Test {" + PMD.EOL +
    35              "  private String bar;" + PMD.EOL +
    36              "}";
    37
    38  }