Link: https://checkstyle.sourceforge.io/checks/annotation/annotationlocation.html
I am quoting the documentation for AnnotationLocation below to highlight the perceived inconsistency.
Use the following configuration to allow multiple annotations on the same line:
<module name="AnnotationLocation">
<property name="allowSamelineMultipleAnnotations" value="true"/>
<property name="allowSamelineSingleParameterlessAnnotation"
value="false"/>
<property name="allowSamelineParameterizedAnnotation" value="false"/>
</module>
Example to allow any location multiple annotations:
@NotNull private boolean field1; //ok
@Override public int hashCode() { return 1; } //ok
@NotNull //ok
private boolean field2;
@Override //ok
public boolean equals(Object obj) { return true; }
@Mock DataLoader loader; //ok
@SuppressWarnings("deprecation") DataLoader loader; //ok
@SuppressWarnings("deprecation") public int foo() { return 1; } //ok
@NotNull @Mock DataLoader loader; //ok
Use the following configuration to allow only one and only parameterized annotation on the same line:
<module name="AnnotationLocation">
<property name="allowSamelineMultipleAnnotations" value="false"/>
<property name="allowSamelineSingleParameterlessAnnotation"
value="false"/>
<property name="allowSamelineParameterizedAnnotation" value="true"/>
</module>
Example to allow only one and only parameterized annotation on the same line:
@NotNull private boolean field1; //violation
@Override public int hashCode() { return 1; } //violation
@NotNull //ok
private boolean field2;
@Override //ok
public boolean equals(Object obj) { return true; }
@Mock DataLoader loader; //violation
@SuppressWarnings("deprecation") DataLoader loader; //ok
@SuppressWarnings("deprecation") public int foo() { return 1; } //ok
@NotNull @Mock DataLoader loader; //violation
end of doc quote.
But, the below config line which is same for above examples mentioned, however presents inconsistent scenarios.
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>
For "Example to allow any location multiple annotations":
@Override public int hashCode() { return 1; } //ok
For "Example to allow only one and only parameterized annotation on the same line":
@Override public int hashCode() { return 1; } //violation
https://checkstyle.sourceforge.io/checks/annotation/annotationlocation.html#Example2-config shows dominant effect of
<property name="allowSamelineMultipleAnnotations" value="true"/>
over
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>.
Link: https://checkstyle.sourceforge.io/checks/annotation/annotationlocation.html
I am quoting the documentation for AnnotationLocation below to highlight the perceived inconsistency.
Use the following configuration to allow multiple annotations on the same line:
Example to allow any location multiple annotations:
Use the following configuration to allow only one and only parameterized annotation on the same line:
Example to allow only one and only parameterized annotation on the same line:
end of doc quote.
But, the below config line which is same for above examples mentioned, however presents inconsistent scenarios.
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>For "Example to allow any location multiple annotations":
@Override public int hashCode() { return 1; } //okFor "Example to allow only one and only parameterized annotation on the same line":
@Override public int hashCode() { return 1; } //violationhttps://checkstyle.sourceforge.io/checks/annotation/annotationlocation.html#Example2-config shows dominant effect of
<property name="allowSamelineMultipleAnnotations" value="true"/>over
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>.