KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * A variable binding represents either a field of a class or interface, or
16  * a local variable declaration (including formal parameters, local variables,
17  * and exception variables).
18  * <p>
19  * This interface is not intended to be implemented by clients.
20  * </p>
21  *
22  * @see ITypeBinding#getDeclaredFields()
23  * @since 2.0
24  */

25 public interface IVariableBinding extends IBinding {
26     
27     /**
28      * Returns whether this binding is for a field.
29      * Note that this method returns <code>true</code> for constants,
30      * including enum constants. This method returns <code>false</code>
31      * for local variables.
32      *
33      * @return <code>true</code> if this is the binding for a field,
34      * and <code>false</code> otherwise
35      */

36     public boolean isField();
37     
38     /**
39      * Returns whether this binding is for an enum constant.
40      * Note that this method returns <code>false</code> for local variables
41      * and for fields other than enum constants.
42      *
43      * @return <code>true</code> if this is the binding for an enum constant,
44      * and <code>false</code> otherwise
45      * @since 3.1
46      */

47     public boolean isEnumConstant();
48     
49     /**
50      * Returns the name of the field or local variable declared in this binding.
51      * The name is always a simple identifier.
52      *
53      * @return the name of this field or local variable
54      */

55     public String JavaDoc getName();
56     
57     /**
58      * Returns the type binding representing the class or interface
59      * that declares this field.
60      * <p>
61      * The declaring class of a field is the class or interface of which it is
62      * a member. Local variables have no declaring class. The field length of an
63      * array type has no declaring class.
64      * </p>
65      *
66      * @return the binding of the class or interface that declares this field,
67      * or <code>null</code> if none
68      */

69     public ITypeBinding getDeclaringClass();
70
71     /**
72      * Returns the binding for the type of this field or local variable.
73      *
74      * @return the binding for the type of this field or local variable
75      */

76     public ITypeBinding getType();
77     
78     /**
79      * Returns a small integer variable id for this variable binding.
80      * <p>
81      * <b>Local variables inside methods:</b> Local variables (and parameters)
82      * declared within a single method are assigned ascending ids in normal
83      * code reading order; var1.getVariableId()&lt;var2.getVariableId() means that var1 is
84      * declared before var2.
85      * </p>
86      * <p>
87      * <b>Local variables outside methods:</b> Local variables declared in a
88      * type's static initializers (or initializer expressions of static fields)
89      * are assigned ascending ids in normal code reading order. Local variables
90      * declared in a type's instance initializers (or initializer expressions
91      * of non-static fields) are assigned ascending ids in normal code reading
92      * order. These ids are useful when checking definite assignment for
93      * static initializers (JLS 16.7) and instance initializers (JLS 16.8),
94      * respectively.
95      * </p>
96      * <p>
97      * <b>Fields:</b> Fields declared as members of a type are assigned
98      * ascending ids in normal code reading order;
99      * field1.getVariableId()&lt;field2.getVariableId() means that field1 is declared before
100      * field2.
101      * </p>
102      *
103      * @return a small non-negative variable id
104      */

105     public int getVariableId();
106     
107     /**
108      * Returns this binding's constant value if it has one.
109      * Some variables may have a value computed at compile-time. If the type of
110      * the value is a primitive type, the result is the boxed equivalent (i.e.,
111      * int returned as an <code>Integer</code>). If the type of the value is
112      * <code>String</code>, the result is the string itself. If the variable has
113      * no compile-time computed value, the result is <code>null</code>.
114      * (Note: compile-time constant expressions cannot denote <code>null</code>;
115      * JLS2 15.28.). The result is always <code>null</code> for enum constants.
116      *
117      * @return the constant value, or <code>null</code> if none
118      * @since 3.0
119      */

120     public Object JavaDoc getConstantValue();
121     
122     /**
123      * Returns the method binding representing the method containing the scope
124      * in which this local variable is declared.
125      * <p>
126      * The declaring method of a method formal parameter is the method itself.
127      * For a local variable declared somewhere within the body of a method,
128      * the declaring method is the enclosing method. When local or anonymous
129      * classes are involved, the declaring method is the innermost such method.
130      * There is no declaring method for a field, or for a local variable
131      * declared in a static or instance initializer; this method returns
132      * <code>null</code> in those cases.
133      * </p>
134      *
135      * @return the binding of the method or constructor that declares this
136      * local variable, or <code>null</code> if none
137      * @since 3.1
138      */

139     public IMethodBinding getDeclaringMethod();
140     
141     /**
142      * Returns the binding for the variable declaration corresponding to this
143      * variable binding. For a binding for a field declaration in an instance
144      * of a generic type, this method returns the binding for the corresponding
145      * field declaration in the generic type. For other variable bindings,
146      * including all ones for local variables and parameters, this method
147      * returns the same binding.
148      *
149      * @return the variable binding for the originating declaration
150      * @since 3.1
151      */

152     public IVariableBinding getVariableDeclaration();
153
154 }
155
Popular Tags