Accessing Javadoc with Javaparser returns null

若如初见. 提交于 2019-12-13 04:53:03

问题


I'm parsing Java source files with Javaparser (javaparser-core 2.0.0) to get Javadoc comments from methods.

However, I always get null When I call MethodDeclaration.getJavaDoc(). Looking at the source of MethodDeclaration, I can see why:

public JavadocComment getJavaDoc() {
    return null;
}

(It appears Javadoc is available from Node.getComment() instead)

My question is: Why is method Javadoc not available from MethodDeclaration.getJavaDoc()?


回答1:


The answer is: because we added the interface DocumentableNode but later we did not implemented correctly. Currently all nodes can have comments attached, however we wanted to add an interface to differentiate the nodes that could have a proper JavaDoc comment (technically you can add a Javadoc comment to a local variable but you shouldn't). Note that a ticket is already open for this issue https://github.com/javaparser/javaparser/issues/141

Disclaimer: I am a JavaParser contributor



来源:https://stackoverflow.com/questions/29563921/accessing-javadoc-with-javaparser-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!