Bug 46013 - IBinding.getKey() for local shouldn't return null
Summary: IBinding.getKey() for local shouldn't return null
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-04 05:15 EST by Dirk Baeumer CLA
Modified: 2003-11-24 05:59 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2003-11-04 05:15:45 EST
I20031029

Now that we have Java elements for locals (and therefore start to support 
actions for them) we sometimes need to know if two locals refer to the same 
element in two different ASTs build for the same CU. This is currently not 
possible because getKey returns null and the bindings aren't identical. Can we 
use the same schema for the key that we use for the Java elements.
Comment 1 Jerome Lanneluc CLA 2003-11-04 06:46:30 EST
Dirk, the key of a local variable will be based on the variable id (see 
IVariableBinding#getVariableId()). This means that if you compare this 2 
versions of the same cu:
public class X {
  void foo() {
    int a;
    int b;
    int c;
  }
}
and
public class X {
  void foo() {
    int a;
    int c;
  }
}

the local variable 'b' in the first version will have the same key as the local 
variable 'c' in the second version.

Will that be ok for you?
Comment 2 Dirk Baeumer CLA 2003-11-05 04:30:49 EST
Hmmm... Yes and No. I know that the key for locals isn't stable, but may be we 
could it make it a little bit more stable by using the following schema:

Path to method/block scope number/variable_name

class A {
  void foo() {
    {
       int a;
    }
    {
       int a;
       int b;
    }
  }
}

will result is the following three keys

A/foo/1/a
A/foo/2/a
A/foo/2/b

Comment 3 Jerome Lanneluc CLA 2003-11-05 12:25:51 EST
Added support for local variable and added regression test 
AstConverterTest2.test0502().

Working on local and anonymous types.
Comment 4 Jerome Lanneluc CLA 2003-11-05 12:43:05 EST
Dirk, now for anonymous types: how stable do you want their key be?
In this example:
class A {
  void foo() {
    new Object() {
    };
    new Object() {
    };
  }
}
how to distinguish the first anoymous from the second one?
Comment 5 Dirk Baeumer CLA 2003-11-05 13:14:04 EST
Good question. In this case we have to enumerate the anonymoues classes. 
Something like A/foo/1/Object$1
Comment 6 Jerome Lanneluc CLA 2003-11-06 07:30:46 EST
Sorry Dirk, we don't have enough information to compute the occurence count for 
an anonymous class inside a method. The best we can do is A$1 for the first 
anonymous in type A, A$2 for the second, etc. Would that be ok?
Comment 7 Dirk Baeumer CLA 2003-11-06 09:13:30 EST
Yes, this is ok. It is better than having null ;-).
Comment 8 Jerome Lanneluc CLA 2003-11-06 09:48:59 EST
Added support for local and anonymous types.
Updated spec of IBinding.getKey(),
Added regression tests AstConverterTest2.test0502a() to test0502h()
Comment 9 Dirk Baeumer CLA 2003-11-06 13:11:43 EST
Jerome, does this cover methods and fields in local types as well ?
Comment 10 Jerome Lanneluc CLA 2003-11-07 02:23:04 EST
Yes, method and fields in local types are supported
Comment 11 David Audel CLA 2003-11-24 05:59:01 EST
Verified.