View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle;
21  
22  import com.puppycrawl.tools.checkstyle.api.DetailAST;
23  import com.puppycrawl.tools.checkstyle.api.FileContents;
24  import com.puppycrawl.tools.checkstyle.api.Violation;
25  
26  /**
27   * Raw {@code TreeWalker} event for audit.
28   *
29   * @param fileContents contents of the file associated with the event
30   * @param fileName file associated with the event
31   * @param violation the actual violation
32   * @param rootAst root AST element {@link DetailAST} of the file
33   */
34  public record TreeWalkerAuditEvent(
35          FileContents fileContents,
36          String fileName,
37          Violation violation,
38          DetailAST rootAst) {
39  
40      /**
41       * Return the line number on the source file where the event occurred.
42       * This may be 0 if there is no relation to a file content.
43       *
44       * @return an integer representing the line number in the file source code.
45       */
46      public int getLine() {
47          return violation.getLineNo();
48      }
49  
50      /**
51       * Return the violation associated to the event.
52       *
53       * @return the violation message
54       */
55      public String getMessage() {
56          return violation.getViolation();
57      }
58  
59      /**
60       * Gets the column associated with the violation.
61       *
62       * @return the column associated with the violation
63       */
64      public int getColumn() {
65          return violation.getColumnNo();
66      }
67  
68      /**
69       * Gets the column char index associated with the violation.
70       *
71       * @return the column char index associated with the violation
72       */
73      public int getColumnCharIndex() {
74          return violation.getColumnCharIndex();
75      }
76  
77      /**
78       * Returns id of module.
79       *
80       * @return the identifier of the module that generated the event. Can return
81       *         null.
82       */
83      public String getModuleId() {
84          return violation.getModuleId();
85      }
86  
87      /**
88       * Gets the name of the source for the violation.
89       *
90       * @return the name of the source for the violation
91       */
92      public String getSourceName() {
93          return violation.getSourceName();
94      }
95  
96      /**
97       * Gets the token type of the violation.
98       *
99       * @return the token type of the violation
100      */
101     public int getTokenType() {
102         return violation.getTokenType();
103     }
104 
105 }