使用Javaparser访问Javadoc返回null [英] Accessing Javadoc with Javaparser returns null

查看:159
本文介绍了使用Javaparser访问Javadoc返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Javaparser (javaparser-core 2.0.0)解析Java源文件。 从方法中获取Javadoc注释。

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

但是,当我调用 MethodDeclaration.getJavaDoc()时,总是得到 null code>。查看 MethodDeclaration 的来源,我可以看到原因:

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;
}

(看来Javadoc可从获得) Node.getComment()代替)

我的问题是:为什么无法使用Javadoc方法MethodDeclaration.getJavaDoc()

推荐答案

答案是:因为我们添加了DocumentableNode接口,但后来我们没有正确实施。当前,所有节点都可以附加注释,但是我们想添加一个接口以区分可能具有适当JavaDoc注释的节点(从技术上讲,您可以将Javadoc注释添加到局部变量,但不应添加)。请注意,针对此问题的票证已经打开 https://github.com/javaparser/javaparser/issues / 141

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

免责声明:我是JavaParser贡献者

Disclaimer: I am a JavaParser contributor

这篇关于使用Javaparser访问Javadoc返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