Bug 87171 - Find declaring node doesn't work for methods/fields using type parameters
Summary: Find declaring node doesn't work for methods/fields using type parameters
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Jim des Rivieres CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-04 14:19 EST by Dirk Baeumer CLA
Modified: 2005-05-11 08:48 EDT (History)
5 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 2005-03-04 14:19:26 EST
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.
Comment 1 Martin Aeschlimann CLA 2005-03-05 03:55:19 EST
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


Comment 2 Dirk Baeumer CLA 2005-03-06 13:58:05 EST
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.
Comment 3 Olivier Thomann CLA 2005-03-07 12:36:35 EST
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.
Comment 4 Olivier Thomann CLA 2005-03-07 12:54:35 EST
Fixed and released in HEAD.
Regression test added in ASTConverter15Test.test0144
Comment 5 Dirk Baeumer CLA 2005-03-07 13:42:33 EST
Olivier, did you consider variable bindings as well. They have to be normalized
as well with the method Jeem added.
Comment 6 Olivier Thomann CLA 2005-03-07 14:16:58 EST
Thanks, Dirk.
I added the same support for IVariable binding.
See ASTConverter15Test.test0141.
Comment 7 Martin Aeschlimann CLA 2005-03-08 03:31:01 EST
I think also
CompilationUnit.findDeclaringNode(String bindingKey)
should be updated
Comment 8 Olivier Thomann CLA 2005-03-08 09:00:30 EST
Reopen for API update.
Comment 9 Olivier Thomann CLA 2005-03-08 09:01:10 EST
Jim,

Could you please check if the API needs to be updated. The problem itself is
already fixed in HEAD.
Comment 10 Jim des Rivieres CLA 2005-04-20 23:51:20 EDT
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.
Comment 11 Olivier Thomann CLA 2005-05-11 08:48:40 EDT
Verified in I20050510-0010.