Skip to content

Give more clarity on xdocs for AnnotationLocation #13796

@relentless-pursuit

Description

@relentless-pursuit

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"/>.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions