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

This page was automatically generated by Maven