KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > SuperFieldAccess


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Simple or qualified "super" field access expression AST node type.
19  *
20  * <pre>
21  * SuperFieldAccess:
22  * [ ClassName <b>.</b> ] <b>super</b> <b>.</b> Identifier
23  * </pre>
24  *
25  * <p>
26  * See <code>FieldAccess</code> for guidelines on handling other expressions
27  * that resemble qualified names.
28  * </p>
29  *
30  * @see FieldAccess
31  * @since 2.0
32  */

33 public class SuperFieldAccess extends Expression {
34
35     /**
36      * The "qualifier" structural property of this node type.
37      * @since 3.0
38      */

39     public static final ChildPropertyDescriptor QUALIFIER_PROPERTY =
40         new ChildPropertyDescriptor(SuperFieldAccess.class, "qualifier", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
41

42     /**
43      * The "name" structural property of this node type.
44      * @since 3.0
45      */

46     public static final ChildPropertyDescriptor NAME_PROPERTY =
47         new ChildPropertyDescriptor(SuperFieldAccess.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
48

49     /**
50      * A list of property descriptors (element type:
51      * {@link StructuralPropertyDescriptor}),
52      * or null if uninitialized.
53      */

54     private static final List JavaDoc PROPERTY_DESCRIPTORS;
55     
56     static {
57         List JavaDoc propertyList = new ArrayList JavaDoc(3);
58         createPropertyList(SuperFieldAccess.class, propertyList);
59         addProperty(QUALIFIER_PROPERTY, propertyList);
60         addProperty(NAME_PROPERTY, propertyList);
61         PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
62     }
63
64     /**
65      * Returns a list of structural property descriptors for this node type.
66      * Clients must not modify the result.
67      *
68      * @param apiLevel the API level; one of the
69      * <code>AST.JLS*</code> constants
70      * @return a list of property descriptors (element type:
71      * {@link StructuralPropertyDescriptor})
72      * @since 3.0
73      */

74     public static List JavaDoc propertyDescriptors(int apiLevel) {
75         return PROPERTY_DESCRIPTORS;
76     }
77             
78     /**
79      * The optional qualifier; <code>null</code> for none; defaults to none.
80      */

81     private Name optionalQualifier = null;
82
83     /**
84      * The field; lazily initialized; defaults to an unspecified,
85      * but legal, simple field name.
86      */

87     private SimpleName fieldName = null;
88
89     /**
90      * Creates a new unparented node for a super field access expression owned
91      * by the given AST. By default, field name is an unspecified, but legal,
92      * name, and there is no qualifier.
93      * <p>
94      * N.B. This constructor is package-private.
95      * </p>
96      *
97      * @param ast the AST that is to own this node
98      */

99     SuperFieldAccess(AST ast) {
100         super(ast);
101     }
102
103     /* (omit javadoc for this method)
104      * Method declared on ASTNode.
105      */

106     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
107         return propertyDescriptors(apiLevel);
108     }
109     
110     /* (omit javadoc for this method)
111      * Method declared on ASTNode.
112      */

113     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
114         if (property == QUALIFIER_PROPERTY) {
115             if (get) {
116                 return getQualifier();
117             } else {
118                 setQualifier((Name) child);
119                 return null;
120             }
121         }
122         if (property == NAME_PROPERTY) {
123             if (get) {
124                 return getName();
125             } else {
126                 setName((SimpleName) child);
127                 return null;
128             }
129         }
130         // allow default implementation to flag the error
131
return super.internalGetSetChildProperty(property, get, child);
132     }
133     
134     /* (omit javadoc for this method)
135      * Method declared on ASTNode.
136      */

137     final int getNodeType0() {
138         return SUPER_FIELD_ACCESS;
139     }
140
141     /* (omit javadoc for this method)
142      * Method declared on ASTNode.
143      */

144     ASTNode clone0(AST target) {
145         SuperFieldAccess result = new SuperFieldAccess(target);
146         result.setSourceRange(this.getStartPosition(), this.getLength());
147         result.setName((SimpleName) ASTNode.copySubtree(target, getName()));
148         result.setQualifier((Name) ASTNode.copySubtree(target, getQualifier()));
149         return result;
150     }
151
152     /* (omit javadoc for this method)
153      * Method declared on ASTNode.
154      */

155     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
156         // dispatch to correct overloaded match method
157
return matcher.match(this, other);
158     }
159
160     /* (omit javadoc for this method)
161      * Method declared on ASTNode.
162      */

