如何创建CheckStyle检查以验证注释字段

时间:2013-04-15 23:07:00

标签: checkstyle

@WebService(serviceName="TestImpl",
targetNamespace = "http://example.org"
)
public class TestImpl implements Test{

如果我的Test类与上面类似,我的检查应验证targetNamespace值是否始终以“http://”开头

如果现有的检查无法解决,我的自定义检查应该如何?

1 个答案:

答案 0 :(得分:0)

您可以使用Checkstyle开箱即可,方法是执行RegexpMultiline检查,如下所示:

<module name="RegexpMultiline">
    <property name="format"
        value="(?s)@WebService\s*\(.*?targetNamespace\s*=\s*&quot;(?!http:\/\/).{7}"/>
    <property name="message"
        value="Target namespace must start with &quot;http://&quot;"/>
</module>

这是一个explanation of the regex

相关问题