Community
Participate
Working Groups
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)
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.
Changed MethodBinding#getJavaElement() to use the compiler binding instead of the ASTNode in case of a binary method. Added regression test ASTModelBridgeTests#testBinaryMethod()
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...
Try org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] parameters = original.parameters;
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.