Skip to content

Commit

Permalink
Issue #11214: Specify violation messages for AnnotationLocationCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyanK7 authored and romani committed Jun 28, 2022
1 parent 6581570 commit 5feecdb
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public final class InlineConfigParser {
"com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheck",
"com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck",
"com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck",
"com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationLocationCheck",
"com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck",
"com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck"));

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ public class InputAnnotationLocationRecordsAndCompactCtors {
@NonNull1 public record MyRecord1() { // ok, no param
}

@SuppressWarnings("deprecation") public record MyRecord2() { // violation
// violation below 'Annotation 'SuppressWarnings' should be alone on line.'
@SuppressWarnings("deprecation") public record MyRecord2() {
}

@SuppressWarnings("deprecation") record MyRecord3() { // violation
// violation below 'Annotation 'SuppressWarnings' should be alone on line.'
@SuppressWarnings("deprecation") record MyRecord3() {
}

@SuppressWarnings("deprecation") public record MyRecord4() { // violation
@SuppressWarnings("deprecation")public MyRecord4{} // violation
// violation below 'Annotation 'SuppressWarnings' should be alone on line.'
@SuppressWarnings("deprecation") public record MyRecord4() {
// violation below 'Annotation 'SuppressWarnings' should be alone on line.'
@SuppressWarnings("deprecation")public MyRecord4{}
}

@SuppressWarnings("deprecation")
public record MyRecord5() {
record MyInnerRecord(){
@SuppressWarnings("Annotation")public MyInnerRecord{} // violation
// violation below 'Annotation 'SuppressWarnings' should be alone on line.'
@SuppressWarnings("Annotation")public MyInnerRecord{}
}
}

Expand All @@ -40,7 +45,8 @@ record MyInnerRecord(){
@SuppressWarnings("deprecation") // ok
public record MyRecord6() {
record MyInnerRecord () {
@SuppressWarnings("Annotation")public MyInnerRecord { // violation
// violation below 'Annotation 'SuppressWarnings' should be alone on line.'
@SuppressWarnings("Annotation")public MyInnerRecord {
}
}
}
Expand All @@ -51,7 +57,7 @@ record MyInnerRecord () {
*/
public record MyRecord7() {
record MyInnerRecord () {@SuppressWarnings("Annotation")public MyInnerRecord {
} // violation above
} // violation above 'Annotation 'SuppressWarnings' should be alone on line.'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import java.lang.annotation.Target;

@AnnotationAnnotation(value = "foo")
@AnnotationAnnotation // violation
@AnnotationAnnotation("bar") @interface InputAnnotationLocationAnnotation { // violation
@AnnotationAnnotation // violation '.* incorrect .* level 2, .* should be 0.'
// violation below 'Annotation 'AnnotationAnnotation' should be alone on line.'
@AnnotationAnnotation("bar") @interface InputAnnotationLocationAnnotation {

@AnnotationAnnotation(value = "foo")
@AnnotationAnnotation // violation
@AnnotationAnnotation("bar") String value(); // violation
@AnnotationAnnotation // violation '.* incorrect .* level 6, .* should be 4.'
@AnnotationAnnotation("bar") String value(); // violation '.* should be alone on line.'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
import java.lang.annotation.Target;

@ClassAnnotation(value = "foo")
@ClassAnnotation // violation
@ClassAnnotation("bar") class InputAnnotationLocationClass { // violation
@ClassAnnotation // violation '.* incorrect .* level 2, .* should be 0.'
// violation below 'Annotation 'ClassAnnotation' should be alone on line.'
@ClassAnnotation("bar") class InputAnnotationLocationClass {

@ClassAnnotation(value = "foo")
@ClassAnnotation // violation
@ClassAnnotation("bar") Object field; // violation
@ClassAnnotation // violation '.* incorrect .* level 6, .* should be 4.'
@ClassAnnotation("bar") Object field; // violation '.* should be alone on line.'

@ClassAnnotation(value = "foo")
@ClassAnnotation // violation
@ClassAnnotation("bar") InputAnnotationLocationClass() { // violation
@ClassAnnotation // violation '.* incorrect .* level 6, .* should be 4.'
// violation below 'Annotation 'ClassAnnotation' should be alone on line.'
@ClassAnnotation("bar") InputAnnotationLocationClass() {
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import java.lang.annotation.Target;

@EnumAnnotation(value = "foo")
@EnumAnnotation // violation
@EnumAnnotation("bar") enum InputAnnotationLocationEnum { // violation
@EnumAnnotation // violation '.* incorrect .* level 2, .* should be 0.'
@EnumAnnotation("bar") enum InputAnnotationLocationEnum { // violation '.* should be alone on line.'

@EnumAnnotation(value = "foo")
@EnumAnnotation // violation
@EnumAnnotation("bar") ENUM_VALUE(); // violation
@EnumAnnotation // violation '.* incorrect .* level 6, .* should be 4.'
@EnumAnnotation("bar") ENUM_VALUE(); // violation '.* should be alone on line.'

InputAnnotationLocationEnum() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,77 @@

package com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation;

@MyAnn_21 @com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation.MyAnn // violation
// violation below 'Annotation 'MyAnn' should be alone on line.'
@MyAnn_21 @com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation.MyAnn
(value = "")
class InputAnnotationLocationIncorrect
{

@MyAnn_21 @MyAnnotation1(value = "") // violation
@MyAnn_21 @MyAnnotation1(value = "") // violation '.* should be alone on line.'
public int a;

@MyAnnotation1(value = "") public int b; // violation
@MyAnnotation1(value = "") public int b; // violation '.* should be alone on line.'

@MyAnn_21 // ok
@MyAnnotation1 // violation
@MyAnnotation1 // violation '.* incorrect .* level 8, .* should be 4.'
(value = "")
public int c;

@MyAnnotation1(value = "") // ok
public int d;

@MyAnn_21 // ok
@MyAnnotation1 // violation
@MyAnnotation1 // violation '.* incorrect .* level 8, .* should be 4.'
(value = "")
public InputAnnotationLocationIncorrect() {}

@MyAnnotation1("foo") @MyAnn_21 void foo1() {} // 2 violations

@MyAnnotation1(value = "") // ok
@MyAnn_21 // violation
@MyAnn_21 // violation '.* incorrect .* level 7, .* should be 4.'
void foo2() {}

@MyAnnotation1(value = "") // ok
@MyAnn_21 // violation
@MyAnnotation3 // violation
@MyAnnotation4 // violation
@MyAnn_21 // violation '.* incorrect .* level 8, .* should be 4.'
@MyAnnotation3 // violation '.* incorrect .* level 6, .* should be 4.'
@MyAnnotation4 // violation '.* incorrect .* level 10, .* should be 4.'
class InnerClass
{
@MyAnn_21 @MyAnnotation1 // violation
@MyAnn_21 @MyAnnotation1 // violation 'Annotation 'MyAnnotation1' should be alone on line.'
(value = "")
public int a;

@MyAnnotation1(value = "") public int b; // violation
@MyAnnotation1(value = "") public int b; // violation '.* should be alone on line.'

@MyAnn_21 // ok
@MyAnnotation1 // violation
@MyAnnotation1 // violation '.* incorrect .* level 12, .* should be 8.'
(value = "")
public int c;

@MyAnnotation1(value = "") // ok
public int d;

@MyAnn_21 // ok
@MyAnnotation1(value = "") public InnerClass() // violation
@MyAnnotation1(value = "") public InnerClass() // violation '.* should be alone on line.'
{
// comment
}
@MyAnnotation1(value = "")
@MyAnn_21 // violation
@MyAnn_21 // violation '.* incorrect .* level 12, .* should be 8.'
void foo1() {}

@MyAnnotation1(value = "")
@MyAnn_21 // violation
@MyAnn_21 // violation '.* incorrect .* level 12, .* should be 8.'
void foo2() {}
}

@MyAnnotation1(value = "")
@MyAnn_21 // violation
@MyAnn_21 // violation '.* incorrect .* level 7, .* should be 4.'
InnerClass anon = new InnerClass()
{
@MyAnn_21 @MyAnnotation1(value = "") public int a; // violation
@MyAnn_21 @MyAnnotation1(value = "") public int a; // violation '.*should be alone on line.'

@MyAnnotation1(value = "") public int b; // violation
@MyAnnotation1(value = "") public int b; // violation '.* should be alone on line.'

@MyAnn_21 // ok
@MyAnnotation1(value = "") // ok
Expand All @@ -90,20 +91,19 @@ void foo2() {}
public int d;

@MyAnnotation1(value = "") // ok
@MyAnn_21 void foo1() {} // violation
@MyAnn_21 void foo1() {} // violation '.* incorrect .* level 11, .* should be 8.'

@MyAnnotation1(value = "") // ok
@MyAnn_21 // violation
@MyAnn_21 // violation '.* incorrect .* level 10, .* should be 8.'
void foo2() {}

@MyAnnotation1(value = "") void foo42() {} // violation
@MyAnnotation1(value = "") void foo42() {} // violation '.* should be alone on line.'
};

}

@MyAnnotation1 // ok
(value = "")
@MyAnn_21 // violation
@MyAnn_21 // violation '.* incorrect .* level 0, .* should be 3.'
class Foo {
public void method1(@MyAnnotation3 @MyAnn_21 Object param1) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ class InputAnnotationLocationIncorrect2
@MyAnnotation_12(value = "") public int b; // ok

@MyAnn_22 // ok
@MyAnnotation_12 // violation
@MyAnnotation_12 // violation '.* incorrect .* level 8, .* should be 4.'
(value = "")
public int c;

@MyAnnotation_12(value = "") // ok
public int d;

@MyAnn_22 // ok
@MyAnnotation_12 // violation
@MyAnnotation_12 // violation '.* incorrect .* level 8, .* should be 4.'
(value = "")
public InputAnnotationLocationIncorrect2() {}

@MyAnnotation_12("foo") @MyAnn_22 void foo1() {} // ok

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnn_22 // violation '.*'MyAnn_22' have incorrect indentation level 7, .* should be 4.'
void foo2() {}

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnnotation_32 // violation
@MyAnnotation_42 // violation
@MyAnn_22 // violation '.* incorrect .* level 8, .* should be 4.'
@MyAnnotation_32 // violation '.* incorrect .* level 6, .* should be 4.'
@MyAnnotation_42 // violation '.* incorrect .* level 10, .* should be 4.'
class InnerClass
{
@MyAnn_22 @MyAnnotation_12 // ok
Expand All @@ -53,7 +53,7 @@ class InnerClass
@MyAnnotation_12(value = "") public int b; // ok

@MyAnn_22 // ok
@MyAnnotation_12 // violation
@MyAnnotation_12 // violation '.* incorrect .* level 12, .* should be 8.'
(value = "")
public int c;

Expand All @@ -66,16 +66,16 @@ class InnerClass
// comment
}
@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnn_22 // violation '.* incorrect .* level 12, .* should be 8.'
void foo1() {}

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnn_22 // violation '.* incorrect .* level 12, .* should be 8.'
void foo2() {}
}

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnn_22 // violation '.* incorrect .* level 7, .* should be 4.'
InnerClass anon = new InnerClass()
{
@MyAnn_22 @MyAnnotation_12(value = "") public int a; // ok
Expand All @@ -90,10 +90,10 @@ void foo2() {}
public int d;

@MyAnnotation_12(value = "") // ok
@MyAnn_22 void foo1() {} // violation
@MyAnn_22 void foo1() {} // violation '.* incorrect .* level 11, .* should be 8.'

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnn_22 // violation '.* incorrect .* level 10, .* should be 8.'
void foo2() {}

@MyAnnotation_12(value = "") void foo42() {} // ok
Expand All @@ -103,7 +103,7 @@ void foo2() {}

@MyAnnotation_12 // ok
(value = "")
@MyAnn_22 // violation
@MyAnn_22 // violation '.*'MyAnn_22' have incorrect indentation level 0, .* should be 3.'
class Foo2 {
public void method1(@MyAnnotation_32 @MyAnn_22 Object param1) { // ok
try {
Expand Down

0 comments on commit 5feecdb

Please sign in to comment.