View Javadoc

    1   /* Generated By:JJTree: Do not edit this line. ASTFieldDeclaration.java */
    2
    3   package net.sourceforge.pmd.lang.java.ast;
    4
    5   public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode 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      @Override
    19      public Object jjtAccept(JavaParserVisitor visitor, Object data) {
    20          return visitor.visit(this, data);
    21      }
    22
    23      public boolean isSyntacticallyPublic() {
    24          return super.isPublic();
    25      }
    26
    27      @Override
    28      public boolean isPublic() {
    29          if (isInterfaceMember()) {
    30              return true;
    31          }
    32          return super.isPublic();
    33      }
    34
    35      public boolean isSyntacticallyStatic() {
    36          return super.isStatic();
    37      }
    38
    39      @Override
    40      public boolean isStatic() {
    41          if (isInterfaceMember()) {
    42              return true;
    43          }
    44          return super.isStatic();
    45      }
    46
    47      public boolean isSyntacticallyFinal() {
    48          return super.isFinal();
    49      }
    50
    51      @Override
    52      public boolean isFinal() {
    53          if (isInterfaceMember()) {
    54              return true;
    55          }
    56          return super.isFinal();
    57      }
    58
    59      @Override
    60      public boolean isPrivate() {
    61          if (isInterfaceMember()) {
    62              return false;
    63          }
    64          return super.isPrivate();
    65      }
    66
    67      @Override
    68      public boolean isPackagePrivate() {
    69          if (isInterfaceMember()) {
    70              return false;
    71          }
    72          return super.isPackagePrivate();
    73      }
    74
    75      @Override
    76      public boolean isProtected() {
    77          if (isInterfaceMember()) {
    78              return false;
    79          }
    80          return super.isProtected();
    81      }
    82
    83      public boolean isInterfaceMember() {
    84          if (jjtGetParent().jjtGetParent() instanceof ASTEnumBody) {
    85              return false;
    86          }
    87          ASTClassOrInterfaceDeclaration n = getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
    88          return n != null && n.isInterface();
    89      }
    90
    91      public boolean isArray() {
    92          return checkType() + checkDecl() > 0;
    93      }
    94
    95      public int getArrayDepth() {
    96          if (!isArray()) {
    97              return 0;
    98          }
    99          return checkType() + checkDecl();
    100     }
    101
    102     private int checkType() {
    103         if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) {
    104             return 0;
    105         }
    106         return ((ASTType) jjtGetChild(0)).getArrayDepth();
    107     }
    108
    109     private int checkDecl() {
    110         if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
    111             return 0;
    112         }
    113         return ((ASTVariableDeclaratorId) jjtGetChild(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 }