How get PsiMethod block comment?

Hi,

 

I have a class with some methods in them.

I now want to find the block comment for the PsiMethod I found but it gives me null when I use method.getDocComment().

What do I have to do to extract the comment from the below method? 

I found the annotation(s), name etc.

/*
* This is an example of a deprecated method
*/
@Deprecated
public boolean isDeprated() {
    return true;
}

2 comments

PsiClass.accept(new JavaRecursiveElementVisitor(){....} can help.

Override the functions for the elements you want to detect.

0

I found a snippet of code doing the below, anything wrong with that (it seems to work)?

 

PsiDocComment currentComment = null;
PsiElement firstElement = internalMethod.getFirstChild();

if ( ( firstElement != null ) && ( firstElement instanceof PsiDocComment ) ) {
currentComment = ( PsiDocComment ) firstElement;
}
0

Please sign in to leave a comment.