Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] Retrieve javadoc programmatically

Hi Jay,

using your hints and looking through some JDT unit tests I found a way to retrieve help from source and javadoc for most of my use cases. Currently it works for class documentation, fields and most methods.

For unknown reasons resolving help fails for methods that are overwritten in the current class and static methods.

What I do is create a fake IProject implementation that basically provides the .classpath file content to JDT.
In the end it boils down to calling

JavadocHover.getHoverInfo(new IJavaElement[] { javaElement }, typeRoot, new Region(0, 1), null);

where JavaElement is of type ResolvedBinaryMethod and typeRoot is of type ClassFile.

I checked my parameters when creating the ResolvedBinaryMethod object with calls from JDT when a hover help is created and all creation parameters are identical. However in my implementation I end up with an exception:

!ENTRY org.eclipse.jdt.ui 4 10001 2015-09-23 20:46:34.060
!MESSAGE Internal Error
!STACK 1
Java Model Exception: Java Model Status [createTempFile(java/lang/String, java/lang/String) {key=Ljava/io/File;.createTempFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;|Ljava/io/IOException;} [in File [in File.class [in java.io [in /opt/oracle-jdk-bin-1.8.0.45/jre/lib/rt.jar]]]] does not exist]
    at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:556)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:590)
    at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:316)
    at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:302)
    at org.eclipse.jdt.internal.core.BinaryMethod.getFlags(BinaryMethod.java:198)
    at org.eclipse.jdt.internal.core.ResolvedBinaryMethod.getFlags(ResolvedBinaryMethod.java:1)
    at org.eclipse.jdt.internal.corext.util.MethodOverrideTester.findOverriddenMethodInType(MethodOverrideTester.java:193)
    at org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2$2.visit(JavadocContentAccess2.java:832)
    at org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2$InheritDocVisitor.visitInheritDocInterfaces(JavadocContentAccess2.java:238)
    at org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2$InheritDocVisitor.visitInheritDoc(JavadocContentAccess2.java:192)
    at org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2.findAttachedDocInHierarchy(JavadocContentAccess2.java:851)
    at org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2.getHTMLContent(JavadocContentAccess2.java:545)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo(JavadocHover.java:721)
    at org.eclipse.ease.ui.help.hovers.JavaClassHelpResolver.resolveHelp(JavaClassHelpResolver.java:55)
    at org.eclipse.ease.ui.help.hovers.JavaClassHelpResolver.resolveHTMLHelp(JavaClassHelpResolver.java:64)
    at org.eclipse.ease.ui.completion.ScriptCompletionProposal.getAdditionalProposalInfo(ScriptCompletionProposal.java:95)
    at org.eclipse.ease.ui.completion.ScriptCompletionProposal.getAdditionalProposalInfo(ScriptCompletionProposal.java:102)
    at org.eclipse.jface.text.contentassist.AdditionalInfoController$3.run(AdditionalInfoController.java:106)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!SUBENTRY 1 org.eclipse.jdt.core 4 969 2015-09-23 20:46:34.060
!MESSAGE createTempFile(java/lang/String, java/lang/String) {key=Ljava/io/File;.createTempFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;|Ljava/io/IOException;} [in File [in File.class [in java.io [in /opt/oracle-jdk-bin-1.8.0.45/jre/lib/rt.jar]]]] does not exist


Any idea what I am missing here?
Would be great to resolve this issue. Then we would have a template how to extract java help from JDT and could eventually think how to make the needed API public.

If anyone might want to look at my source code:
http://git.eclipse.org/c/ease/org.eclipse.ease.core.git/tree/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/help/hovers/JavaMethodHelpResolver.java
http://git.eclipse.org/c/ease/org.eclipse.ease.core.git/tree/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/help/hovers/JavaClassHelpResolver.java

thanks for your help
Christian



Am 16.09.2015 um 07:48 schrieb Jayaprakash Arthanareeswaran:

Hello Christian,

The code that is responsible for parsing source files and producing Javadoc in HTML format resides in org.eclipse.jdt.ui bundle. But this is a UI feature and heavily depends on other Eclipse UI components. There are some thoughts to isolate the non UI code, but then that's all just thoughts as of now.



Back to the top