001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.core.dom;
011:
012: /**
013: * A variable binding represents either a field of a class or interface, or
014: * a local variable declaration (including formal parameters, local variables,
015: * and exception variables).
016: * <p>
017: * This interface is not intended to be implemented by clients.
018: * </p>
019: *
020: * @see ITypeBinding#getDeclaredFields()
021: * @since 2.0
022: */
023: public interface IVariableBinding extends IBinding {
024:
025: /**
026: * Returns whether this binding is for a field.
027: * Note that this method returns <code>true</code> for constants,
028: * including enum constants. This method returns <code>false</code>
029: * for local variables.
030: *
031: * @return <code>true</code> if this is the binding for a field,
032: * and <code>false</code> otherwise
033: */
034: public boolean isField();
035:
036: /**
037: * Returns whether this binding is for an enum constant.
038: * Note that this method returns <code>false</code> for local variables
039: * and for fields other than enum constants.
040: *
041: * @return <code>true</code> if this is the binding for an enum constant,
042: * and <code>false</code> otherwise
043: * @since 3.1
044: */
045: public boolean isEnumConstant();
046:
047: /**
048: * Returns whether this binding corresponds to a parameter.
049: *
050: * @return <code>true</code> if this is the binding for a parameter,
051: * and <code>false</code> otherwise
052: * @since 3.2
053: */
054: public boolean isParameter();
055:
056: /**
057: * Returns the name of the field or local variable declared in this binding.
058: * The name is always a simple identifier.
059: *
060: * @return the name of this field or local variable
061: */
062: public String getName();
063:
064: /**
065: * Returns the type binding representing the class or interface
066: * that declares this field.
067: * <p>
068: * The declaring class of a field is the class or interface of which it is
069: * a member. Local variables have no declaring class. The field length of an
070: * array type has no declaring class.
071: * </p>
072: *
073: * @return the binding of the class or interface that declares this field,
074: * or <code>null</code> if none
075: */
076: public ITypeBinding getDeclaringClass();
077:
078: /**
079: * Returns the binding for the type of this field or local variable.
080: *
081: * @return the binding for the type of this field or local variable
082: */
083: public ITypeBinding getType();
084:
085: /**
086: * Returns a small integer variable id for this variable binding.
087: * <p>
088: * <b>Local variables inside methods:</b> Local variables (and parameters)
089: * declared within a single method are assigned ascending ids in normal
090: * code reading order; var1.getVariableId()<var2.getVariableId() means that var1 is
091: * declared before var2.
092: * </p>
093: * <p>
094: * <b>Local variables outside methods:</b> Local variables declared in a
095: * type's static initializers (or initializer expressions of static fields)
096: * are assigned ascending ids in normal code reading order. Local variables
097: * declared in a type's instance initializers (or initializer expressions
098: * of non-static fields) are assigned ascending ids in normal code reading
099: * order. These ids are useful when checking definite assignment for
100: * static initializers (JLS 16.7) and instance initializers (JLS 16.8),
101: * respectively.
102: * </p>
103: * <p>
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
107: * field2.
108: * </p>
109: *
110: * @return a small non-negative variable id
111: */
112: public int getVariableId();
113:
114: /**
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.
123: *
124: * @return the constant value, or <code>null</code> if none
125: * @since 3.0
126: */
127: public Object getConstantValue();
128:
129: /**
130: * Returns the method binding representing the method containing the scope
131: * in which this local variable is declared.
132: * <p>
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.
140: * </p>
141: *
142: * @return the binding of the method or constructor that declares this
143: * local variable, or <code>null</code> if none
144: * @since 3.1
145: */
146: public IMethodBinding getDeclaringMethod();
147:
148: /**
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.
155: *
156: * @return the variable binding for the originating declaration
157: * @since 3.1
158: */
159: public IVariableBinding getVariableDeclaration();
160:
161: }
|