Bug 91445 - IMethodBinding.getJavaElement() returns an "unopen" IMethod
Summary: IMethodBinding.getJavaElement() returns an "unopen" IMethod
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 88860
  Show dependency tree
 
Reported: 2005-04-14 15:26 EDT by Robert M. Fuhrer CLA
Modified: 2005-05-12 07:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert M. Fuhrer CLA 2005-04-14 15:26:00 EDT
IMethodBinding.getJavaElement() produces an IMethod that in the debugger looks like:

 unmodifiableList(java.util.List) (not open) [in Collections [in
Collections.class [in java.util [in
...\org.eclipse.jdt.ui.tests\testresources\rtstubs15.jar [in UnmodifiableList]]]]]

Note the "(not open)" indication.

The odd thing is that this IMethod is an intermediate result of a call to
ITypeBinding.getJavaElement(). The scenario: in analyzing

 <T> List<T> Collections.unmodifiableList(List<? extends T> list);

which has a method type parameter, the following method is called, passing an
IMethodBinding for Collections.unmodifiableList():

 void foo(IMethodBinding method) {
     ITypeBinding[] parmBindings= method.getTypeParameters();

     for(int idx= 0; idx < parmBindings.length; idx++) {
         ITypeBinding pb= parmBindings[idx];
         ITypeParameter tp= (ITypeParameter) pb.getJavaElement();
         // ...
     }
 }

In particular, a call is made to getJavaElement() on the ITypeBinding for the
method type parameter, namely, <T>. This call throws a JavaModelException, since
at some level JDT/Core claims that the method doesn't exist. Obviously, since
I'm starting with an IMethodBinding, the method *does* exist.

In case you're wondering, the IMethodBinding in question was returned by
IMethodBinding.getMethodDeclaration(), so it refers to the original generic
declaration, not some instantiation.

============================================================================
An easier way to reproduce is this:
- select the type parameter of Collections#unmodifiableList(..) in the editor
and open the ASTView
- set a breakpoint in JavaUI.revealInEditor(..) 
- expand the type binding for T and doubleclick the java element in the ASTView
(the last, green child)
Comment 1 Markus Keller CLA 2005-04-19 12:03:36 EDT
The problem is that the parameterTypes in the returned IMethod
unmodifiableList(..) are unresolved: [QList<+QT;>;].
The parameterTypes of the correct IMethod are [Ljava.util.List<TT;>;].

This is a problem for all reference-type method argument types, not just exotic
cases.

Jerome, it would be nice if you could bump up the priority of this PR a bit. It
makes IMethodBinding.getJavaElement() unusable in most cases and thus prevents
further testing of the feature.
Comment 2 Jerome Lanneluc CLA 2005-04-20 04:00:48 EDT
Changed MethodBinding#getJavaElement() to use the compiler binding instead of
the ASTNode in case of a binary method.

Added regression test ASTModelBridgeTests#testBinaryMethod()
Comment 3 Robert M. Fuhrer CLA 2005-04-20 09:58:05 EDT
Seems the change to getJavaElement() is not quite compatible with the 3.1M6 
source base, specifically, the line

	TypeBinding[] parameters = original.parameters;

which gets a type error (two different kinds of TypeBinding's), and the call 
to TypeBinding.genericTypeSignature(), which apparently doesn't exist in M6.

Any chance of getting a patch for 3.1M6, or any hints on what to do about 
these two issues?

I'm trying to get something finished in the next few days before a hard 
deadline, before M7 will come out, and don't really have the time to switch to 
HEAD or the latest integration build...
Comment 4 Jerome Lanneluc CLA 2005-04-20 10:13:04 EDT
Try org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] parameters =
original.parameters;
Comment 5 Frederic Fusier CLA 2005-05-12 07:10:24 EDT
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.