Best way to get com.sun.source.doctree.DocTree?
Jonathan Gibbons
jonathan.gibbons at oracle.com
Wed Oct 1 00:04:21 UTC 2014
On 09/30/2014 04:06 PM, Harry Terkelsen wrote:
> Hi compiler devs,
>
> I would like to use the DocTree API for JavaDoc comments but I don't
> see any way to get a DocTree from a JavaDoc comment?
>
> Is there any way to simply parse a JavaDoc comment, given as a String,
> along with the start and end positions in the original source, and get
> back a DocTree with source positions properly set? In other words, is
> it possible to write this method:
>
> DocTree parseDocTree(String comment, int pos, int endPos);
>
> If that is not possible, I see that I can go from TreePath ->
> DocCommentTree with DocTrees#getDocCommentTree(TreePath) but I'm
> assuming this is only for JavaDoc comments that are attached to
> top-level program elements. Is this the only way to get DocTrees?
>
> Thanks!
> Harry
The only public supported method is the one you found,
DocTrees#getDocCommentTree(TreePath)
I'm not sure why you would want the method you are asking for (to parse
an arbitrary string as a comment.) It would be somewhat more
interesting to ask if there was a "comment" token that you could parse
into a DocTree, and yes, that does exist inside javac, although it is
not exposed publicly at this time. Look for DocCommentParser.
-- Jon
More information about the compiler-dev
mailing list