Repository: checkstyle/checkstyle

Problem statement:
Update AbstractChecks to log DetailAST - AnnotationLocation
Child of https://github.com/checkstyle/checkstyle/issues/5777

This issue specifically focuses on AnnotationLocation .


Hints:
I am on it.
Hi @romani, 
   As per my understanding, the requirement is to overload the log function in the AnnotationLocationCheck providing AST. However, I feel like I am missing something. Could you clarify a little on what should be done?
Thanks.
@Malintha1996 All checks call a log method to report violations. They can either send a line only, a line and column, or the AST. We are in the process of changing all our `log` calls in AbstractChecks to pass the AST instead of anything else. The reason is for xpath suppressions, it needs the AST to know where the violation is in the tree to determine if it matches a suppression xpath supplied by the user. Besides making this change, all tests need to pass and regression needs to be provided for the changes.
Got it.  Thanks for the assistance.
@rnveach , Will you briefly mention the XpathRegression tests that should be added. Should I consider all possible tokens such as 'CLASS_DEF' in adding tests 
@Malintha1996 See https://github.com/checkstyle/checkstyle/issues/7729 and it's final commit as an example of completed work for this issue. Let me know if you have any more questions.

Patch:
diff --git a/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionAnnotationLocationTest.java b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionAnnotationLocationTest.java
new file mode 100644
--- /dev/null
+++ b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionAnnotationLocationTest.java
@@ -0,0 +1,233 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2020 the original author or authors.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+////////////////////////////////////////////////////////////////////////////////
+
+package org.checkstyle.suppressionxpathfilter;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationLocationCheck;
+
+public class XpathRegressionAnnotationLocationTest extends AbstractXpathTestSupport {
+
+    private final String checkName = AnnotationLocationCheck.class.getSimpleName();
+
+    @Override
+    protected String getCheckName() {
+        return checkName;
+    }
+
+    @Test
+    public void testClass() throws Exception {
+        final File fileToProcess = new File(getPath(
+                "SuppressionXpathRegressionAnnotationLocationClass.java"));
+
+        final DefaultConfiguration moduleConfig =
+                createModuleConfig(AnnotationLocationCheck.class);
+
+        final String[] expectedViolation = {
+            "6:1: " + getCheckMessage(AnnotationLocationCheck.class,
+                    AnnotationLocationCheck.MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationClass']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationClass']]"
+                        + "/MODIFIERS",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationClass']]/"
+                        + "MODIFIERS/ANNOTATION[./IDENT[@text='ClassAnnotation']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationClass']]/"
+                        + "MODIFIERS/ANNOTATION[./IDENT[@text='ClassAnnotation']]/AT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation,
+                expectedXpathQueries);
+    }
+
+    @Test
+    public void testInterface() throws Exception {
+        final File fileToProcess = new File(getPath(
+                "SuppressionXpathRegressionAnnotationLocationInterface.java"));
+
+        final DefaultConfiguration moduleConfig =
+                createModuleConfig(AnnotationLocationCheck.class);
+
+        final String[] expectedViolation = {
+            "7:1: " + getCheckMessage(AnnotationLocationCheck.class,
+             AnnotationLocationCheck.MSG_KEY_ANNOTATION_LOCATION_ALONE,
+                    "InterfaceAnnotation"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+            "/INTERFACE_DEF[./IDENT[@text='SuppressionXpathRegression"
+                    + "AnnotationLocationInterface']]",
+            "/INTERFACE_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationInterface'"
+                        + "]]/MODIFIERS",
+            "/INTERFACE_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationInterface']]"
+                    + "/MODIFIERS/ANNOTATION[./IDENT[@text='InterfaceAnnotation']]",
+            "/INTERFACE_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationInterface']]"
+                    + "/MODIFIERS/ANNOTATION[./IDENT[@text='InterfaceAnnotation']]/AT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation,
+                expectedXpathQueries);
+    }
+
+    @Test
+    public void testEnum() throws Exception {
+        final File fileToProcess = new File(getPath(
+                "SuppressionXpathRegressionAnnotationLocationEnum.java"));
+
+        final DefaultConfiguration moduleConfig =
+                createModuleConfig(AnnotationLocationCheck.class);
+
+        final String[] expectedViolation = {
+            "6:1: " + getCheckMessage(AnnotationLocationCheck.class,
+                    AnnotationLocationCheck.MSG_KEY_ANNOTATION_LOCATION_ALONE,
+                    "EnumAnnotation"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+                "/ENUM_DEF[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationEnum']]",
+                "/ENUM_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationEnum']]"
+                        + "/MODIFIERS",
+                "/ENUM_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationEnum']]"
+                        + "/MODIFIERS/ANNOTATION[./IDENT[@text='EnumAnnotation']]",
+                "/ENUM_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationEnum']]"
+                        + "/MODIFIERS/ANNOTATION[./IDENT[@text='EnumAnnotation']]/AT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation,
+                expectedXpathQueries);
+
+    }
+
+    @Test
+    public void testMethod() throws Exception {
+        final File fileToProcess = new File(getPath(
+                "SuppressionXpathRegressionAnnotationLocationMethod.java"));
+
+        final DefaultConfiguration moduleConfig =
+                createModuleConfig(AnnotationLocationCheck.class);
+        moduleConfig.addAttribute("tokens", "METHOD_DEF");
+
+        final String[] expectedViolation = {
+            "4:6: " + getCheckMessage(AnnotationLocationCheck.class,
+                    AnnotationLocationCheck.MSG_KEY_ANNOTATION_LOCATION_ALONE,
+                    "MethodAnnotation"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationMethod']]/"
+                        + "OBJBLOCK/METHOD_DEF[./IDENT[@text='foo1']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationMethod']]/"
+                        + "OBJBLOCK/METHOD_DEF[./IDENT[@text='foo1']]/MODIFIERS",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationMethod']]/"
+                        + "OBJBLOCK/METHOD_DEF[./IDENT[@text='foo1']]/MODIFIERS/"
+                        + "ANNOTATION[./IDENT[@text='MethodAnnotation']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationMethod']]/"
+                        + "OBJBLOCK/METHOD_DEF[./IDENT[@text='foo1']]/MODIFIERS/"
+                        + "ANNOTATION[./IDENT[@text='MethodAnnotation']]/AT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation,
+                expectedXpathQueries);
+
+    }
+
+    @Test
+    public void testVariable() throws Exception {
+        final File fileToProcess = new File(getPath(
+                "SuppressionXpathRegressionAnnotationLocationVariable.java"));
+
+        final DefaultConfiguration moduleConfig =
+                createModuleConfig(AnnotationLocationCheck.class);
+        moduleConfig.addAttribute("tokens", "VARIABLE_DEF");
+
+        final String[] expectedViolation = {
+            "4:5: " + getCheckMessage(AnnotationLocationCheck.class,
+                    AnnotationLocationCheck.MSG_KEY_ANNOTATION_LOCATION_ALONE,
+                    "VariableAnnotation"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationVariable']]/"
+                        + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='b']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationVariable']]/"
+                        + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='b']]/MODIFIERS",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationVariable']]/"
+                        + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='b']]/MODIFIERS/"
+                        + "ANNOTATION[./IDENT[@text='VariableAnnotation']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionAnnotationLocationVariable']]/"
+                        + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='b']]/MODIFIERS/"
+                        + "ANNOTATION[./IDENT[@text='VariableAnnotation']]/AT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation,
+                expectedXpathQueries);
+
+    }
+
+    @Test
+    public void testConstructor() throws Exception {
+        final File fileToProcess = new File(getPath(
+                "SuppressionXpathRegressionAnnotationLocationCTOR.java"));
+
+        final DefaultConfiguration moduleConfig =
+                createModuleConfig(AnnotationLocationCheck.class);
+        moduleConfig.addAttribute("tokens", "CTOR_DEF");
+
+        final String[] expectedViolation = {
+            "4:5: " + getCheckMessage(AnnotationLocationCheck.class,
+                    AnnotationLocationCheck.MSG_KEY_ANNOTATION_LOCATION_ALONE,
+                    "CTORAnnotation"),
+        };
+
+        final List<String> expectedXpathQueries = Arrays.asList(
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/OBJBLOCK/CTOR_DEF"
+                        + "[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/OBJBLOCK/CTOR_DEF"
+                        + "[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/MODIFIERS",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/OBJBLOCK/CTOR_DEF"
+                        + "[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/"
+                        + "MODIFIERS/ANNOTATION[./IDENT[@text='CTORAnnotation']]",
+                "/CLASS_DEF[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/OBJBLOCK/CTOR_DEF"
+                        + "[./IDENT[@text='SuppressionXpathRegression"
+                        + "AnnotationLocationCTOR']]/"
+                        + "MODIFIERS/ANNOTATION[./IDENT[@text='CTORAnnotation']]/AT"
+        );
+
+        runVerifications(moduleConfig, fileToProcess, expectedViolation,
+                expectedXpathQueries);
+
+    }
+
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationAnnotation.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationAnnotation.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationAnnotation.java
@@ -0,0 +1,15 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Annotation("bar") @interface SuppressionXpathRegressionAnnotationLocationAnnotation {//warn
+
+}
+
+@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
+@interface Annotation  {
+
+    String value() default "";
+
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationCTOR.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationCTOR.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationCTOR.java
@@ -0,0 +1,12 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+public class SuppressionXpathRegressionAnnotationLocationCTOR {
+    @CTORAnnotation(value = "") public SuppressionXpathRegressionAnnotationLocationCTOR()//warn
+    {
+        // comment
+    }
+}
+
+@interface CTORAnnotation {
+    String value();
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationClass.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationClass.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationClass.java
@@ -0,0 +1,15 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@ClassAnnotation("bar") class SuppressionXpathRegressionAnnotationLocationClass { //warn
+
+}
+
+@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE})
+@interface ClassAnnotation {
+
+    String value() default "";
+
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationEnum.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationEnum.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationEnum.java
@@ -0,0 +1,18 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@EnumAnnotation("bar") enum SuppressionXpathRegressionAnnotationLocationEnum { //warn
+
+    SuppressionXpathRegressionAnnotationLocationEnum() {
+    }
+
+}
+
+@Target({ElementType.FIELD, ElementType.TYPE})
+@interface EnumAnnotation  {
+
+    String value() default "";
+
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationInterface.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationInterface.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationInterface.java
@@ -0,0 +1,25 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Target;
+
+@InterfaceAnnotation("bar") interface SuppressionXpathRegressionAnnotationLocationInterface { //warn
+
+}
+
+@Repeatable(InterfaceAnnotations.class)
+@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE})
+@interface InterfaceAnnotation  {
+
+    String value() default "";
+
+}
+
+@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE})
+@interface InterfaceAnnotations {
+
+    InterfaceAnnotation[] value();
+
+}
+
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationMethod.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationMethod.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationMethod.java
@@ -0,0 +1,10 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+public class SuppressionXpathRegressionAnnotationLocationMethod {
+     @MethodAnnotation("foo") void foo1() {}//warn
+}
+@interface MethodAnnotation {
+     String value();
+}
+
+
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationVariable.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationVariable.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/annotationlocation/SuppressionXpathRegressionAnnotationLocationVariable.java
@@ -0,0 +1,8 @@
+package org.checkstyle.suppressionxpathfilter.annotationlocation;
+
+public class SuppressionXpathRegressionAnnotationLocationVariable {
+    @VariableAnnotation(value = "") public int b; //warn
+}
+@interface VariableAnnotation {
+    String value();
+}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.java
@@ -282,11 +282,11 @@ private void checkAnnotations(DetailAST modifierNode, int correctIndentation) {
             final boolean hasParameters = isParameterized(annotation);
 
             if (!isCorrectLocation(annotation, hasParameters)) {
-                log(annotation.getLineNo(),
+                log(annotation,
                         MSG_KEY_ANNOTATION_LOCATION_ALONE, getAnnotationName(annotation));
             }
             else if (annotation.getColumnNo() != correctIndentation && !hasNodeBefore(annotation)) {
-                log(annotation.getLineNo(), MSG_KEY_ANNOTATION_LOCATION,
+                log(annotation, MSG_KEY_ANNOTATION_LOCATION,
                     getAnnotationName(annotation), annotation.getColumnNo(), correctIndentation);
             }
             annotation = annotation.getNextSibling();
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionXpathFilter.java
@@ -44,9 +44,6 @@
  * </p>
  * <ul id="SuppressionXpathFilter_IncompatibleChecks">
  * <li>
- * AnnotationLocation
- * </li>
- * <li>
  * AnnotationOnSameLine
  * </li>
  * <li>


Test patch:
diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java
--- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java
+++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java
@@ -42,18 +42,18 @@ public void testAnnotation() throws Exception {
         final String msgLocationAlone = "annotation.location.alone";
         final String msgLocation = "annotation.location";
         final String[] expected = {
-            "3: " + getCheckMessage(clazz, msgLocationAlone, "MyAnnotation1"),
-            "20: " + getCheckMessage(clazz, msgLocation, "MyAnnotation1", "8", "4"),
-            "27: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "7", "4"),
-            "31: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "8", "4"),
-            "32: " + getCheckMessage(clazz, msgLocation, "MyAnnotation3", "6", "4"),
-            "33: " + getCheckMessage(clazz, msgLocation, "MyAnnotation4", "10", "4"),
-            "54: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "12", "8"),
-            "58: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "12", "8"),
-            "78: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "11", "8"),
-            "81: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "10", "8"),
-            "90: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "1", "0"),
-            "93: " + getCheckMessage(clazz, msgLocationAlone, "MyAnnotationWithParam"),
+            "3:16: " + getCheckMessage(clazz, msgLocationAlone, "MyAnnotation1"),
+            "20:9: " + getCheckMessage(clazz, msgLocation, "MyAnnotation1", "8", "4"),
+            "27:8: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "7", "4"),
+            "31:9: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "8", "4"),
+            "32:7: " + getCheckMessage(clazz, msgLocation, "MyAnnotation3", "6", "4"),
+            "33:11: " + getCheckMessage(clazz, msgLocation, "MyAnnotation4", "10", "4"),
+            "54:13: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "12", "8"),
+            "58:13: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "12", "8"),
+            "78:12: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "11", "8"),
+            "81:11: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "10", "8"),
+            "90:2: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "1", "0"),
+            "93:1: " + getCheckMessage(clazz, msgLocationAlone, "MyAnnotationWithParam"),
         };
 
         final String filePath = getPath("InputAnnotationLocation.java");
@@ -71,7 +71,7 @@ public void testAnnotationVariables() throws Exception {
 
         final String msgLocation = "annotation.location";
         final String[] expected = {
-            "63: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "7", "4"),
+            "63:8: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "7", "4"),
         };
 
         final String filePath = getPath("InputAnnotationLocationVariables.java");
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java
@@ -56,30 +56,30 @@ public void testCorrect() throws Exception {
     public void testIncorrect() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         final String[] expected = {
-            "6: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnn"),
-            "11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "14: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
-            "25: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
-            "29: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "29: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation2"),
-            "32: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
-            "36: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 8, 4),
-            "37: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation3", 6, 4),
-            "38: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation4", 10, 4),
-            "41: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "45: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "48: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 12, 8),
-            "56: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "61: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
-            "65: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
-            "70: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
-            "73: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "75: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "85: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 11, 8),
-            "88: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 10, 8),
-            "91: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "98: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 0, 3),
+            "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),
         };
         verify(checkConfig, getPath("InputAnnotationLocationIncorrect.java"), expected);
     }
@@ -91,30 +91,30 @@ public void testIncorrectAllTokens() throws Exception {
                 + "CTOR_DEF, VARIABLE_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, "
                 + "ENUM_CONSTANT_DEF, PACKAGE_DEF");
         final String[] expected = {
-            "6: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnn"),
-            "11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "14: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
-            "25: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
-            "29: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "29: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation2"),
-            "32: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
-            "36: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 8, 4),
-            "37: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation3", 6, 4),
-            "38: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation4", 10, 4),
-            "41: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "45: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "48: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 12, 8),
-            "56: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "61: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
-            "65: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
-            "70: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
-            "73: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "75: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "85: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 11, 8),
-            "88: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 10, 8),
-            "91: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation1"),
-            "98: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 0, 3),
+            "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),
         };
         verify(checkConfig, getPath("InputAnnotationLocationIncorrect.java"), expected);
     }
