Community
Participate
Working Groups
Build Identifier: M20100909-0800 I've noticed, local variables declared in an instance initializer have no "declaring class" (IVariableBinding.getDeclaringClass() returns null). However, classes declared inside an instance initializer return the enclosing class as the declaring class. I think this inconsistency should be considered a bug. Knowing a local variable's enclosing class is _extremely_ useful. Reproducible: Always Steps to Reproduce: 1. Example code: public class Initializer { { int i = 2; // has no declaring class class Inside { } // has declaring class } }
It would be an API breakage to return a declaring class for a local variable. /** * Returns the type binding representing the class or interface * that declares this field. * <p> * The declaring class of a field is the class or interface of which it is * a member. Local variables have no declaring class. The field length of an * array type has no declaring class. * </p> * * @return the binding of the class or interface that declares this field, * or <code>null</code> if none */ public ITypeBinding getDeclaringClass(); Closing as INVALID. You can retrieve the declaring method for the local variable. If you get null for the declaring method and null for the declaring class, then you know that you have a local variable inside an initializer (static or not).
It would be very useful to know the declaring class (for building a "semi-qualified" name - I know local variables have no qualified name). But not a bug, indeed. Should this be considered as a RFE?
(In reply to comment #2) > It would be very useful to know the declaring class (for building a > "semi-qualified" name - I know local variables have no qualified name). But not > a bug, indeed. Should this be considered as a RFE? Yes, please. Open a new bug report. A new method would be required on IVariableBinding. In your case would the binding's key be good enough ?
Yes, I'm currently using the binding key. But knowing the enclosing class matters would be a very desirable feature.
Verified for 3.7M5