001: /* Generated By:JJTree: Do not edit this line. ASTFieldDeclaration.java */
002:
003: package net.sourceforge.pmd.ast;
004:
005: public class ASTFieldDeclaration extends AccessNode implements
006: Dimensionable {
007:
008: public ASTFieldDeclaration(int id) {
009: super (id);
010: }
011:
012: public ASTFieldDeclaration(JavaParser p, int id) {
013: super (p, id);
014: }
015:
016: /**
017: * Accept the visitor. *
018: */
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: public boolean isPublic() {
028: if (isInterfaceMember()) {
029: return true;
030: }
031: return super .isPublic();
032: }
033:
034: public boolean isSyntacticallyStatic() {
035: return super .isStatic();
036: }
037:
038: public boolean isStatic() {
039: if (isInterfaceMember()) {
040: return true;
041: }
042: return super .isStatic();
043: }
044:
045: public boolean isSyntacticallyFinal() {
046: return super .isFinal();
047: }
048:
049: public boolean isFinal() {
050: if (isInterfaceMember()) {
051: return true;
052: }
053: return super .isFinal();
054: }
055:
056: public boolean isPrivate() {
057: if (isInterfaceMember()) {
058: return false;
059: }
060: return super .isPrivate();
061: }
062:
063: public boolean isPackagePrivate() {
064: if (isInterfaceMember()) {
065: return false;
066: }
067: return super .isPackagePrivate();
068: }
069:
070: public boolean isProtected() {
071: if (isInterfaceMember()) {
072: return false;
073: }
074: return super .isProtected();
075: }
076:
077: public boolean isInterfaceMember() {
078: ASTClassOrInterfaceDeclaration n = (ASTClassOrInterfaceDeclaration) getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
079: return n instanceof ASTClassOrInterfaceDeclaration
080: && n.isInterface();
081: }
082:
083: public boolean isArray() {
084: return checkType() + checkDecl() > 0;
085: }
086:
087: public int getArrayDepth() {
088: if (!isArray()) {
089: return 0;
090: }
091: return checkType() + checkDecl();
092: }
093:
094: private int checkType() {
095: if (jjtGetNumChildren() == 0
096: || !(jjtGetChild(0) instanceof ASTType)) {
097: return 0;
098: }
099: return ((ASTType) jjtGetChild(0)).getArrayDepth();
100: }
101:
102: private int checkDecl() {
103: if (jjtGetNumChildren() < 2
104: || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
105: return 0;
106: }
107: return ((ASTVariableDeclaratorId) (jjtGetChild(1)
108: .jjtGetChild(0))).getArrayDepth();
109: }
110:
111: public void dump(String prefix) {
112: String out = collectDumpedModifiers(prefix);
113: if (isArray()) {
114: out += "(array";
115: for (int i = 0; i < getArrayDepth(); i++) {
116: out += "[";
117: }
118: out += ")";
119: }
120: System.out.println(out);
121: dumpChildren(prefix);
122: }
123:
124: /**
125: * Gets the variable name of this field.
126: * This method searches the first VariableDeclartorId node and returns it's image or <code>null</code> if the child node is not found.
127: *
128: * @return a String representing the name of the variable
129: */
130: public String getVariableName() {
131: ASTVariableDeclaratorId decl = (ASTVariableDeclaratorId) getFirstChildOfType(ASTVariableDeclaratorId.class);
132: if (decl != null) {
133: return decl.getImage();
134: }
135: return null;
136: }
137: }
|