自定义PMD规则 - 检查包装评论到位 [英] Custom PMD Rule - Check Package Comment In Place

查看:154
本文介绍了自定义PMD规则 - 检查包装评论到位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写规则来强制包中包含带有特定表达式的Javadoc注释,例如:

I'm trying to write a rule to enforce that a package contains a Javadoc comment with a particular expression, e.g:

/**
 * Example Expression
 */

有谁知道如何我会使用 AbstractJavaRule 类编写这样的规则。我看过ASTPackageDeclaration,但这似乎没有我想要的。

Does anybody know how I would write such a rule using the AbstractJavaRule class. I've looked at ASTPackageDeclaration, but this doesn't appear to have what I want.

非常感谢提前......

Many thanks in advance...

推荐答案

PMD使用JavaCC将每个java文件解析为抽象语法树。通常,用于编译的解析器只会删除注释,以及我可以在如何编写规则中收集的内容页面,PMD也放弃了AST的评论。

PMD uses JavaCC to parse each java file into an Abstract Syntax Tree. 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论坛,它确实看起来像注释保留为SPECIAL_TOKEN ,但很难将它们与它们关联的AST节点对齐。所以你可能很难写这条规则。你有没有看过 Checkstyle ?它有一个 RegexpHeader规则,可以做你想要的。

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. So you may have a hard time writing this rule. Have you looked at Checkstyle instead? It has a RegexpHeader rule that may do what you want.

这篇关于自定义PMD规则 - 检查包装评论到位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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