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 junit.framework.TestCase; 7 import net.sourceforge.pmd.PMD; 8 import net.sourceforge.pmd.TargetJDK1_4; 9 import net.sourceforge.pmd.ast.ASTCompilationUnit; 10 import net.sourceforge.pmd.ast.ASTType; 11 import net.sourceforge.pmd.ast.JavaParser; 12 13 import java.io.StringReader; 14 15 public class ASTTypeTest extends TestCase{ 16 17 public void testIsArray() { 18 JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST1)); 19 ASTCompilationUnit cu = parser.CompilationUnit(); 20 ASTType node = (ASTType)cu.findChildrenOfType(ASTType.class).get(0); 21 assertTrue(node.isArray()); 22 } 23 24 public void testOneDimensionArray() { 25 JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST2)); 26 ASTCompilationUnit cu = parser.CompilationUnit(); 27 ASTType node = (ASTType)cu.findChildrenOfType(ASTType.class).get(0); 28 assertEquals(1, node.getDimensions()); 29 } 30 31 public void testMultiDimensionalArray() { 32 JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST3)); 33 ASTCompilationUnit cu = parser.CompilationUnit(); 34 ASTType node = (ASTType)cu.findChildrenOfType(ASTType.class).get(0); 35 assertEquals(3, node.getDimensions()); 36 } 37 38 private static final String TEST1 = 39 "class Foo {" + PMD.EOL + 40 " String[] foo() {}" + PMD.EOL + 41 "}"; 42 43 private static final String TEST2 = 44 "class Foo {" + PMD.EOL + 45 " String[] foo() {}" + PMD.EOL + 46 "}"; 47 48 private static final String TEST3 = 49 "class Foo {" + PMD.EOL + 50 " String[][][] foo() {}" + PMD.EOL + 51 "}"; 52 53 }