Community
Participate
Working Groups
with the following code, if I call getDeclaringClass() on the object IVariableBinding which represents 'length' from 'System.out.println(tab.length);', I get null. package test; public class Bar{ static void ___run(java.lang.String[] args, int[] tab) throws Throwable { System.out.println(tab.length); } public static void main (String[] args){ } }
What do you expect? length is not a field defined in a class. It is a special field which results in the arraylength bytecode. Then it doesn't seem wrong to reply null to getDeclaringClass() for such an IVariableBinding.
I know 'length' is a special field for array types, but I don't see any way for know if the IVariableBinding object I have represents the 'length' field of an object or for an array. For the moment, I ask the TypeBinding of the qualifier (for a QualifiedName) or the expression (for a FieldAccess) to know if the field is a normal field or the 'length' field of an array.
Another way is to check if getDeclaringClass() answers null and its name (you have the name set in the IVariableBinding) is "length". If "length" is the field "length" of a class, its declaring class won't be null. I will update the specs of IVariableBinding.getDeclaringClass() to reflect that it can reply null for the special length field. Fixed and released in HEAD.