Bug 110172 - [plan] API to extract the Javadoc on org.eclipse.jdt.core.IMember
Summary: [plan] API to extract the Javadoc on org.eclipse.jdt.core.IMember
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 75980 (view as bug list)
Depends on:
Blocks: 127898
  Show dependency tree
 
Reported: 2005-09-21 09:37 EDT by Jerome Lanneluc CLA
Modified: 2007-06-21 07:48 EDT (History)
4 users (show)

See Also:


Attachments
Proposed API (1.16 KB, patch)
2005-09-29 17:33 EDT, Olivier Thomann CLA
no flags Details | Diff
API + implementation (3.76 KB, patch)
2005-10-20 15:33 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression tests (14.98 KB, patch)
2005-10-20 15:34 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jerome Lanneluc CLA 2005-09-21 09:37:33 EDT
I20050920

A new API to get the Javadoc for a Java element is needed. This API will extract
the Javadoc from the IBuffer of the Java element (underlying compilation unit,
or attached source for a class file).
Comment 1 Olivier Thomann CLA 2005-09-29 16:56:38 EDT
Would this be fine?

/**
 * Returns the Javadoc in HTML format if found, null otherwise.
 * 
 * <p>If this element is from source, then the javadoc is 
 * extracted from the corresponding source.</p>
 * <p>If this element is from a binary, the the javadoc is extracted from either
the 
 * attached source if present or the
IClasspathAttribute#JAVADOC_LOCATION_ATTRIBUTE_NAME
 * attribute of the corresponding classpath entry if set.
 *
 * @return a string with the Javadoc in HTML format.
 * @since 3.2
 */
String getJavadoc();
Comment 2 Olivier Thomann CLA 2005-09-29 17:33:57 EDT
Created attachment 27701 [details]
Proposed API
Comment 3 Jerome Lanneluc CLA 2005-09-30 04:36:32 EDT
Extracting the Javadoc from bug
IClasspathAttribute#JAVADOC_LOCATION_ATTRIBUTE_NAME is covered by bug 110173 and
should be a separated API.

I don't think the API for this bug (extracting the Javadoc from source) should
convert it to HTML. Dani, can you please confirm this ? 
Comment 4 Olivier Thomann CLA 2005-09-30 08:26:29 EDT
I find two API redundant. The purpose of this API is to retrieve the javadoc of
the corresponding IJavaElement. For a binary element, the javadoc should be
retrieve from the javadoc attachement if no source is available. This should be
done transparently for the user.
Having two APIs would force the user to make two calls.
From my perpective bug 110173 is an implementation details of this bug.
Comment 5 Olivier Thomann CLA 2005-09-30 08:58:49 EDT
Dani,

I would need details to know what you expect. Right now this API proposal
matches what you have internally.
Could it be interesting to have two API? one to return the javadoc as it is in
the source and one to return it as HTML source.
Comment 6 Dani Megert CLA 2005-10-03 09:26:40 EDT
>I find two API redundant. The purpose of this API is to retrieve the javadoc of
>the corresponding IJavaElement. For a binary element, the javadoc should be
>retrieve from the javadoc attachement if no source is available.
This is the easy case ;-) The question is what do we do if both are present?
- the attached Javadoc might be better (since eventually being processed by some
doclet) than the result of extracting it from the source.
- the attached Javadoc might only contain public Javadoc.

Clients might want the Javadoc from source as is (as pointed out by Jerome) i.e.
not yet converted to HTML while the Javadoc from the attached Javadoc will be an
HTML fragment. However, there should be an option whether to convert the source
Javadoc to HTML or not (see JavadocContentAccess for how we currently offer it
to clients).

Could you also provide a reader instead of a string as we do in
JavadocContentAccess?
Comment 7 Dani Megert CLA 2005-10-03 10:08:39 EDT
Adding Martin to the cc-list since he implemented JDT UI's Javadoc access.
Comment 8 Martin Aeschlimann CLA 2005-10-03 10:58:49 EDT
I think there are 3 kind of functionalities:

