Regex jcip注释的checkstyle规则

Regex jcip注释的checkstyle规则,regex,annotations,checkstyle,rule,Regex,Annotations,Checkstyle,Rule,我需要一条规则,检查字段和类是否使用java并发性实践注释进行了正确的注释,注释由以下内容提供: 字段必须用@GuardedBy注释,类必须用@Immutable、@ThreadSafe或@NotThreadSafe中的一个注释 我目前应用了一条规则,它确保用@Repository而不是@Service或@Component注释SpringDAO类 <module name="Regexp"> <property name="format" value

我需要一条规则,检查字段和类是否使用java并发性实践注释进行了正确的注释,注释由以下内容提供:

字段必须用@GuardedBy注释,类必须用@Immutable、@ThreadSafe或@NotThreadSafe中的一个注释

我目前应用了一条规则,它确保用@Repository而不是@Service或@Component注释SpringDAO类

<module name="Regexp">
    <property name="format" 
        value="(@Component|@Service)(.*[\n])*.*class.*Dao.*\{" />
    <property name="message" 
        value="Daos sollten lieber mit @Repository annotiert werden." />
    <property name="illegalPattern" value="true" />
</module>

这种方法的问题是,我只能检查一些注释,然后告诉您,最好使用另一个注释。这对jcip注释检查没有帮助,因为我无法检查“没有特定注释存在”

对于初学者来说,如果有人知道如何将上面的Dao检查转换为确保@Repository出现在以Dao结尾的类上的检查,那就太酷了。 然后可以使用该模式开发jcip注释检查

或者,与其尝试转换regexp检查,还不如用checkstyle的令牌支持实现jcip规则?这可能会使这条规则更加健全

无论如何,我想知道如何通过checkstyle确保特定元素上必须存在特定注释。希望有人知道这一点。:)

找到了解决方案:

<module name="Regexp">
    <property name="format" value="(interface [a-zA-Z0-9 &lt;&gt;,\.]* \{|(@Immutable|@ThreadSafe|@NotThreadSafe)(.*[\n])*.*(class|enum) [a-zA-Z0-9\s&lt;&gt;,\.]* \{)" />
    <property name="message" value="Types must be annotated with @Immutable, @ThreadSafe, or @NotThreadSafe." />
    <property name="illegalPattern" value="false" />
</module>

此外,检查
@GuardedBy
没有任何意义,因为它取决于类使用的同步策略。因此,并不总是需要将
@GuardedBy
添加到字段声明中。对于一个简单的checkstyle规则来说,检查需要它的情况是非常复杂的

编辑:为了保持一致性,我已将规则更新为更健壮的版本