@@ -152,19 +152,19 @@ public void testWithParameters() throws Exception {
         checkConfig.addAttribute("allowSamelineParameterizedAnnotation", "true");
         checkConfig.addAttribute("allowSamelineMultipleAnnotations", "true");
         final String[] expected = {
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
-            "25: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 8, 4),
-            "32: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
-            "36: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 8, 4),
-            "37: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation3", 6, 4),
-            "38: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation4", 10, 4),
-            "48: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation1", 12, 8),
-            "61: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
-            "65: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 12, 8),
-            "70: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 7, 4),
-            "85: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 11, 8),
-            "88: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 10, 8),
-            "98: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "MyAnnotation2", 0, 3),
+            "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),
             };
         verify(checkConfig, getPath("InputAnnotationLocationIncorrect.java"), expected);
     }
@@ -174,9 +174,9 @@ public void testWithMultipleAnnotations() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         checkConfig.addAttribute("allowSamelineSingleParameterlessAnnotation", "false");
         final String[] expected = {
-            "3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation11"),
-            "3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation12"),
-            "3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation13"),
+            "3:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation11"),
+            "3:17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation12"),
+            "3:33: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "MyAnnotation13"),
             };
         verify(checkConfig, getPath("InputAnnotationLocationCustomAnnotationsDeclared.java"),
                 expected);
