Pluggable Annotation Processor API 可以检索源代码注释吗? [英] Can the Pluggable Annotation Processor API retrieve source code comments?

查看:28
本文介绍了Pluggable Annotation Processor API 可以检索源代码注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 Java6+ 的可插入注释处理 api 来自动创建一些部署 XML 文件.这些 XML 文件的一部分包含对象的描述.描述始终与与类本身相关联的 Javadoc 的内容相同.我可以强制注释成为@Block 注释的一个字段,但这会重复信息.在注解处理过程中,有没有办法获取类/类型注释的内容?

I am using the pluggable annotation processing api withing Java6+ to automatically create some deployment XML files. Part of these XML files contains a description of the object. The description is ALWAYS the same content as the Javadoc associated with the class itself. I could force the comment to be a field of the @Block annotation, but that duplicates the information. Is there any way during annotation processing to get the contents of the class/type comment?

在这个例子中,我想在注释处理过程中得到我的块的一个很好的描述".

In this example, I want to get "A nice description of my block" during annotation processing.

/**
* A nice description of my block
**/
@Block
public class CustomBlock {
}

推荐答案

我似乎总是在发布 SO 后立即找到答案.

I seem to always find the answer right after I post on SO.

为了将来参考,这里是解决方案

For future reference, here is the solution

public class CustomAnnotationProcessor extends AbstractAnnotationProcessor
{
    public boolean process(...)
    {

        // use the protected member, processingEnv

        String comment = processingEnv.getElementUtils().getDocComment(anyElement);


    }
}

这篇关于Pluggable Annotation Processor API 可以检索源代码注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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