Coverage Report - com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck
 
Classes in this File Line Coverage Branch Coverage Complexity
FileTabCharacterCheck
100%
14/14
100%
6/6
2.5
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2014  Oliver Burn
 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  
 package com.puppycrawl.tools.checkstyle.checks.whitespace;
 20  
 
 21  
 import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
 22  
 import java.io.File;
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * Checks to see if a file contains a tab character.
 27  
  * @author oliverb
 28  
  */
 29  3
 public class FileTabCharacterCheck extends AbstractFileSetCheck
 30  
 {
 31  
     /** Indicates whether to report once per file, or for each line. */
 32  
     private boolean mEachLine;
 33  
 
 34  
     @Override
 35  
     protected void processFiltered(File aFile, List<String> aLines)
 36  
     {
 37  2
         int lineNum = 0;
 38  2
         for (final String line : aLines) {
 39  244
             lineNum++;
 40  244
             final int tabPosition = line.indexOf('\t');
 41  244
             if (tabPosition != -1) {
 42  9
                 if (mEachLine) {
 43  8
                     log(lineNum, tabPosition + 1, "containsTab");
 44  
                 }
 45  
                 else {
 46  1
                     log(lineNum, tabPosition + 1, "file.containsTab");
 47  1
                     break;
 48  
                 }
 49  
             }
 50  243
         }
 51  2
     }
 52  
 
 53  
     /**
 54  
      * Whether report on each line containing a tab.
 55  
      * @param aEachLine Whether report on each line containing a tab.
 56  
      */
 57  
     public void setEachLine(boolean aEachLine)
 58  
     {
 59  3
         mEachLine = aEachLine;
 60  3
     }
 61  
 }