@@ -196,10 +196,10 @@ public void testAnnotation() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         checkConfig.addAttribute("tokens", "ANNOTATION_DEF, ANNOTATION_FIELD_DEF");
         final String[] expected = {
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "AnnotationAnnotation", 2, 0),
-            "18: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "AnnotationAnnotation"),
-            "21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "AnnotationAnnotation", 6, 4),
-            "22: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "AnnotationAnnotation"),
+            "17:3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "AnnotationAnnotation", 2, 0),
+            "18:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "AnnotationAnnotation"),
+            "21:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "AnnotationAnnotation", 6, 4),
+            "22:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "AnnotationAnnotation"),
         };
         verify(checkConfig, getPath("InputAnnotationLocationAnnotation.java"), expected);
     }
@@ -209,12 +209,12 @@ public void testClass() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         checkConfig.addAttribute("tokens", "CLASS_DEF, CTOR_DEF, VARIABLE_DEF");
         final String[] expected = {
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "ClassAnnotation", 2, 0),
-            "18: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
-            "21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "ClassAnnotation", 6, 4),
-            "22: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
-            "25: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "ClassAnnotation", 6, 4),
-            "26: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
+            "17:3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "ClassAnnotation", 2, 0),
+            "18:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
+            "21:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "ClassAnnotation", 6, 4),
+            "22:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
+            "25:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "ClassAnnotation", 6, 4),
+            "26:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "ClassAnnotation"),
         };
         verify(checkConfig, getPath("InputAnnotationLocationClass.java"), expected);
     }
