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 AccessNode 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          ASTClassOrInterfaceDeclaration n = (ASTClassOrInterfaceDeclaration)getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
    78          return n instanceof ASTClassOrInterfaceDeclaration && n.isInterface();
    79      }
    80
    81      public boolean isArray() {
    82          return checkType() + checkDecl() > 0;
    83      }
    84
    85      public int getArrayDepth() {
    86          if (!isArray()) {
    87              return 0;
    88          }
    89          return checkType() + checkDecl();
    90      }
    91
    92      private int checkType() {
    93          if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) {
    94              return 0;
    95          }
    96          return ((ASTType) jjtGetChild(0)).getArrayDepth();
    97      }
    98
    99      private int checkDecl() {
    100         if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
    101             return 0;
    102         }
    103         return ((ASTVariableDeclaratorId) (jjtGetChild(1).jjtGetChild(0))).getArrayDepth();
    104     }
    105
    106     public void dump(String prefix) {
    107         String out = collectDumpedModifiers(prefix);
    108         if (isArray()) {
    109             out += "(array";
    110             for (int i = 0; i < getArrayDepth(); i++) {
    111                 out += "[";
    112             }
    113             out += ")";
    114         }
    115         System.out.println(out);
    116         dumpChildren(prefix);
    117     }
    118
    119     /***
    120      * Gets the variable name of this field.
    121      * This method searches the first VariableDeclartorId node and returns it's 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 = (ASTVariableDeclaratorId) getFirstChildOfType(ASTVariableDeclaratorId.class);
    127         if (decl != null) {
    128             return decl.getImage();
    129         }
    130         return null;
    131     }
    132 }