001: /* Generated By:JJTree: Do not edit this line. ASTFieldDeclaration.java */
002:
003: package net.sourceforge.pmd.ast;
004:
005: public class ASTFieldDeclaration extends SimpleJavaAccessTypeNode
006: implements 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: if (jjtGetParent().jjtGetParent() instanceof ASTEnumBody) {
079: return false;
080: }
081: ASTClassOrInterfaceDeclaration n = getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
082: return n != null && n.isInterface();
083: }
084:
085: public boolean isArray() {
086: return checkType() + checkDecl() > 0;
087: }
088:
089: public int getArrayDepth() {
090: if (!isArray()) {
091: return 0;
092: }
093: return checkType() + checkDecl();
094: }
095:
096: private int checkType() {
097: if (jjtGetNumChildren() == 0
098: || !(jjtGetChild(0) instanceof ASTType)) {
099: return 0;
100: }
101: return ((ASTType) jjtGetChild(0)).getArrayDepth();
102: }
103:
104: private int checkDecl() {
105: if (jjtGetNumChildren() < 2
106: || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
107: return 0;
108: }
109: return ((ASTVariableDeclaratorId) (jjtGetChild(1)
110: .jjtGetChild(0))).getArrayDepth();
111: }
112:
113: public void dump(String prefix) {
114: String out = collectDumpedModifiers(prefix);
115: if (isArray()) {
116: out += "(array";
117: for (int i = 0; i < getArrayDepth(); i++) {
118: out += "[";
119: }
120: out += ")";
121: }
122: System.out.println(out);
123: dumpChildren(prefix);
124: }
125:
126: /**
127: * Gets the variable name of this field.
128: * This method searches the first VariableDeclartorId node and returns it's image or <code>null</code> if the child node is not found.
129: *
130: * @return a String representing the name of the variable
131: */
132: public String getVariableName() {
133: ASTVariableDeclaratorId decl = getFirstChildOfType(ASTVariableDeclaratorId.class);
134: if (decl != null) {
135: return decl.getImage();
136: }
137: return null;
138: }
139: }
|