@@ -224,10 +224,10 @@ public void testEnum() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         checkConfig.addAttribute("tokens", "ENUM_DEF, ENUM_CONSTANT_DEF");
         final String[] expected = {
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "EnumAnnotation", 2, 0),
-            "18: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "EnumAnnotation"),
-            "21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "EnumAnnotation", 6, 4),
-            "22: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "EnumAnnotation"),
+            "17:3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "EnumAnnotation", 2, 0),
+            "18:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "EnumAnnotation"),
+            "21:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "EnumAnnotation", 6, 4),
+            "22:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "EnumAnnotation"),
         };
         verify(checkConfig, getPath("InputAnnotationLocationEnum.java"), expected);
     }
@@ -237,10 +237,10 @@ public void testInterface() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         checkConfig.addAttribute("tokens", "INTERFACE_DEF, METHOD_DEF");
         final String[] expected = {
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "InterfaceAnnotation", 2, 0),
-            "18: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "InterfaceAnnotation"),
-            "21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "InterfaceAnnotation", 6, 4),
-            "22: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "InterfaceAnnotation"),
+            "17:3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "InterfaceAnnotation", 2, 0),
+            "18:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "InterfaceAnnotation"),
+            "21:7: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "InterfaceAnnotation", 6, 4),
+            "22:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "InterfaceAnnotation"),
         };
         verify(checkConfig, getPath("InputAnnotationLocationInterface.java"), expected);
     }
