    1   package test.net.sourceforge.pmd.ast;
    2
    3   import net.sourceforge.pmd.PMD;
    4   import net.sourceforge.pmd.TargetJDK1_4;
    5   import net.sourceforge.pmd.ast.ASTCompilationUnit;
    6   import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration;
    7   import net.sourceforge.pmd.ast.JavaParser;
    8   import test.net.sourceforge.pmd.testframework.ParserTst;
    9
    10  import java.io.StringReader;
    11
    12  public class ASTLocalVariableDeclarationTest extends ParserTst {
    13
    14      public void testSingleDimArray() {
    15          JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST1));
    16          ASTCompilationUnit cu = parser.CompilationUnit();
    17          ASTLocalVariableDeclaration node = (ASTLocalVariableDeclaration) cu.findChildrenOfType(ASTLocalVariableDeclaration.class).get(0);
    18          assertEquals(1, node.getArrayDepth());
    19      }
    20
    21      public void testMultDimArray() {
    22          JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST2));
    23          ASTCompilationUnit cu = parser.CompilationUnit();
    24          ASTLocalVariableDeclaration node = (ASTLocalVariableDeclaration) cu.findChildrenOfType(ASTLocalVariableDeclaration.class).get(0);
    25          assertEquals(2, node.getArrayDepth());
    26      }
    27
    28      public void testMultDimArraySplitBraces() {
    29          JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST3));
    30          ASTCompilationUnit cu = parser.CompilationUnit();
    31          ASTLocalVariableDeclaration node = (ASTLocalVariableDeclaration) cu.findChildrenOfType(ASTLocalVariableDeclaration.class).get(0);
    32          assertEquals(3, node.getArrayDepth());
    33      }
    34
    35      private static final String TEST1 =
    36              "class Foo {" + PMD.EOL +
    37              " void bar() {int x[] = null;}" + PMD.EOL +
    38              "}";
    39
    40      private static final String TEST2 =
    41              "class Foo {" + PMD.EOL +
    42              " void bar() {int x[][] = null;}" + PMD.EOL +
    43              "}";
    44
    45      private static final String TEST3 =
    46              "class Foo {" + PMD.EOL +
    47              " void bar() {int[] x[][] = null;}" + PMD.EOL +
    48              "}";
    49
    50  }