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;
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).
19 * @see ITypeBinding#getDeclaredFields()
21 * @noimplement This interface is not intended to be implemented by clients.
23 public interface IVariableBinding extends IBinding {
26 * Returns whether this binding is for a field.
27 * Note that this method returns <code>true</code> for constants,
28 * including enum constants. This method returns <code>false</code>
29 * for local variables.
31 * @return <code>true</code> if this is the binding for a field,
32 * and <code>false</code> otherwise
34 public boolean isField();
37 * Returns whether this binding is for an enum constant.
38 * Note that this method returns <code>false</code> for local variables
39 * and for fields other than enum constants.
41 * @return <code>true</code> if this is the binding for an enum constant,
42 * and <code>false</code> otherwise
45 public boolean isEnumConstant();
48 * Returns whether this binding corresponds to a parameter.
50 * @return <code>true</code> if this is the binding for a parameter,
51 * and <code>false</code> otherwise
54 public boolean isParameter();
57 * Returns the name of the field or local variable declared in this binding.
58 * The name is always a simple identifier.
60 * @return the name of this field or local variable
62 public String getName();
65 * Returns the type binding representing the class or interface
66 * that declares this field.
68 * The declaring class of a field is the class or interface of which it is
69 * a member. Local variables have no declaring class. The field length of an
70 * array type has no declaring class.
73 * @return the binding of the class or interface that declares this field,
74 * or <code>null</code> if none
76 public ITypeBinding getDeclaringClass();
79 * Returns the binding for the type of this field or local variable.
81 * @return the binding for the type of this field or local variable
83 public ITypeBinding getType();
86 * Returns a small integer variable id for this variable binding.
88 * <b>Local variables inside methods:</b> Local variables (and parameters)
89 * declared within a single method are assigned ascending ids in normal
90 * code reading order; var1.getVariableId()<var2.getVariableId() means that var1 is
91 * declared before var2.
94 * <b>Local variables outside methods:</b> Local variables declared in a
95 * type's static initializers (or initializer expressions of static fields)
96 * are assigned ascending ids in normal code reading order. Local variables
97 * declared in a type's instance initializers (or initializer expressions
98 * of non-static fields) are assigned ascending ids in normal code reading
99 * order. These ids are useful when checking definite assignment for
100 * static initializers (JLS 16.7) and instance initializers (JLS 16.8),
104 * <b>Fields:</b> Fields declared as members of a type are assigned
105 * ascending ids in normal code reading order;
106 * field1.getVariableId()<field2.getVariableId() means that field1 is declared before
110 * @return a small non-negative variable id
112 public int getVariableId();
115 * Returns this binding's constant value if it has one.
116 * Some variables may have a value computed at compile-time. If the type of
117 * the value is a primitive type, the result is the boxed equivalent (i.e.,
118 * int returned as an <code>Integer</code>). If the type of the value is
119 * <code>String</code>, the result is the string itself. If the variable has
120 * no compile-time computed value, the result is <code>null</code>.
121 * (Note: compile-time constant expressions cannot denote <code>null</code>;
122 * JLS2 15.28.). The result is always <code>null</code> for enum constants.
124 * @return the constant value, or <code>null</code> if none
127 public Object getConstantValue();
130 * Returns the method binding representing the method containing the scope
131 * in which this local variable is declared.
133 * The declaring method of a method formal parameter is the method itself.
134 * For a local variable declared somewhere within the body of a method,
135 * the declaring method is the enclosing method. When local or anonymous
136 * classes are involved, the declaring method is the innermost such method.
137 * There is no declaring method for a field, or for a local variable
138 * declared in a static or instance initializer; this method returns
139 * <code>null</code> in those cases.
142 * @return the binding of the method or constructor that declares this
143 * local variable, or <code>null</code> if none
146 public IMethodBinding getDeclaringMethod();
149 * Returns the binding for the variable declaration corresponding to this
150 * variable binding. For a binding for a field declaration in an instance
151 * of a generic type, this method returns the binding for the corresponding
152 * field declaration in the generic type. For other variable bindings,
153 * including all ones for local variables and parameters, this method
154 * returns the same binding.
156 * @return the variable binding for the originating declaration
159 public IVariableBinding getVariableDeclaration();