View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   /* Generated By:JJTree: Do not edit this line. ASTFormalParameter.java */
5   
6   package net.sourceforge.pmd.lang.java.ast;
7   
8   import net.sourceforge.pmd.Rule;
9   
10  public class ASTFormalParameter extends AbstractJavaAccessNode implements Dimensionable, CanSuppressWarnings {
11  
12      private boolean isVarargs;
13  
14  
15      public void setVarargs() {
16          isVarargs = true;
17      }
18  
19      public boolean isVarargs() {
20          return isVarargs;
21      }
22  
23      public boolean isExplicitReceiverParameter() {
24          return getDecl().isExplicitReceiverParameter();
25      }
26  
27      public ASTFormalParameter(int id) {
28          super(id);
29      }
30  
31      public ASTFormalParameter(JavaParser p, int id) {
32          super(p, id);
33      }
34  
35      public Object jjtAccept(JavaParserVisitor visitor, Object data) {
36          return visitor.visit(this, data);
37      }
38  
39      public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
40          for (int i = 0; i < jjtGetNumChildren(); i++) {
41              if (jjtGetChild(i) instanceof ASTAnnotation) {
42                  ASTAnnotation a = (ASTAnnotation) jjtGetChild(i);
43                  if (a.suppresses(rule)) {
44                      return true;
45                  }
46              }
47          }
48          return false;
49      }
50  
51      public boolean isArray() {
52          return checkType() + checkDecl() > 0;
53      }
54  
55      public int getArrayDepth() {
56          if (!isArray()) {
57              return 0;
58          }
59          return checkType() + checkDecl();
60      }
61  
62      public ASTType getTypeNode() {
63          for (int i = 0; i < jjtGetNumChildren(); i++) {
64              if (jjtGetChild(i) instanceof ASTType) {
65                  return (ASTType) jjtGetChild(i);
66              }
67          }
68          throw new IllegalStateException("ASTType not found");
69      }
70  
71      private int checkType() {
72          return getTypeNode().getArrayDepth();
73      }
74  
75      protected ASTVariableDeclaratorId getDecl() {
76          try {
77              return (ASTVariableDeclaratorId) jjtGetChild(jjtGetNumChildren()-1);
78          } catch (ClassCastException c) {
79              System.out.println("CLASS CAST: " + this.getBeginLine() + ":" + this.getBeginColumn() + " " + this.toString());
80              return null;
81          }
82      }
83  
84      private int checkDecl() {
85          return getDecl().getArrayDepth();
86      }
87  
88  }