Community
Participate
Working Groups
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..."
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.
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 ?
I would use getSourceRange() in all cases. If it is a null or the [0, -1] range, then check for the default constructor case.
Created attachment 99056 [details] Proposed fix ((JavaElement)method).getSourceMapper() is replaced by ((JavaElement)method).getClassFile().getBuffer() to check if there is attached source.
Patch is simple. Good candidate for RC1.
Jerome - Could you review my fix ?
Fix looks good.
Released for 3.4RC1. Tests added ResolveTests#testConstructor5() -> testConstructor6()
Verified for 3.4RC1 using I20080510-2000