Skip to content

Commit

Permalink
Issue checkstyle#9437: update AnnotationLocationCheckTest to use uniq…
Browse files Browse the repository at this point in the history
…ue Input file in each test method
  • Loading branch information
SGanguly1999 committed Mar 25, 2021
1 parent 3ffef52 commit ad0f5d6
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 60 deletions.
Expand Up @@ -91,32 +91,32 @@ public void testIncorrectAllTokens() throws Exception {
+ "CTOR_DEF, VARIABLE_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, "
+ "ENUM_CONSTANT_DEF, PACKAGE_DEF");
final String[] expected = {
"6:16: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnn"),
"11:20: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"14:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"17:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
"25:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
"29:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"29:27: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation2"),
"32:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
"36:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 8, 4),
"37:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation3", 6, 4),
"38:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation4", 10, 4),
"41:24: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"45:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"48:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 12, 8),
"56:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"61:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
"65:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
"70:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
"73:24: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"75:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"85:12: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 11, 8),
"88:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 10, 8),
"91:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
"98:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 0, 3),
"8:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnn3"),
"13:15: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"16:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"19:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_13", 8, 4),
"27:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_13", 8, 4),
"31:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"31:29: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnn_23"),
"34:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 7, 4),
"38:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 8, 4),
"39:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_33", 6, 4),
"40:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_43", 10, 4),
"43:19: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"47:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"50:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_13", 12, 8),
"58:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"63:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 12, 8),
"67:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 12, 8),
"72:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 7, 4),
"75:19: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"77:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"87:12: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 11, 8),
"90:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 10, 8),
"93:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation_13"),
"100:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_23", 0, 3),
};
verify(checkConfig, getPath("InputAnnotationLocationIncorrect.java"), expected);
verify(checkConfig, getPath("InputAnnotationLocationIncorrect3.java"), expected);
}

@Test
Expand Down Expand Up @@ -154,21 +154,21 @@ public void testWithParameters() throws Exception {
checkConfig.addAttribute("allowSamelineParameterizedAnnotation", "true");
checkConfig.addAttribute("allowSamelineMultipleAnnotations", "true");
final String[] expected = {
"17:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
"25:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
"32:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
"36:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 8, 4),
"37:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation3", 6, 4),
"38:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation4", 10, 4),
"48:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 12, 8),
"61:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
"65:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
"70:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
"85:12: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 11, 8),
"88:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 10, 8),
"98:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 0, 3),
"20:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_12", 8, 4),
"28:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_12", 8, 4),
"35:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 7, 4),
"39:9: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 8, 4),
"40:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_32", 6, 4),
"41:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_42", 10, 4),
"51:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation_12", 12, 8),
"64:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 12, 8),
"68:13: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 12, 8),
"73:8: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 7, 4),
"88:12: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 11, 8),
"91:11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 10, 8),
"101:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnn_22", 0, 3),
};
verify(checkConfig, getPath("InputAnnotationLocationIncorrect.java"), expected);
verify(checkConfig, getPath("InputAnnotationLocationIncorrect2.java"), expected);
}

@Test
Expand Down
Expand Up @@ -3,76 +3,76 @@



