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