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