163     void accept0(ASTVisitor visitor) {
164         boolean visitChildren = visitor.visit(this);
165         if (visitChildren) {
166             // visit children in normal left to right reading order
167
acceptChild(visitor, getQualifier());
168             acceptChild(visitor, getName());
169         }
170         visitor.endVisit(this);
171     }
172     
173     /**
174      * Returns the qualifier of this "super" field access expression, or
175      * <code>null</code> if there is none.
176      *
177      * @return the qualifier name node, or <code>null</code> if there is none
178      */

179     public Name getQualifier() {
180         return this.optionalQualifier;
181     }
182     
183     /**
184      * Sets or clears the qualifier of this "super" field access expression.
185      *
186      * @param name the qualifier name node, or <code>null</code> if
187      * there is none
188      * @exception IllegalArgumentException if:
189      * <ul>
190      * <li>the node belongs to a different AST</li>
191      * <li>the node already has a parent</li>
192      * </ul>
193      */

194     public void setQualifier(Name name) {
195         ASTNode oldChild = this.optionalQualifier;
196         preReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
197         this.optionalQualifier = name;
198         postReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
199     }
200
201     /**
202      * Returns the name of the field accessed in this "super" field access
203      * expression.
204      *
205      * @return the field name
206      */

207     public SimpleName getName() {
208         if (this.fieldName == null) {
209             // lazy init must be thread-safe for readers
210
synchronized (this) {
211                 if (this.fieldName == null) {
212                     preLazyInit();
213                     this.fieldName = new SimpleName(this.ast);
214                     postLazyInit(this.fieldName, NAME_PROPERTY);
215                 }
216             }
217         }
218         return this.fieldName;
219     }
220
221     /**
222      * Resolves and returns the binding for the field accessed by this
223      * expression.
224      * <p>
225      * Note that bindings are generally unavailable unless requested when the
226      * AST is being built.
227      * </p>
228      *
229      * @return the variable binding, or <code>null</code> if the binding cannot
230      * be resolved
231      * @since 3.0
232      */

233     public IVariableBinding resolveFieldBinding() {
234         return this.ast.getBindingResolver().resolveField(this);
235     }
236         
237     /**
238      * Sets the name of the field accessed in this "super" field access
239      * expression.
240      *
241      * @param fieldName the field name
242      * @exception IllegalArgumentException if:
243      * <ul>
244      * <li>the node belongs to a different AST</li>
245      * <li>the node already has a parent</li>
246      * </ul>
247      */

248     public void setName(SimpleName fieldName) {
249         if (fieldName == null) {
250             throw new IllegalArgumentException JavaDoc();
251         }
252         ASTNode oldChild = this.fieldName;
253         preReplaceChild(oldChild, fieldName, NAME_PROPERTY);
254         this.fieldName = fieldName;
255         postReplaceChild(oldChild, fieldName, NAME_PROPERTY);
256     }
257
258     /* (omit javadoc for this method)
259      * Method declared on ASTNode.
260      */

261     int memSize() {
262         // treat Code as free
263
return BASE_NODE_SIZE + 2 * 4;
264     }
265     
266     /* (omit javadoc for this method)
267      * Method declared on ASTNode.
268      */

269     int treeSize() {
270         return
271             memSize()
272             + (this.optionalQualifier == null ? 0 : getQualifier().treeSize())
273             + (this.fieldName == null ? 0 : getName().treeSize());
274     }
275 }
276
277
Popular Tags