如何在方法注释后强制换行,其余部分与 checkstyle 在一行中强制执行?

How to enforce line break after method annotation and the rest in one line with checkstyle?

哪个 checkstyle 规则可以强制执行

@Test public void
matchesEmptyElement() {

无效且仅

@Test
public void matchesEmptyElement() {

有效,即注释(如果有)访问修饰符(如果有)之间的换行符而不是访问修饰符和左括号之间的换行符?

AnnotationLocation 是您要查找的支票:

<module name="AnnotationLocation">
  <property name="allowSamelineMultipleAnnotations" value="false"/>
  <property name="allowSamelineSingleParameterlessAnnotation" value="false"/>
  <property name="allowSamelineParameterizedAnnotation" value="false"/>
</module>

或者,由于 false 是所有这些属性的默认值,您可以降低一些稳健性:

<module name="AnnotationLocation" />