Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352464

Summary: [1.7] Incorrect Javadoc shown for reference of invokeExact (missing PolymorphicSignature annotation)
Product: [Eclipse Project] JDT Reporter: Deepak Azad <deepakazad>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, markus.kell.r, Olivier_Thomann
Version: 3.7Flags: Olivier_Thomann: review? (amj87.iitr)
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix + regression test none

Description Deepak Azad CLA 2011-07-19 10:24:22 EDT
- Hover over invokeExact method call to bring up the Javadoc hover
----------------------------------------------------------------
public static void main(String[] args) throws Throwable {
	MethodHandles.Lookup lookup = MethodHandles.lookup();
	MethodType mt = MethodType.methodType(String.class, String.class, char.class);
	MethodHandle mh = lookup.findStatic(InvokeExactAndGeneric1.class, "append", mt);
	mh.invokeExact("appen",'d'); //hover here
}
----------------------------------------------------------------

Two things

1) The method signature is shown as 
"Object java.lang.invoke.MethodHandle.invokeExact(String args0, char args1) throws Throwable"
Shouldn't it be "invokeExact(Object... args)" ?

2) @PolymorphicSignature annotation is not shown in the javadoc. (The annotation is there when hovering over declaration of invokeExact, but is missing on the method reference)
Comment 1 Olivier Thomann CLA 2011-07-19 14:35:52 EDT
(In reply to comment #0)
> 1) The method signature is shown as 
> "Object java.lang.invoke.MethodHandle.invokeExact(String args0, char args1)
> throws Throwable"
> Shouldn't it be "invokeExact(Object... args)" ?
I think this should be handled directly in:
org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabelComposer.appendMethodLabel(IMethod, long) 
when the IMethod is polymorphic the declared types should be used.

> 2) @PolymorphicSignature annotation is not shown in the javadoc. (The
> annotation is there when hovering over declaration of invokeExact, but is
> missing on the method reference)
I am not sure why you expect the annotation on the reference.
Comment 2 Olivier Thomann CLA 2011-07-21 12:29:25 EDT
Created attachment 200106 [details]
Proposed fix + regression test

We indeed are returning method declaration annotation for method invocations. This patch should solve that part of the problem. I still believe the signature should be handled by the UI side.
Comment 3 Olivier Thomann CLA 2011-07-21 14:19:48 EDT
Ayushman, please review.
Comment 4 Olivier Thomann CLA 2011-07-25 12:18:56 EDT
Released in BETA_JAVA7 branch only.

Markus/Deepak, could you please confirm that the signature should be handled by the UI side ?
Maybe we should add an isPolymorphic() method on IMethod to ease the check on the UI side.
Comment 5 Deepak Azad CLA 2011-07-26 01:09:21 EDT
I am a little confused. When I hover over the declaration or a reference of java.util.Arrays.asList(T...), I do NOT see @SafeVarargs annotation in the javadoc hover.

However, when I create my own method and hover over its declaration or a reference I see the annotation in the javadoc hover.
	@SafeVarargs
	public static <T> List<T> asList(T... a) {
		return null;
	}

With the fix from comment 2, java.util.Arrays.asList(T...) is the only case I know at this point where a annotation is missing in the javadoc hover.
Comment 6 Markus Keller CLA 2011-07-26 06:50:24 EDT
The signature is correct as it is rendered. The invocation of polymorphic methods is handled specially by the compiler: It always uses the static types of the actual argument expressions to determine the actually called method. The hover reinforces that by showing the actual signature.

The fix for the PolymorphicSignature annotation works fine.

(In reply to comment #5)
> I am a little confused. When I hover over the declaration or a reference of
> java.util.Arrays.asList(T...), I do NOT see @SafeVarargs annotation in the
> javadoc hover.

That's a separate issue. Filed bug 353093.
Comment 7 Jay Arthanareeswaran CLA 2011-08-02 10:23:42 EDT
Verified for 3.8M1 with build I20110729-1200.