如何将注释的目标限制为 'ElementType.TYPE_USE',
How can I limit an annotation 's target only to be 'ElementType.TYPE_USE',
如何将注释的目标限制为 'ElementType.TYPE_USE',任何其他用途都会被 'maven checkstyle' 插件拒绝
我只能想到RegexpMultiline, if you want to do it with Checkstyle. You might configure it like so (regex):
<module name="RegexpMultiline">
<property name="format" value="\bElementType\s*\.\s*(?!TYPE_USE)\w+\b"/>
<property name="message" value="Illegal ElementType. Only TYPE_USE is permitted."/>
<property name="fileExtensions" value="java"/>
</module>
这个解决方案还不够完美,因为它也会触发评论,而且不限于注释。如果您需要更多控制权,请写一个 custom check。
如何将注释的目标限制为 'ElementType.TYPE_USE',任何其他用途都会被 'maven checkstyle' 插件拒绝
我只能想到RegexpMultiline, if you want to do it with Checkstyle. You might configure it like so (regex):
<module name="RegexpMultiline">
<property name="format" value="\bElementType\s*\.\s*(?!TYPE_USE)\w+\b"/>
<property name="message" value="Illegal ElementType. Only TYPE_USE is permitted."/>
<property name="fileExtensions" value="java"/>
</module>
这个解决方案还不够完美,因为它也会触发评论,而且不限于注释。如果您需要更多控制权,请写一个 custom check。