001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2014  Oliver Burn
004//
005// This library is free software; you can redistribute it and/or
006// modify it under the terms of the GNU Lesser General Public
007// License as published by the Free Software Foundation; either
008// version 2.1 of the License, or (at your option) any later version.
009//
010// This library is distributed in the hope that it will be useful,
011// but WITHOUT ANY WARRANTY; without even the implied warranty of
012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013// Lesser General Public License for more details.
014//
015// You should have received a copy of the GNU Lesser General Public
016// License along with this library; if not, write to the Free Software
017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018////////////////////////////////////////////////////////////////////////////////
019package com.puppycrawl.tools.checkstyle.checks.whitespace;
020
021import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
022import java.io.File;
023import java.util.List;
024
025/**
026 * Checks to see if a file contains a tab character.
027 * @author oliverb
028 */
029public class FileTabCharacterCheck extends AbstractFileSetCheck
030{
031    /** Indicates whether to report once per file, or for each line. */
032    private boolean eachLine;
033
034    @Override
035    protected void processFiltered(File file, List<String> lines)
036    {
037        int lineNum = 0;
038        for (final String line : lines) {
039            lineNum++;
040            final int tabPosition = line.indexOf('\t');
041            if (tabPosition != -1) {
042                if (eachLine) {
043                    log(lineNum, tabPosition + 1, "containsTab");
044                }
045                else {
046                    log(lineNum, tabPosition + 1, "file.containsTab");
047                    break;
048                }
049            }
050        }
051    }
052
053    /**
054     * Whether report on each line containing a tab.
055     * @param eachLine Whether report on each line containing a tab.
056     */
057    public void setEachLine(boolean eachLine)
058    {
059        this.eachLine = eachLine;
060    }
061}