Bug 14322 - AST/DOM : IVariableBinding.getDeclaringClass() for 'length' field of an array return null
Summary: AST/DOM : IVariableBinding.getDeclaringClass() for 'length' field of an array...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-22 11:34 EDT by Luc Bourlier CLA
Modified: 2002-04-23 08:47 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Bourlier CLA 2002-04-22 11:34:50 EDT
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){
  }
}
Comment 1 Olivier Thomann CLA 2002-04-22 12:26:45 EDT
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.
Comment 2 Luc Bourlier CLA 2002-04-22 14:25:41 EDT
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.
Comment 3 Olivier Thomann CLA 2002-04-22 14:34:55 EDT
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.