Community
Participate
Working Groups
The documentation for org.eclipse.jdt.core.dom.IVariableBinding.getVariableId() explicitly states that "the numbering does not include the local variables declared within the method's local (or anonymous) types - their ids would be relative to the methods of the local type". However, this is apparently not the case. When obtaining an IVariableBinding from a SimpleName that represents a local variable, the IDs for local variables inside nested methods are not relative to their directly declaring method (i.e., starting at 0) but to the enclosing method (i.e., starting at last ID used in enclosing method plus one). I was hoping to solve a certain variable use analysis problem using the variable ID, but that code depends on getVariableId() working as specified.
Would you have a test case to submit? Thanks.
We've looked into this and you're right. The implementation does not honor this clause of the spec: "Note that the numbering does not include the local variables declared within the method's local (or anonymous) types - their ids would be relative to the methods of the local type." Since it has never worked this way, and would be some work to make it work that way, we are considering dropping this clause from the spec. btw, although the implementation currently start variable ids from 0, the initial numbering and gap between ids is unspecified. The intent is to provide sufficient info to judge relative position and nothing more. Mirko: would you be able to adjust your analysis algorithm accordingly?
Reconsider post 3.0.
Thanks for looking into this. We were able to work around the bug and use a different approach that does not depend on getVariableId(). If you decide not to implement the numbering scheme that is advertised, please make sure that the documentation is updated accordingly, so that no one else runs into this trap.
We will drop the clause from the spec. This aligns the spec with what has been implemented all along. This API change approved by PMC from inclusion in 3.0 M9. Reopening. Olivier, pls verify.
Verified that the note has been removed.
Fixed and released in HEAD.
Verified in 200405201600.