Coverage Report - com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeWalkerAuditEvent
100%
17/17
N/A
1
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2017 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.LocalizedMessage;
 25  
 
 26  
 /**
 27  
  * Raw {@code TreeWalker} event for audit.
 28  
  *
 29  
  * @author Timur Tibeyev
 30  
  */
 31  
 public class TreeWalkerAuditEvent {
 32  
     /** Filename event associated with. **/
 33  
     private final String fileName;
 34  
     /** The file contents. */
 35  
     private final FileContents fileContents;
 36  
     /** Message associated with the event. **/
 37  
     private final LocalizedMessage localizedMessage;
 38  
     /** Root ast element. **/
 39  
     private final DetailAST rootAst;
 40  
 
 41  
     /**
 42  
      * Creates a new {@code TreeWalkerAuditEvent} instance.
 43  
      *
 44  
      * @param fileContents contents of the file associated with the event
 45  
      * @param fileName file associated with the event
 46  
      * @param localizedMessage the actual message
 47  
      * @param rootAst root AST element {@link DetailAST} of the file
 48  
      */
 49  
     public TreeWalkerAuditEvent(FileContents fileContents, String fileName,
 50  417
                                 LocalizedMessage localizedMessage, DetailAST rootAst) {
 51  417
         this.fileContents = fileContents;
 52  417
         this.fileName = fileName;
 53  417
         this.localizedMessage = localizedMessage;
 54  417
         this.rootAst = rootAst;
 55  417
     }
 56  
 
 57  
     /**
 58  
      * Returns name of file being audited.
 59  
      * @return the file name currently being audited or null if there is
 60  
      *     no relation to a file.
 61  
      */
 62  
     public String getFileName() {
 63  40
         return fileName;
 64  
     }
 65  
 
 66  
     /**
 67  
      * Returns contents of the file.
 68  
      * @return contents of the file.
 69  
      */
 70  
     public FileContents getFileContents() {
 71  391
         return fileContents;
 72  
     }
 73  
 
 74  
     /**
 75  
      * Gets the localized message.
 76  
      * @return the localized message
 77  
      */
 78  
     public LocalizedMessage getLocalizedMessage() {
 79  412
         return localizedMessage;
 80  
     }
 81  
 
 82  
     /**
 83  
      * Return the line number on the source file where the event occurred.
 84  
      * This may be 0 if there is no relation to a file content.
 85  
      * @return an integer representing the line number in the file source code.
 86  
      */
 87  
     public int getLine() {
 88  1580
         return localizedMessage.getLineNo();
 89  
     }
 90  
 
 91  
     /**
 92  
      * Return the message associated to the event.
 93  
      * @return the event message
 94  
      */
 95  
     public String getMessage() {
 96  14
         return localizedMessage.getMessage();
 97  
     }
 98  
 
 99  
     /**
 100  
      * Gets the column associated with the message.
 101  
      * @return the column associated with the message
 102  
      */
 103  
     public int getColumn() {
 104  7
         return localizedMessage.getColumnNo();
 105  
     }
 106  
 
 107  
     /**
 108  
      * Gets the column char index associated with the message.
 109  
      * @return the column char index associated with the message
 110  
      */
 111  
     public int getColumnCharIndex() {
 112  6
         return localizedMessage.getColumnCharIndex();
 113  
     }
 114  
 
 115  
     /**
 116  
      * Returns id of module.
 117  
      * @return the identifier of the module that generated the event. Can return
 118  
      *         null.
 119  
      */
 120  
     public String getModuleId() {
 121  110
         return localizedMessage.getModuleId();
 122  
     }
 123  
 
 124  
     /**
 125  
      * Gets the name of the source for the message.
 126  
      * @return the name of the source for the message
 127  
      */
 128  
     public String getSourceName() {
 129  312
         return localizedMessage.getSourceName();
 130  
     }
 131  
 
 132  
     /**
 133  
      * Gets the token type of the message.
 134  
      * @return the token type of the message
 135  
      */
 136  
     public int getTokenType() {
 137  11
         return localizedMessage.getTokenType();
 138  
     }
 139  
 
 140  
     /**
 141  
      * Gets the root element of the AST tree.
 142  
      * @return the root element of the AST tree
 143  
      */
 144  
     public DetailAST getRootAst() {
 145  21
         return rootAst;
 146  
     }
 147  
 }