1
2
3 package net.sourceforge.pmd.lang.java.ast;
4
5 public class ASTType extends AbstractJavaTypeNode {
6 public ASTType(int id) {
7 super(id);
8 }
9
10 public ASTType(JavaParser p, int id) {
11 super(p, id);
12 }
13
14
15
16
17 @Override
18 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
19 return visitor.visit(this, data);
20 }
21
22 public String getTypeImage() {
23 ASTPrimitiveType prim = getFirstDescendantOfType(ASTPrimitiveType.class);
24 if (prim != null) {
25 return prim.getImage();
26 }
27 return getFirstDescendantOfType(ASTClassOrInterfaceType.class).getImage();
28 }
29
30 public int getArrayDepth() {
31 if (jjtGetNumChildren() != 0 && (jjtGetChild(0) instanceof ASTReferenceType || jjtGetChild(0) instanceof ASTPrimitiveType)) {
32 return ((Dimensionable) jjtGetChild(0)).getArrayDepth();
33 }
34 throw new RuntimeException("ASTType.getArrayDepth called, but first child (of " + jjtGetNumChildren() + " total children) is neither a primitive nor a reference type.");
35 }
36
37 public boolean isArray() {
38 return getArrayDepth() > 0;
39 }
40
41
42 }