KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 /**
15  * Abstract base class of all AST node types that declare a single local
16  * variable.
17  * <p>
18  * <pre>
19  * VariableDeclaration:
20  * SingleVariableDeclaration
21  * VariableDeclarationFragment
22  * </pre>
23  * </p>
24  *
25  * @see SingleVariableDeclaration
26  * @see VariableDeclarationFragment
27  * @since 2.0
28  */

29 public abstract class VariableDeclaration extends ASTNode {
30     
31     /**
32      * Returns structural property descriptor for the "extraDimensions" property
33      * of this node.
34      *
35      * @return the property descriptor
36      * @since 3.1
37      */

38     abstract SimplePropertyDescriptor internalExtraDimensionsProperty();
39
40     /**
41      * Returns structural property descriptor for the "extraDimensions" property
42      * of this node.
43      *
44      * @return the property descriptor
45      * @since 3.1
46      */

47     public final SimplePropertyDescriptor getExtraDimensionsProperty() {
48         return internalExtraDimensionsProperty();
49     }
50
51     /**
52      * Returns structural property descriptor for the "initializer" property
53      * of this node.
54      *
55      * @return the property descriptor
56      * @since 3.1
57      */

58     abstract ChildPropertyDescriptor internalInitializerProperty();
59
60     /**
61      * Returns structural property descriptor for the "initializer" property
62      * of this node.
63      *
64      * @return the property descriptor
65      * @since 3.1
66      */

67     public final ChildPropertyDescriptor getInitializerProperty() {
68         return internalInitializerProperty();
69     }
70
71     /**
72      * Returns structural property descriptor for the "name" property
73      * of this node.
74      *
75      * @return the property descriptor
76      * @since 3.1
77      */

78     abstract ChildPropertyDescriptor internalNameProperty();
79
80     /**
81      * Returns structural property descriptor for the "name" property
82      * of this node.
83      *
84      * @return the property descriptor
85      * @since 3.1
86      */

87     public final ChildPropertyDescriptor getNameProperty() {
88         return internalNameProperty();
89     }
90
91     /**
92      * Creates a new AST node for a variable declaration owned by the given AST.
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     VariableDeclaration(AST ast) {
100         super(ast);
101     }
102     
103     /**
104      * Returns the name of the variable declared in this variable declaration.
105      *
106      * @return the variable name node
107      */

108     public abstract SimpleName getName();
109         
110     /**
111      * Sets the name of the variable declared in this variable declaration
112      * to the given name.
113      *
114      * @param variableName the new variable name
115      * @exception IllegalArgumentException if:
116      * <ul>
117      * <li>the node belongs to a different AST</li>
118      * <li>the node already has a parent</li>
119      * </ul>
120      */

121     public abstract void setName(SimpleName variableName);
122
123     /**
124      * Returns the number of extra array dimensions over and above the
125      * explicitly-specified type.
126      * <p>
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.
133      * </p>
134      *
135      * @return the number of extra array dimensions
136      * @since 2.1
137      */

138     public abstract int getExtraDimensions();
139
140     /**
141      * Sets the number of extra array dimensions over and above the
142      * explicitly-specified type.
143      * <p>
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.
150      * </p>
151      *
152      * @param dimensions the number of array dimensions
153      * @exception IllegalArgumentException if the number of dimensions is
154      * negative
155      * @since 2.1
156      */

157     public abstract void setExtraDimensions(int dimensions);
158
159     /**
160      * Returns the initializer of this variable declaration, or
161      * <code>null</code> if there is none.
162      *
163      * @return the initializer expression node, or <code>null</code> if
164      * there is none
165      */

166     public abstract Expression getInitializer();
167     
168     /**
169      * Sets or clears the initializer of this variable declaration.
170      *
171      * @param initializer the initializer expression node, or <code>null</code>
172      * if there is none
173      * @exception IllegalArgumentException if:
174      * <ul>
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>
178      * </ul>
179      */

180     public abstract void setInitializer(Expression initializer);
181
182     /**
183      * Resolves and returns the binding for the variable declared in this
184      * variable declaration.
185      * <p>
186      * Note that bindings are generally unavailable unless requested when the
187      * AST is being built.
188      * </p>
189      *
190      * @return the binding, or <code>null</code> if the binding cannot be
191      * resolved
192      */

193     public IVariableBinding resolveBinding() {
194         return this.ast.getBindingResolver().resolveVariable(this);
195     }
196 }
197
Popular Tags