a.) Binary Java elements that have no source attachment, but have a Javadoc
location, should make use of the Javadoc location as good as possible for a
source attachment replacement. -> E.g. create a source stub with Javadoc
comments, member header stubs and maybe disassebled code. I think this is bug
110173 and would not require any new API, just an updated SourceMapper.
With this change, all our code that gets the Javadoc from a member with source
will work without change. (We offer API for this, see JavadocContentAccess).

b.) The code that extracts Javadoc comments from a member (JavadocContentAccess)
could be taken over by jdt core. A cheaper way of doing it is just to have new
API that returns the source ranges of the Javadoc comment. The luxury way would
be to give back the comment in a structured way (similar to the DOM-AST). I
would suggest to simply add new api that returns the source ranges. Having the
source ranges, it should be possible for users to use the DOM AST.

c.) Code that extracts Javadoc for a member from an HTML page. This is code we
don't have yet, and would have to be done when implementing a.).
What we have is code that constructs an URL for a member:
JavaUI.getJavadocLocation(IJavaElement element, boolean resolveAnchor), that
then can be used to open a browser on the documentation of this member.

Important: the Javadoc locations attributes are currently only defined for
libaries, not for source. Javadoc for source does mostly not exist, or is
out-dated. JDT-UI currently lets you define a location _per project_ (not per
source folder!), and this location is currently not shared in the classpath but
only internal.
Comment 9 Olivier Thomann CLA 2005-10-04 15:12:47 EDT
(In reply to comment #6)
> This is the easy case ;-) The question is what do we do if both are present?
Would be up to the user to decide which one he wants to use?

> Clients might want the Javadoc from source as is (as pointed out by Jerome) i.e.
> not yet converted to HTML while the Javadoc from the attached Javadoc will be an
> HTML fragment. However, there should be an option whether to convert the source
> Javadoc to HTML or not (see JavadocContentAccess for how we currently offer it
> to clients).
Then we should offer an API that returns a string either in HTML or plain text
according to a flag. We would have one API to retrieve from source and one to
retrieve the javadoc from attached doc.

> Could you also provide a reader instead of a string as we do in
> JavadocContentAccess?
What would be the avantage to get a reader?
Comment 10 Martin Aeschlimann CLA 2005-10-05 03:50:49 EDT
It seems to me that returning a a html string is a bit too much for an API in
the Java model as it already deals with representation (e.g. decition to use a
list for the taks, make the tags bold ect.)
A string would be better but I think this might be already too much as
extracting the tags also requires to know if a tag is the first on the line.

/**
 * This @tag is just text. (This is an inline {@tag}, what you really should do)
 * @tag This is a real tag as it is first on the line.
 */

As said, I think best would be just to have a new API that returns the source
ranges of the Javadoc comment and we should have a way to use the DOM AST on
just that source to get tags and descriptions.
Comment 11 Olivier Thomann CLA 2005-10-05 09:49:14 EDT
Having a source range only would make it up to the user to convert to HTML.
That is fine for me.
So this API would return the source range if the javadoc is retrieved from the
source or attached source for binary element.
It would return null if no source is attached for binary element.
Ok for you?
Comment 12 Olivier Thomann CLA 2005-10-17 14:24:17 EDT
would this be fine?

/**
 * Returns the Javadoc range if this element is from source or if this element
 * is a binary element with an attached source, null otherwise.
 * 
 * <p>If this element is from source, then the javadoc range is 
 * extracted from the corresponding source.</p>
 * <p>If this element is from a binary, the the javadoc is extracted from the
 * attached source if present.</p>
 *
 * @return a source range corresponding to the javadoc source
 * @since 3.2
 */