@@ -250,8 +250,8 @@ public void testPackage() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class);
         checkConfig.addAttribute("tokens", "PACKAGE_DEF");
         final String[] expected = {
-            "11: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "PackageAnnotation", 2, 0),
-            "12: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "PackageAnnotation"),
+            "11:3: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION, "PackageAnnotation", 2, 0),
+            "12:1: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "PackageAnnotation"),
         };
         verify(checkConfig, getPath("inputs/package-info.java"), expected);
     }
@@ -285,10 +285,13 @@ public void testAnnotationParameterized() throws Exception {
         checkConfig.addAttribute("allowSamelineSingleParameterlessAnnotation", "false");
         checkConfig.addAttribute("allowSamelineParameterizedAnnotation", "true");
         final String[] expected = {
-            "15: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "23: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "25: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "15:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "17:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "17:17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "23:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "23:17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "23:33: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "25:21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
         };
         verify(checkConfig, getPath("InputAnnotationLocationParameterized.java"), expected);
     }
@@ -300,11 +303,13 @@ public void testAnnotationSingleParameterless() throws Exception {
         checkConfig.addAttribute("allowSamelineSingleParameterlessAnnotation", "true");
         checkConfig.addAttribute("allowSamelineParameterizedAnnotation", "false");
         final String[] expected = {
-            "19: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "23: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "25: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
-            "27: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "19:17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "21:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "23:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "25:17: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "25:33: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "27:5: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
+            "27:21: " + getCheckMessage(MSG_KEY_ANNOTATION_LOCATION_ALONE, "Annotation"),
         };
         verify(checkConfig, getPath("InputAnnotationLocationSingleParameterless.java"), expected);
     }
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XpathRegressionTest.java
@@ -52,7 +52,6 @@ public class XpathRegressionTest extends AbstractModuleTestSupport {
     // till https://github.com/checkstyle/checkstyle/issues/5777
     public static final Set<String> INCOMPATIBLE_CHECK_NAMES =
         Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
-            "AnnotationLocation",
             "AnnotationOnSameLine",
             "AnnotationUseStyle",
             "AvoidEscapedUnicodeCharacters",