KickJava   Java API By Example, From Geeks To Geeks.

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


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 "this" AST node type.
19  *
20  * <pre>
21  * ThisExpression:
22  * [ ClassName <b>.</b> ] <b>this</b>
23  * </pre>
24  * <p>
25  * See <code>FieldAccess</code> for guidelines on handling other expressions
26  * that resemble qualified names.
27  * </p>
28  *
29  * @see FieldAccess
30  * @since 2.0
31  */

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

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

41     /**
42      * A list of property descriptors (element type:
43      * {@link StructuralPropertyDescriptor}),
44      * or null if uninitialized.
45      */

46     private static final List JavaDoc PROPERTY_DESCRIPTORS;
47     
48     static {
49         List JavaDoc propertyList = new ArrayList JavaDoc(2);
50         createPropertyList(ThisExpression.class, propertyList);
51         addProperty(QUALIFIER_PROPERTY, propertyList);
52         PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
53     }
54
55     /**
56      * Returns a list of structural property descriptors for this node type.
57      * Clients must not modify the result.
58      *
59      * @param apiLevel the API level; one of the
60      * <code>AST.JLS*</code> constants
61      * @return a list of property descriptors (element type:
62      * {@link StructuralPropertyDescriptor})
63      * @since 3.0
64      */

65     public static List JavaDoc propertyDescriptors(int apiLevel) {
66         return PROPERTY_DESCRIPTORS;
67     }
68             
69     /**
70      * The optional qualifier; <code>null</code> for none; defaults to none.
71      */

72     private Name optionalQualifier = null;
73
74     /**
75      * Creates a new AST node for a "this" expression owned by the
76      * given AST. By default, there is no qualifier.
77      *
78      * @param ast the AST that is to own this node
79      */

80     ThisExpression(AST ast) {
81         super(ast);
82     }
83
84     /* (omit javadoc for this method)
85      * Method declared on ASTNode.
86      */

87     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
88         return propertyDescriptors(apiLevel);
89     }
90     
91     /* (omit javadoc for this method)
92      * Method declared on ASTNode.
93      */

94     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
95         if (property == QUALIFIER_PROPERTY) {
96             if (get) {
97                 return getQualifier();
98             } else {
99                 setQualifier((Name) child);
100                 return null;
101             }
102         }
103         // allow default implementation to flag the error
104
return super.internalGetSetChildProperty(property, get, child);
105     }
106     
107     /* (omit javadoc for this method)
108      * Method declared on ASTNode.
109      */

110     final int getNodeType0() {
111         return THIS_EXPRESSION;
112     }
113
114     /* (omit javadoc for this method)
115      * Method declared on ASTNode.
116      */

117     ASTNode clone0(AST target) {
118         ThisExpression result = new ThisExpression(target);
119         result.setSourceRange(this.getStartPosition(), this.getLength());
120         result.setQualifier((Name) ASTNode.copySubtree(target, getQualifier()));
121         return result;
122     }
123
124     /* (omit javadoc for this method)
125      * Method declared on ASTNode.
126      */

127     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
128         // dispatch to correct overloaded match method
129
return matcher.match(this, other);
130     }
131
132     /* (omit javadoc for this method)
133      * Method declared on ASTNode.
134      */

135     void accept0(ASTVisitor visitor) {
136         boolean visitChildren = visitor.visit(this);
137         if (visitChildren) {
138             acceptChild(visitor, getQualifier());
139         }
140         visitor.endVisit(this);
141     }
142     
143     /**
144      * Returns the qualifier of this "this" expression, or
145      * <code>null</code> if there is none.
146      *
147      * @return the qualifier name node, or <code>null</code> if there is none
148      */

149     public Name getQualifier() {
150         return this.optionalQualifier;
151     }
152     
153     /**
154      * Sets or clears the qualifier of this "this" expression.
155      *
156      * @param name the qualifier name node, or <code>null</code> if
157      * there is none
158      * @exception IllegalArgumentException if:
159      * <ul>
160      * <li>the node belongs to a different AST</li>
161      * <li>the node already has a parent</li>
162      * </ul>
163      */

164     public void setQualifier(Name name) {
165         ASTNode oldChild = this.optionalQualifier;
166         preReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
167         this.optionalQualifier = name;
168         postReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
169     }
170
171     /* (omit javadoc for this method)
172      * Method declared on ASTNode.
173      */

174     int memSize() {
175         // treat Operator as free
176
return BASE_NODE_SIZE + 1 * 4;
177     }
178     
179     /* (omit javadoc for this method)
180      * Method declared on ASTNode.
181      */

182     int treeSize() {
183         return
184             memSize()
185             + (this.optionalQualifier == null ? 0 : getQualifier().treeSize());
186     }
187 }
188
Popular Tags