ASTFieldDeclaration.java
001 /* Generated By:JJTree: Do not edit this line. ASTFieldDeclaration.java */
002 
003 package net.sourceforge.pmd.lang.java.ast;
004 
005 public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements Dimensionable {
006 
007     public ASTFieldDeclaration(int id) {
008         super(id);
009     }
010 
011     public ASTFieldDeclaration(JavaParser p, int id) {
012         super(p, id);
013     }
014 
015     /**
016      * Accept the visitor. *
017      */
018     @Override
019     public Object jjtAccept(JavaParserVisitor visitor, Object data) {
020         return visitor.visit(this, data);
021     }
022 
023     public boolean isSyntacticallyPublic() {
024         return super.isPublic();
025     }
026 
027     @Override
028     public boolean isPublic() {
029         if (isInterfaceMember()) {
030             return true;
031         }
032         return super.isPublic();
033     }
034 
035     public boolean isSyntacticallyStatic() {
036         return super.isStatic();
037     }
038 
039     @Override
040     public boolean isStatic() {
041         if (isInterfaceMember()) {
042             return true;
043         }
044         return super.isStatic();
045     }
046 
047     public boolean isSyntacticallyFinal() {
048         return super.isFinal();
049     }
050 
051     @Override
052     public boolean isFinal() {
053         if (isInterfaceMember()) {
054             return true;
055         }
056         return super.isFinal();
057     }
058 
059     @Override
060     public boolean isPrivate() {
061         if (isInterfaceMember()) {
062             return false;
063         }
064         return super.isPrivate();
065     }
066 
067     @Override
068     public boolean isPackagePrivate() {
069         if (isInterfaceMember()) {
070             return false;
071         }
072         return super.isPackagePrivate();
073     }
074 
075     @Override
076     public boolean isProtected() {
077         if (isInterfaceMember()) {
078             return false;
079         }
080         return super.isProtected();
081     }
082 
083     public boolean isInterfaceMember() {
084         if (jjtGetParent().jjtGetParent() instanceof ASTEnumBody) {
085             return false;
086         }
087         ASTClassOrInterfaceDeclaration n = getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
088         return n != null && n.isInterface();
089     }
090 
091     public boolean isArray() {
092         return checkType() + checkDecl() 0;
093     }
094 
095     public int getArrayDepth() {
096         if (!isArray()) {
097             return 0;
098         }
099         return checkType() + checkDecl();
100     }
101 
102     private int checkType() {
103         if (jjtGetNumChildren() == || !(jjtGetChild(0instanceof ASTType)) {
104             return 0;
105         }
106         return ((ASTTypejjtGetChild(0)).getArrayDepth();
107     }
108 
109     private int checkDecl() {
110         if (jjtGetNumChildren() || !(jjtGetChild(1instanceof ASTVariableDeclarator)) {
111             return 0;
112         }
113         return ((ASTVariableDeclaratorIdjjtGetChild(1).jjtGetChild(0)).getArrayDepth();
114     }
115 
116     /**
117      * Gets the variable name of this field.
118      * This method searches the first VariableDeclartorId node and returns its image or <code>null</code> if the child node is not found.
119      *
120      @return a String representing the name of the variable
121      */
122     public String getVariableName() {
123         ASTVariableDeclaratorId decl = getFirstDescendantOfType(ASTVariableDeclaratorId.class);
124         if (decl != null) {
125             return decl.getImage();
126         }
127         return null;
128     }
129 }