How can I get all Javadoc comments in a project

I want to get all of the javadocs in a project, either as Strings or as PSI elements. Is there a quick way to do this?

0
4 comments
Avatar
Permanently deleted user

No. 

Maybe, the quickest way would be to find all "/**" substrings in all files and then try to get the PSI from these positions.

0
Avatar
Permanently deleted user

Is there a way to work backwards from methods possibly? I know that there is a stub index for public methods. Can I use this to get the javadoc for that stub?

0
Avatar
Permanently deleted user

If you are looking for Javadoc comments in Java code, then you can iterate over all of the source files looking for PsiDocComment elements.  Then element.getText() should get you the entire comment.  Just remember that all PsiDocComment elements are a tree themselves for several types of tokens that are parsed by IDEA.

If you want only the ones defined immediately before methods and/or classes, then once you obtain the appropriate element (from the index), look for a `PsiDocComment` element as an immediate child of the returned element.

0
Avatar
Permanently deleted user

@dgfried Yes, you can. (e.g. iterate all files in your project, find PsiFIle for the corresponding VirtualFile and query its PsiDocComments. Or process all methods from stub index). However, as I said, it may be unnecessarily slow because you would have to construct PSI for all members, even if they don't own javadoc. To text-search files for javadoc comment and then get the PSI for them only, seem to be a bit faster. But YMMV of course.

0

Please sign in to leave a comment.