1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
14 import java.util.ArrayList;
15 import java.util.List;
18 * Simple or qualified "this" AST node type.
22 * [ ClassName <b>.</b> ] <b>this</b>
25 * See <code>FieldAccess</code> for guidelines on handling other expressions
26 * that resemble qualified names.
31 * @noinstantiate This class is not intended to be instantiated by clients.
33 public class ThisExpression extends Expression {
36 * The "qualifier" structural property of this node type.
39 public static final ChildPropertyDescriptor QUALIFIER_PROPERTY =
40 new ChildPropertyDescriptor(ThisExpression.class, "qualifier", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
43 * A list of property descriptors (element type:
44 * {@link StructuralPropertyDescriptor}),
45 * or null if uninitialized.
47 private static final List PROPERTY_DESCRIPTORS;
50 List propertyList = new ArrayList(2);
51 createPropertyList(ThisExpression.class, propertyList);
52 addProperty(QUALIFIER_PROPERTY, propertyList);
53 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
57 * Returns a list of structural property descriptors for this node type.
58 * Clients must not modify the result.
60 * @param apiLevel the API level; one of the
61 * <code>AST.JLS*</code> constants
62 * @return a list of property descriptors (element type:
63 * {@link StructuralPropertyDescriptor})
66 public static List propertyDescriptors(int apiLevel) {
67 return PROPERTY_DESCRIPTORS;
71 * The optional qualifier; <code>null</code> for none; defaults to none.
73 private Name optionalQualifier = null;
76 * Creates a new AST node for a "this" expression owned by the
77 * given AST. By default, there is no qualifier.
79 * @param ast the AST that is to own this node
81 ThisExpression(AST ast) {
85 /* (omit javadoc for this method)
86 * Method declared on ASTNode.
88 final List internalStructuralPropertiesForType(int apiLevel) {
89 return propertyDescriptors(apiLevel);
92 /* (omit javadoc for this method)
93 * Method declared on ASTNode.
95 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
96 if (property == QUALIFIER_PROPERTY) {
98 return getQualifier();
100 setQualifier((Name) child);
104 // allow default implementation to flag the error
105 return super.internalGetSetChildProperty(property, get, child);
108 /* (omit javadoc for this method)
109 * Method declared on ASTNode.
111 final int getNodeType0() {
112 return THIS_EXPRESSION;
115 /* (omit javadoc for this method)
116 * Method declared on ASTNode.
118 ASTNode clone0(AST target) {
119 ThisExpression result = new ThisExpression(target);
120 result.setSourceRange(this.getStartPosition(), this.getLength());
121 result.setQualifier((Name) ASTNode.copySubtree(target, getQualifier()));
125 /* (omit javadoc for this method)
126 * Method declared on ASTNode.
128 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
129 // dispatch to correct overloaded match method
130 return matcher.match(this, other);
133 /* (omit javadoc for this method)
134 * Method declared on ASTNode.
136 void accept0(ASTVisitor visitor) {
137 boolean visitChildren = visitor.visit(this);
139 acceptChild(visitor, getQualifier());
141 visitor.endVisit(this);
145 * Returns the qualifier of this "this" expression, or
146 * <code>null</code> if there is none.
148 * @return the qualifier name node, or <code>null</code> if there is none
150 public Name getQualifier() {
151 return this.optionalQualifier;
155 * Sets or clears the qualifier of this "this" expression.
157 * @param name the qualifier name node, or <code>null</code> if
159 * @exception IllegalArgumentException if:
161 * <li>the node belongs to a different AST</li>
162 * <li>the node already has a parent</li>
165 public void setQualifier(Name name) {
166 ASTNode oldChild = this.optionalQualifier;
167 preReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
168 this.optionalQualifier = name;
169 postReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
172 /* (omit javadoc for this method)
173 * Method declared on ASTNode.
176 // treat Operator as free
177 return BASE_NODE_SIZE + 1 * 4;
180 /* (omit javadoc for this method)
181 * Method declared on ASTNode.
186 + (this.optionalQualifier == null ? 0 : getQualifier().treeSize());