Community
Participate
Working Groups
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.
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?
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
Added support for local variable and added regression test AstConverterTest2.test0502(). Working on local and anonymous types.
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?
Good question. In this case we have to enumerate the anonymoues classes. Something like A/foo/1/Object$1
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?
Yes, this is ok. It is better than having null ;-).
Added support for local and anonymous types. Updated spec of IBinding.getKey(), Added regression tests AstConverterTest2.test0502a() to test0502h()
Jerome, does this cover methods and fields in local types as well ?
Yes, method and fields in local types are supported
Verified.