可插入注释处理器API可以检索源$ C $ C的意见? [英] Can the Pluggable Annotation Processor API retrieve source code comments?
问题描述
我使用的是可插入注释处理API withing的Java6 +自动创建一些部署XML文件。这些XML文件的一部分,包含对象的描述。该说明是永远不变的内容与类本身相关的Javadoc。我可能会迫使评论是@Block注释字段,但复制的信息。有没有标注处理过程中的任何方式来获得类/类型的注释的内容?
在这个例子中,我想注释处理过程中得到我的块的一个很好的说明。
/ **
*我的块的一个很好的说明
** /
@块
公共类CustomBlock {
}
我似乎总能找到我张贴在SO之后的答案。
有关备查,这里是解决方案
公共类CustomAnnotationProcessor扩展AbstractAnnotationProcessor
{
公共布尔过程(...)
{ //使用受保护的成员,processingEnv 。字符串评论= processingEnv.getElementUtils()getDocComment(anyelement的);
}
}
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 {
}
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);
}
}
这篇关于可插入注释处理器API可以检索源$ C $ C的意见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!