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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
15 * Abstract base class of all AST node types that declare a single local
19 * VariableDeclaration:
20 * SingleVariableDeclaration
21 * VariableDeclarationFragment
25 * @see SingleVariableDeclaration
26 * @see VariableDeclarationFragment
29 public abstract class VariableDeclaration extends ASTNode {
32 * Returns structural property descriptor for the "extraDimensions" property
35 * @return the property descriptor
38 abstract SimplePropertyDescriptor internalExtraDimensionsProperty();
41 * Returns structural property descriptor for the "extraDimensions" property
44 * @return the property descriptor
47 public final SimplePropertyDescriptor getExtraDimensionsProperty() {
48 return internalExtraDimensionsProperty();
52 * Returns structural property descriptor for the "initializer" property
55 * @return the property descriptor
58 abstract ChildPropertyDescriptor internalInitializerProperty();
61 * Returns structural property descriptor for the "initializer" property
64 * @return the property descriptor
67 public final ChildPropertyDescriptor getInitializerProperty() {
68 return internalInitializerProperty();
72 * Returns structural property descriptor for the "name" property
75 * @return the property descriptor
78 abstract ChildPropertyDescriptor internalNameProperty();
81 * Returns structural property descriptor for the "name" property
84 * @return the property descriptor
87 public final ChildPropertyDescriptor getNameProperty() {
88 return internalNameProperty();
92 * Creates a new AST node for a variable declaration owned by the given AST.
94 * N.B. This constructor is package-private.
97 * @param ast the AST that is to own this node
99 VariableDeclaration(AST ast) {
104 * Returns the name of the variable declared in this variable declaration.
106 * @return the variable name node
108 public abstract SimpleName getName();
111 * Sets the name of the variable declared in this variable declaration
114 * @param variableName the new variable name
115 * @exception IllegalArgumentException if:
117 * <li>the node belongs to a different AST</li>
118 * <li>the node already has a parent</li>
121 public abstract void setName(SimpleName variableName);
124 * Returns the number of extra array dimensions over and above the
125 * explicitly-specified type.
127 * For example, <code>int x[][]</code> has a type of
128 * <code>int</code> and two extra array dimensions;
129 * <code>int[][] x</code> has a type of <code>int[][]</code>
130 * and zero extra array dimensions. The two constructs have different
131 * ASTs, even though there are really syntactic variants of the same
132 * variable declaration.
135 * @return the number of extra array dimensions
138 public abstract int getExtraDimensions();
141 * Sets the number of extra array dimensions over and above the
142 * explicitly-specified type.
144 * For example, <code>int x[][]</code> has a type of
145 * <code>int</code> and two extra array dimensions;
146 * <code>int[][] x</code> has a type of <code>int[][]</code>
147 * and zero extra array dimensions. The two constructs have different
148 * ASTs, even though there are really syntactic variants of the same
149 * variable declaration.
152 * @param dimensions the number of array dimensions
153 * @exception IllegalArgumentException if the number of dimensions is
157 public abstract void setExtraDimensions(int dimensions);
160 * Returns the initializer of this variable declaration, or
161 * <code>null</code> if there is none.
163 * @return the initializer expression node, or <code>null</code> if
166 public abstract Expression getInitializer();
169 * Sets or clears the initializer of this variable declaration.
171 * @param initializer the initializer expression node, or <code>null</code>
173 * @exception IllegalArgumentException if:
175 * <li>the node belongs to a different AST</li>
176 * <li>the node already has a parent</li>
177 * <li>a cycle in would be created</li>
180 public abstract void setInitializer(Expression initializer);
183 * Resolves and returns the binding for the variable declared in this
184 * variable declaration.
186 * Note that bindings are generally unavailable unless requested when the
187 * AST is being built.
190 * @return the binding, or <code>null</code> if the binding cannot be
193 public IVariableBinding resolveBinding() {
194 return this.ast.getBindingResolver().resolveVariable(this);