Bug 194743 - Constructor tooltip does not show constructor javadoc without source attachment
Summary: Constructor tooltip does not show constructor javadoc without source attachment
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-28 08:02 EDT by Heiko Selber CLA
Modified: 2008-05-13 11:00 EDT (History)
2 users (show)

See Also:
jerome_lanneluc: review+


Attachments
Proposed fix (5.01 KB, patch)
2008-05-07 07:58 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Heiko Selber CLA 2007-06-28 08:02:45 EDT
When I use a jar with a javadoc attachment, but without a source attachment, the tooltip for a constructor from this jar in the Java editor displays the javadoc of the class instead of the constructor's.

All other methods are correctly shown (AFAICT).

Only when I attach the sources, too, the constructor tooltip is shown.


Example: I installed Java3D from https://java3d.dev.java.net/binary-builds.html

This adds 3 jars (3dcore.jar, 3dutils.jar and vecmath.jar) to the lib/ext directory of all appropriate JREs.

They are automagically added to the JRE system libraries in Eclipse.

The jars come without sources and javadoc, so I installed the javadoc (java3d-1_5_1-docs.zip; note this link is broken, it should point to java3d-1_5_1-api-docs.zip) separately.

I then attached it to the jars, using Window -> Preferences -> Java -> Installed JREs -> Edit...

Then, open one of the examples (from j3d-examples-1_5_1-src.zip), e.g. SphereMotion.java and let the mouse hover over the constructor of Sphere in this line:

Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 80, a);

The tooltip shows the description of the class:

"com.sun.j3d.utils.geometry.Sphere
Sphere is a geometry primitive created with a given radius and resolution. It is centered at the origin..."

If you attach the sources (j3d-1_5_1-src.zip and vecmath-1_5_1-src.zip, respectively), the tooltip will show the correct javadoc of the constructor itself:

"com.sun.j3d.utils.geometry.Sphere.Sphere(float radius, int primflags, int divisions, Appearance ap)
Constructs a customized Sphere of a given radius, number of divisions, and..."
Comment 1 Olivier Thomann CLA 2007-07-09 15:15:39 EDT
The problem comes from the selection engine that returns a type when hovering on the word "Sphere".
This is then map to the binary type Sphere as a java element for which the javadoc is requested.
If you open the type Sphere (without having the source attached, just the javadoc) and in the outliner you select the constructors, you can see in the javadoc view that the proper documentation is displayed.
If the source is attached, the selection engine returns a ResolvedBinaryMethod node and therefore the javadoc is properly retrieved.

David, would it be possible to get a ResolvedBinaryMethod in both cases? This would make the behavior more consistent.
Comment 2 David Audel CLA 2007-07-10 10:54:02 EDT
The bug seems to be a regression due to the fix of bug 126330.

SelectionRequestor#acceptBinaryMethod(IType,IMethod,char[],boolean) use JavaElement#getSourceMapper() to know if there is an attached source. Before the fix for 126330 null was returned.

A fix could be to use getSourceAttachmentPath() of the package fragment root instead of getSourceMapper() or to flag the source mapper with a special value when there is no attached source.

jerome - do you see a better way to know that there is no attached source from an IMethod ?
Comment 3 Jerome Lanneluc CLA 2007-08-09 07:46:01 EDT
I would use getSourceRange() in all cases. If it is a null or the [0, -1] range, then check for the default constructor case.
Comment 4 David Audel CLA 2008-05-07 07:58:11 EDT
Created attachment 99056 [details]
Proposed fix

((JavaElement)method).getSourceMapper() is replaced by ((JavaElement)method).getClassFile().getBuffer() to check if there is attached source.
Comment 5 Jerome Lanneluc CLA 2008-05-07 09:22:31 EDT
Patch is simple. Good candidate for RC1.
Comment 6 David Audel CLA 2008-05-07 09:23:28 EDT
Jerome - Could you review my fix ?
Comment 7 Jerome Lanneluc CLA 2008-05-07 09:36:19 EDT
Fix looks good.
Comment 8 David Audel CLA 2008-05-07 09:41:46 EDT
Released for 3.4RC1.

Tests added
  ResolveTests#testConstructor5() -> testConstructor6()
Comment 9 Jerome Lanneluc CLA 2008-05-13 11:00:20 EDT
Verified for 3.4RC1 using I20080510-2000