View Javadoc

1   /* Generated By:JJTree: Do not edit this line. ASTFieldDeclaration.java */
2   
3   package net.sourceforge.pmd.ast;
4   
5   public class ASTFieldDeclaration extends SimpleJavaAccessTypeNode implements Dimensionable {
6   
7       public ASTFieldDeclaration(int id) {
8           super(id);
9       }
10  
11      public ASTFieldDeclaration(JavaParser p, int id) {
12          super(p, id);
13      }
14  
15      /**
16       * Accept the visitor. *
17       */
18      public Object jjtAccept(JavaParserVisitor visitor, Object data) {
19          return visitor.visit(this, data);
20      }
21  
22      public boolean isSyntacticallyPublic() {
23          return super.isPublic();
24      }
25  
26      public boolean isPublic() {
27          if (isInterfaceMember()) {
28              return true;
29          }
30          return super.isPublic();
31      }
32  
33      public boolean isSyntacticallyStatic() {
34          return super.isStatic();
35      }
36  
37      public boolean isStatic() {
38          if (isInterfaceMember()) {
39              return true;
40          }
41          return super.isStatic();
42      }
43  
44      public boolean isSyntacticallyFinal() {
45          return super.isFinal();
46      }
47  
48      public boolean isFinal() {
49          if (isInterfaceMember()) {
50              return true;
51          }
52          return super.isFinal();
53      }
54  
55      public boolean isPrivate() {
56          if (isInterfaceMember()) {
57              return false;
58          }
59          return super.isPrivate();
60      }
61  
62      public boolean isPackagePrivate() {
63          if (isInterfaceMember()) {
64              return false;
65          }
66          return super.isPackagePrivate();
67      }
68  
69      public boolean isProtected() {
70          if (isInterfaceMember()) {
71              return false;
72          }
73          return super.isProtected();
74      }
75  
76      public boolean isInterfaceMember() {
77          if (jjtGetParent().jjtGetParent() instanceof ASTEnumBody) {
78              return false;
79          }
80          ASTClassOrInterfaceDeclaration n = getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
81          return n != null && n.isInterface();
82      }
83  
84      public boolean isArray() {
85          return checkType() + checkDecl() > 0;
86      }
87  
88      public int getArrayDepth() {
89          if (!isArray()) {
90              return 0;
91          }
92          return checkType() + checkDecl();
93      }
94  
95      private int checkType() {
96          if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) {
97              return 0;
98          }
99          return ((ASTType) jjtGetChild(0)).getArrayDepth();
100     }
101 
102     private int checkDecl() {
103         if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
104             return 0;
105         }
106         return ((ASTVariableDeclaratorId) (jjtGetChild(1).jjtGetChild(0))).getArrayDepth();
107     }
108 
109     public void dump(String prefix) {
110         String out = collectDumpedModifiers(prefix);
111         if (isArray()) {
112             out += "(array";
113             for (int i = 0; i < getArrayDepth(); i++) {
114                 out += "[";
115             }
116             out += ")";
117         }
118         System.out.println(out);
119         dumpChildren(prefix);
120     }
121 
122     /**
123      * Gets the variable name of this field.
124      * This method searches the first VariableDeclartorId node and returns it's image or <code>null</code> if the child node is not found.
125      *
126      * @return a String representing the name of the variable
127      */
128     public String getVariableName() {
129         ASTVariableDeclaratorId decl = getFirstChildOfType(ASTVariableDeclaratorId.class);
130         if (decl != null) {
131             return decl.getImage();
132         }
133         return null;
134     }
135 }