我正在尝试使用正则表达式创建一个 checkstyle 模块,用于检查 javax.ws.rs.Path 注释是否以斜杠开头。
在我的 checkstyle.xml 文件中我定义了
<module name="Regex">
<property name="format" value="/api" />
<property name="message" value="Missing /" />
</module>
我希望它检查的是我是否有如下资源类
@Path("/api/v1/persons")
public class PersonResource {
...
}
那么它将通过检查,没有任何问题,另一方面,如果我的类如下所示
@Path("api/v1/persons")
public class PersonResource {
...
}
请注意,第一个 /
丢失,那么它应该从我的 checkstyle 中收到错误/警告。
现在这可以通过 checkstyle 实现吗?还是我必须自己编写 check .
我似乎在 Annotations 中找不到任何内容这样就可以了。
最佳答案
没有标准的支票可以满足您的需求,但有非标准的支票和 http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationElementValueCheck.html应该能够强制执行正确的值,您只需要制作正确的正则表达式即可。项目页面https://github.com/sevntu-checkstyle/sevntu.checkstyle 。如果您在使用自定义检查时遇到问题,可以将此检查移至标准库,但这需要您的帮助才能完成。
关于java - 让checkstyle检查javax路径注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52591813/