简体   繁体   English

自定义PMD规则-检查包注释到位

[英]Custom PMD Rule - Check Package Comment In Place

I'm trying to write a rule to enforce that a package contains a Javadoc comment with a particular expression, eg: 我正在尝试编写一条规则,以强制程序包包含带有特定表达式的Javadoc注释,例如:

/**
 * Example Expression
 */

Does anybody know how I would write such a rule using the AbstractJavaRule class. 有人知道我将如何使用AbstractJavaRule类编写这样的规则。 I've looked at ASTPackageDeclaration, but this doesn't appear to have what I want. 我看过ASTPackageDeclaration,但这似乎没有我想要的。

Many thanks in advance... 提前谢谢了...

PMD uses JavaCC to parse each java file into an Abstract Syntax Tree. PMD使用JavaCC将每个Java文件解析为抽象语法树。 Typically parsers used for compilation just drop comments, and from what I can gather on the "How to write a rule" page, PMD is also dropping comments from the AST. 通常,用于编译的解析器只会删除注释,而根据我在“如何编写规则”页面上的了解,PMD也会从AST删除注释。

But looking at the PMD forum, it does look like comments are preserved as a SPECIAL_TOKEN , but it is difficult to align them with the AST node they are associated with. 但是在PMD论坛上,看起来确实将注释保留为SPECIAL_TOKEN ,但是很难将其与它们关联的AST节点对齐。 So you may have a hard time writing this rule. 因此,您可能很难编写此规则。 Have you looked at Checkstyle instead? 您是否看过Checkstyle It has a RegexpHeader rule that may do what you want. 它具有RegexpHeader规则可以满足您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM