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.checks.whitespace; | |
21 | ||
22 | import java.io.File; | |
23 | ||
24 | import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; | |
25 | import com.puppycrawl.tools.checkstyle.api.FileText; | |
26 | ||
27 | /** | |
28 | * Checks to see if a file contains a tab character. | |
29 | * @author oliverb | |
30 | */ | |
31 | public class FileTabCharacterCheck extends AbstractFileSetCheck { | |
32 | ||
33 | /** | |
34 | * A key is pointing to the warning message text in "messages.properties" | |
35 | * file. | |
36 | */ | |
37 | public static final String MSG_CONTAINS_TAB = "containsTab"; | |
38 | ||
39 | /** | |
40 | * A key is pointing to the warning message text in "messages.properties" | |
41 | * file. | |
42 | */ | |
43 | public static final String MSG_FILE_CONTAINS_TAB = "file.containsTab"; | |
44 | ||
45 | /** Indicates whether to report once per file, or for each line. */ | |
46 | private boolean eachLine; | |
47 | ||
48 | @Override | |
49 | protected void processFiltered(File file, FileText fileText) { | |
50 | int lineNum = 0; | |
51 |
3
1. processFiltered : changed conditional boundary → KILLED 2. processFiltered : Changed increment from 1 to -1 → KILLED 3. processFiltered : negated conditional → KILLED |
for (int index = 0; index < fileText.size(); index++) { |
52 | final String line = fileText.get(index); | |
53 |
1
1. processFiltered : Changed increment from 1 to -1 → KILLED |
lineNum++; |
54 | final int tabPosition = line.indexOf('\t'); | |
55 |
1
1. processFiltered : negated conditional → KILLED |
if (tabPosition != -1) { |
56 |
1
1. processFiltered : negated conditional → KILLED |
if (eachLine) { |
57 |
2
1. processFiltered : Replaced integer addition with subtraction → KILLED 2. processFiltered : removed call to com/puppycrawl/tools/checkstyle/checks/whitespace/FileTabCharacterCheck::log → KILLED |
log(lineNum, tabPosition + 1, MSG_CONTAINS_TAB); |
58 | } | |
59 | else { | |
60 |
2
1. processFiltered : Replaced integer addition with subtraction → KILLED 2. processFiltered : removed call to com/puppycrawl/tools/checkstyle/checks/whitespace/FileTabCharacterCheck::log → KILLED |
log(lineNum, tabPosition + 1, MSG_FILE_CONTAINS_TAB); |
61 | break; | |
62 | } | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | /** | |
68 | * Whether report on each line containing a tab. | |
69 | * @param eachLine Whether report on each line containing a tab. | |
70 | */ | |
71 | public void setEachLine(boolean eachLine) { | |
72 | this.eachLine = eachLine; | |
73 | } | |
74 | } | |
Mutations | ||
51 |
1.1 2.2 3.3 |
|
53 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 2.2 |
|
60 |
1.1 2.2 |