Skip to content

Commit

Permalink
Issue checkstyle#11214: specified violation message for AnnotationUse…
Browse files Browse the repository at this point in the history
…StyleCheck
  • Loading branch information
ThatSneakyCoder authored and romani committed Oct 8, 2022
1 parent 49a93e4 commit fa68569
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public final class InlineConfigParser {
"com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck",
"com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck",
"com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck",
"com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck",
"com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck",
"com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck",
"com.puppycrawl.tools.checkstyle.checks.coding.PackageDeclarationCheck",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ public void testDefault() throws Exception {
final String[] expected = {
"13:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"14:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"20:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"22:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"28:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"21:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"23:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"29:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"33:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"39:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"42:5: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"50:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"52:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"56:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"84:32: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"86:40: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"30:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"35:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"42:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"45:5: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"53:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"55:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"59:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"88:32: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"91:40: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
};

verifyWithInlineConfigParser(
Expand All @@ -134,9 +134,9 @@ public void testParensAlways() throws Exception {
"27:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"32:5: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"80:32: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"82:40: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"90:9: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"90:31: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"83:40: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"91:9: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
"91:31: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_MISSING),
};

verifyWithInlineConfigParser(
Expand All @@ -150,10 +150,10 @@ public void testParensAlways() throws Exception {
public void testParensNever() throws Exception {
final String[] expected = {
"22:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"39:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"42:5: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"84:32: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"86:40: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"40:1: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"43:5: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"86:32: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
"89:40: " + getCheckMessage(MSG_KEY_ANNOTATION_PARENS_PRESENT),
};

verifyWithInlineConfigParser(
Expand Down Expand Up @@ -185,8 +185,8 @@ public void testStyleCompact() throws Exception {
"52:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
"56:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
"76:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
"82:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
"86:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
"83:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
"88:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT"),
};

verifyWithInlineConfigParser(
Expand All @@ -198,13 +198,13 @@ public void testStyleCompactNoArray() throws Exception {
final String[] expected = {
"13:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"14:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"20:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"28:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"21:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"29:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"33:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"50:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"30:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"35:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"52:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"56:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"54:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"58:1: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
};

verifyWithInlineConfigParser(
Expand All @@ -216,17 +216,17 @@ public void testCommaAlwaysViolations() throws Exception {
final String[] expected = {
"12:20: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"15:30: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"19:40: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"22:44: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"25:54: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"33:22: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"33:36: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"35:21: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"35:30: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"38:39: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"38:49: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"41:21: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"41:41: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"20:40: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"24:45: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"28:55: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"36:22: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"36:36: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"38:21: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"38:30: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"41:39: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"41:49: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"44:21: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
"44:41: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING),
};

verifyWithInlineConfigParser(
Expand Down Expand Up @@ -264,9 +264,9 @@ public void testCommaAlwaysNoViolationsNonCompilable() throws Exception {
public void testTrailingArrayIgnore() throws Exception {
final String[] expected = {
"15:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"22:13: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"33:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"39:9: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"23:13: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"35:5: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
"42:9: " + getCheckMessage(MSG_KEY_ANNOTATION_INCORRECT_STYLE, "COMPACT_NO_ARRAY"),
};

verifyWithInlineConfigParser(
Expand All @@ -276,14 +276,14 @@ public void testTrailingArrayIgnore() throws Exception {
@Test
public void testCommaNeverViolations() throws Exception {
final String[] expected = {
"15:32: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"19:42: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"22:46: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"25:56: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"33:24: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"33:39: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"39:41: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"39:52: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"16:32: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"21:42: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"25:46: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"29:56: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"37:24: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"37:39: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"43:41: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
"43:52: " + getCheckMessage(MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT),
};

verifyWithInlineConfigParser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ enum DOGS5 {
String[] um() default {};
@Another({""}) //compact
String[] duh() default {};
@Another(value={""}) //expanded // violation
@Another(value={""}) //expanded // violation 'Annotation style must be 'COMPACT''
DOGS[] pooches();
}

@Another(value={""}) //expanded // violation
@Another(value={""}) //expanded // violation 'Annotation style must be 'COMPACT''
enum E5 {

}
Expand All @@ -73,17 +73,19 @@ enum E5 {
class Closing5 {
static final String UN_U = "UN_U";

@SuppressWarnings(value = UN_U) // violation
@SuppressWarnings(value = UN_U) // violation 'Annotation style must be 'COMPACT''
int d;
}

@AnnotationWithAnnotationValue(@Another)
class Example17 {}
@AnnotationWithAnnotationValue(value = @Another) // violation
// violation below 'Annotation style must be 'COMPACT''
@AnnotationWithAnnotationValue(value = @Another)
class Example18 {}
@AnnotationWithAnnotationValue(@Another())
class Example19 {}
@AnnotationWithAnnotationValue(value = @Another()) // violation
// violation below 'Annotation style must be 'COMPACT''
@AnnotationWithAnnotationValue(value = @Another())
class Example20 {}

class Foo5 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.annotationusestyle;

@Deprecated
@SomeArrays(pooches={DOGS.LEO}) // violation
@SuppressWarnings({""}) // violation
@SomeArrays(pooches={DOGS.LEO}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
@SuppressWarnings({""}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
public class InputAnnotationUseStyleCompactNoArray
{

}

@SomeArrays(pooches={DOGS.LEO}, um={}, duh={"bleh"}) // violation
// violation below 'Annotation style must be 'COMPACT_NO_ARRAY''
@SomeArrays(pooches={DOGS.LEO},um={}, duh={"bleh"})
@SuppressWarnings("") //compact_no_array
@Deprecated()
class Dep6 {

}

@Deprecated
@SomeArrays(pooches={DOGS.LEO}) // violation
@SuppressWarnings({""}) // violation
@SomeArrays(pooches={DOGS.LEO}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
@SuppressWarnings({""}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
enum SON6 {

@Deprecated
@SomeArrays(pooches={DOGS.LEO}, um={""}, duh={"bleh"}) // violation
// violation below 'Annotation style must be 'COMPACT_NO_ARRAY''
@SomeArrays(pooches={DOGS.LEO},um={""}, duh={"bleh"})
@APooch(dog=DOGS.HERBIE)
@Another("") //compact_no_array
ETHAN
Expand All @@ -47,13 +49,13 @@ enum DOGS6 {
@interface SomeArrays6 {
@Another("") //compact
String[] um() default {};
@Another({""}) //compact // violation
@Another({""}) //compact // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
String[] duh() default {};
@Another(value={""}) //expanded // violation
@Another(value={""}) //expanded // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
DOGS[] pooches();
}

@Another(value={""}) //expanded // violation
@Another(value={""}) //expanded // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
enum E6 {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,53 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.annotationusestyle;

@Deprecated
@SomeArrays(pooches={DOGS.LEO}) // violation
@SuppressWarnings({""}) // violation
@SomeArrays(pooches={DOGS.LEO}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
@SuppressWarnings({""}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
public class InputAnnotationUseStyleDifferentStyles
{

}

@SomeArrays(pooches={DOGS.LEO}, um={}, duh={"bleh"}) // violation
// violation below 'Annotation style must be 'COMPACT_NO_ARRAY''
@SomeArrays(pooches={DOGS.LEO},um={}, duh={"bleh"})
@SuppressWarnings("") //compact_no_array
@Deprecated() // violation
@Deprecated() // violation 'Annotation cannot have closing parenthesis'
class Dep {

}

@Deprecated
@SomeArrays(pooches={DOGS.LEO}) // violation
@SuppressWarnings({""}) // violation
@SomeArrays(pooches={DOGS.LEO}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY'
@SuppressWarnings({""}) // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
enum SON {

@Deprecated
@SomeArrays(pooches={DOGS.LEO}, um={""}, duh={"bleh"}) // violation
// violation below 'Annotation style must be 'COMPACT_NO_ARRAY''
@SomeArrays(pooches={DOGS.LEO},um={""}, duh={"bleh"})
@APooch(dog=DOGS.HERBIE)
@Another("") //compact_no_array
ETHAN
}

@InputAnnotationUseStyleCustomAnnotation3() // violation
// violation below 'Annotation cannot have closing parenthesis'
@InputAnnotationUseStyleCustomAnnotation3()
enum DOGS {

@Deprecated() // violation
@Deprecated() // violation 'Annotation cannot have closing parenthesis'
LEO,
HERBIE
}

@interface SomeArrays {
@Another("") //compact
String[] um() default {};
@Another({""}) //compact // violation
@Another({""}) //compact // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
String[] duh() default {};
@Another(value={""}) //expanded // violation
@Another(value={""}) //expanded // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
DOGS[] pooches();
}

@Another(value={""}) //expanded // violation
@Another(value={""}) //expanded // violation 'Annotation style must be 'COMPACT_NO_ARRAY''
enum E {

}
Expand Down Expand Up @@ -81,9 +84,11 @@ class Closing {
class Example1 {}
@AnnotationWithAnnotationValue(value = @Another)
class Example2 {}
@AnnotationWithAnnotationValue(@Another()) // violation
// violation below 'Annotation cannot have closing parenthesis'
@AnnotationWithAnnotationValue(@Another())
class Example3 {}
@AnnotationWithAnnotationValue(value = @Another()) // violation
// violation below 'Annotation cannot have closing parenthesis'
@AnnotationWithAnnotationValue(value = @Another())
class Example4 {}

class Foo {
Expand Down

0 comments on commit fa68569

Please sign in to comment.