Community
Participate
Working Groups
The code below is all in compilation unit Inline.java public class Inline<T> { void foo(T t) { System.out.println(t); } } class Use { public static void main(String[] args) { Inline<String> i= null; i.foo("Eclipse"); } } - take the method binding of the invocation foo in i.foo("Eclipse"); - take the root node representing the whole CU - call root.findDeclaringNode(methodBinding); observe: null is returned although the CU contains the corresponding declaration. Please note that the same happens for fields using type parameters.
IMO this is not a bug: You can only use the declaration binding for root.findDeclaringNode(methodBinding) -> get the method binding decl with methodBinding.getMethodDeclaration
IMO it is a bug. The doc says that the result is the declaration node for the binding iff the decl is in the same AST. So the method should apply the various get*Declaration methods.
I think that when the binding is a parameterized binding (method or type), then the declaring binding should be used transparently for the user. In this case, I should call getMethodDeclaration() on the binding you passed to the findDeclaringNode(...) method. Doing this, I would get the binding I stored when processing the method declaration. Does this change sound reasonable? If yes, I will release the code.
Fixed and released in HEAD. Regression test added in ASTConverter15Test.test0144
Olivier, did you consider variable bindings as well. They have to be normalized as well with the method Jeem added.
Thanks, Dirk. I added the same support for IVariable binding. See ASTConverter15Test.test0141.
I think also CompilationUnit.findDeclaringNode(String bindingKey) should be updated
Reopen for API update.
Jim, Could you please check if the API needs to be updated. The problem itself is already fixed in HEAD.
Added following para to specs for CompilationUnit.findDeclaringNode({IBinding, String}): * For parameterized or raw type bindings, the declaring node is * that of the corresponding generic type. And for parameterized or raw * method bindings, the declaring node is that of the corresponding * generic method.
Verified in I20050510-0010.