@MyAnnotation2 @com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation.MyAnn //warn
@MyAnnotation2 @com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation.MyAnn
(value = "")
class InputAnnotationLocationIncorrect
{

@MyAnnotation2 @MyAnnotation1(value = "")
public int a;

@MyAnnotation1(value = "") public int b; //warn
@MyAnnotation1(value = "") public int b;

@MyAnnotation2
@MyAnnotation1 //warn
@MyAnnotation1
(value = "")
public int c;

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

@MyAnnotation2
@MyAnnotation1 //warn
@MyAnnotation1
(value = "")
public InputAnnotationLocationIncorrect() {}

@MyAnnotation1("foo") @MyAnnotation2 void foo1() {} //warn
@MyAnnotation1("foo") @MyAnnotation2 void foo1() {}

@MyAnnotation1(value = "")
@MyAnnotation2 //warn
@MyAnnotation2
void foo2() {}

@MyAnnotation1(value = "")
@MyAnnotation2 //warn
@MyAnnotation3 //warn
@MyAnnotation4 //warn
@MyAnnotation2
@MyAnnotation3
@MyAnnotation4
class InnerClass
{
@MyAnnotation2 @MyAnnotation1 //warn
@MyAnnotation2 @MyAnnotation1
(value = "")
public int a;

@MyAnnotation1(value = "") public int b; //warn
@MyAnnotation1(value = "") public int b;

@MyAnnotation2
@MyAnnotation1 //warn
@MyAnnotation1
(value = "")
public int c;

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

@MyAnnotation2
@MyAnnotation1(value = "") public InnerClass() //warn
@MyAnnotation1(value = "") public InnerClass()
{
// comment
}
@MyAnnotation1(value = "")
@MyAnnotation2 //warn
@MyAnnotation2
void foo1() {}

@MyAnnotation1(value = "")
@MyAnnotation2 //warn
@MyAnnotation2
void foo2() {}
}

@MyAnnotation1(value = "")
@MyAnnotation2 //warn
@MyAnnotation2
InnerClass anon = new InnerClass()
{
@MyAnnotation2 @MyAnnotation1(value = "") public int a;

@MyAnnotation1(value = "") public int b; //warn
@MyAnnotation1(value = "") public int b;

@MyAnnotation2
@MyAnnotation1(value = "")
Expand All @@ -82,18 +82,18 @@ void foo2() {}
public int d;

@MyAnnotation1(value = "")
@MyAnnotation2 void foo1() {} //warn
@MyAnnotation2 void foo1() {}

@MyAnnotation1(value = "")
@MyAnnotation2 //warn
@MyAnnotation2
void foo2() {}

@MyAnnotation1(value = "") void foo42() {} //warn
@MyAnnotation1(value = "") void foo42() {}
};

}

@MyAnnotation1 //warn
@MyAnnotation1
(value = "")
@MyAnnotation2
class Foo {
Expand Down
@@ -0,0 +1,124 @@
package com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation;

/* Config:
* allowSamelineSingleParameterlessAnnotation = true
* allowSamelineParameterizedAnnotation = true
* allowSamelineMultipleAnnotations = true
*/

@MyAnn_22 @com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation.MyAnn_2 // ok
(value = "")
class InputAnnotationLocationIncorrect2
{

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

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

@MyAnn_22 // ok
@MyAnnotation_12 // violation
(value = "")
public int c;

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

@MyAnn_22 // ok
@MyAnnotation_12 // violation
(value = "")
public InputAnnotationLocationIncorrect2() {}

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

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
void foo2() {}

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
@MyAnnotation_32 // violation
@MyAnnotation_42 // violation
class InnerClass
{
@MyAnn_22 @MyAnnotation_12 // ok
(value = "")
public int a;

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

@MyAnn_22 // ok
@MyAnnotation_12 // violation
(value = "")
public int c;

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

@MyAnn_22 // ok
@MyAnnotation_12(value = "") public InnerClass() // ok
{
// comment
}
@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
void foo1() {}

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
void foo2() {}
}

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
InnerClass anon = new InnerClass()
{
@MyAnn_22 @MyAnnotation_12(value = "") public int a; // ok

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

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

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

@MyAnnotation_12(value = "") // ok
@MyAnn_22 void foo1() {} // violation

@MyAnnotation_12(value = "") // ok
@MyAnn_22 // violation
void foo2() {}

@MyAnnotation_12(value = "") void foo42() {} // ok
};

}

@MyAnnotation_12 // ok
(value = "")
@MyAnn_22 // violation
class Foo2 {
public void method1(@MyAnnotation_32 @MyAnn_22 Object param1) { // ok
try {
}
catch (@MyAnnotation_32 @MyAnn_22 Exception e) { // ok
}
return;
}
}

@interface MyAnnotation_12 {

String value();}

@interface MyAnn_22 {}

@interface MyAnnotation_32 {}

@interface MyAnnotation_42 {}

@interface MyAnn_2 {

String value();}

0 comments on commit ad0f5d6

Please sign in to comment.