ISourceRange getJavadocRange();
Comment 13 Jerome Lanneluc CLA 2005-10-18 04:12:00 EDT
(In reply to comment #12)
> would this be fine?
> 
> /**
>  * Returns the Javadoc range if this element is from source or if this element
>  * is a binary element with an attached source, null otherwise.
>  * 
>  * <p>If this element is from source, then the javadoc range is 
>  * extracted from the corresponding source.</p>
>  * <p>If this element is from a binary, the the javadoc is extracted from the
>  * attached source if present.</p>
>  *
>  * @return a source range corresponding to the javadoc source
>  * @since 3.2
>  */
> ISourceRange getJavadocRange();

This looks good to me.
Comment 14 Dani Megert CLA 2005-10-18 05:03:47 EDT
+1
Comment 15 Martin Aeschlimann CLA 2005-10-18 06:41:13 EDT
looks good!

I would add to @return:
a source range corresponding to the javadoc source or <code>null</code> if no
source is available or the element has no javadoc comment.
Comment 16 Olivier Thomann CLA 2005-10-20 10:50:26 EDT
I'll start implementing this one.
Comment 17 Olivier Thomann CLA 2005-10-20 10:54:50 EDT
Maybe we should put this new API only on IMember since it has no meaning otherwise.
Comment 18 Jerome Lanneluc CLA 2005-10-20 11:05:59 EDT
(In reply to comment #17)
> Maybe we should put this new API only on IMember since it has no meaning
otherwise.
agreed
Comment 19 Olivier Thomann CLA 2005-10-20 11:20:36 EDT
We might also want to add:
 * @exception JavaModelException if this element does not exist or if an
 *      exception occurs while accessing its corresponding resource.

Since we access the buffer of the corresponding IMember, we can either add a
throws clause or silently consume the exception. I am inclined to add a throws
clause.
Comment 20 Olivier Thomann CLA 2005-10-20 11:22:39 EDT
So to summarize, we end up with this API:

/**
 * Returns the Javadoc range if this element is from source or if this element
 * is a binary element with an attached source, null otherwise.
 * 
 * <p>If this element is from source, the javadoc range is 
 * extracted from the corresponding source.</p>
 * <p>If this element is from a binary, the javadoc is extracted from the
 * attached source if present.</p>
 *
 * @exception JavaModelException if this element does not exist or if an
 *      exception occurs while accessing its corresponding resource.
 * @return a source range corresponding to the javadoc source or <code>null</code>
 * if no source is available or the element has no javadoc comment.
 * @since 3.2
 */
ISourceRange getJavadocRange() throws JavaModelException;

defined on org.eclipse.jdt.core.IMember.
Comment 21 Olivier Thomann CLA 2005-10-20 12:12:48 EDT
Update title accordingly.
The API is ready to be released if it is ok with you.
Comment 22 Olivier Thomann CLA 2005-10-20 15:33:38 EDT
Created attachment 28542 [details]
API + implementation
Comment 23 Olivier Thomann CLA 2005-10-20 15:34:16 EDT
Created attachment 28544 [details]
Regression tests

I will release the binary files separately.
Comment 24 Olivier Thomann CLA 2005-10-20 18:29:44 EDT
Fixed and released in HEAD.
Regression tests added in
org.eclipse.jdt.core.tests.model.AttachSourceTests.test110172 and
org.eclipse.jdt.core.tests.model.CompilationUnitTests.test110172.
Comment 25 David Audel CLA 2005-10-31 06:06:45 EST
Verified for 3.2 M3 using build I20051031-0010
Comment 26 Christopher Oezbek CLA 2006-03-14 15:13:19 EST
Hello,
  I just discovered this awesome API-extension in the release plan for 3.2. Does this mean it is now basically possible to extract all information necessary to build a JavaDoc documentation from the JavaModel? Is something like this planned to replace the external dependency on javadoc?

  Hm. But how about the JavaDoc associated with an IPackageFragment? Java 1.5 has the JavaDoc in the package-info.java (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=83804 for more information about package-info.java)

Thanks,
  Christopher

Comment 27 Martin Aeschlimann CLA 2006-03-15 04:04:44 EST
No there are no plans to change the Javadoc wizard to not use the javadoc command. There's more involved than just extracting comments from files. But this might be better discussed in a new bug report. 
Comment 28 Christopher Oezbek CLA 2006-03-15 05:43:41 EST
I would like to elaborate on the possible bug in comment #26:

(In reply to comment #17)
> Maybe we should put this new API only on IMember since it has no meaning
> otherwise.

That's right with the notable exception that a PackageFragment also has a JavaDoc comment (in the package-info.java) which should be accessible using the same interface.

Comment 29 Frederic Fusier CLA 2007-06-21 07:48:55 EDT
*** Bug 75980 has been marked as a duplicate of this bug. ***