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; | |
21 | ||
22 | import java.util.regex.Pattern; | |
23 | ||
24 | import com.puppycrawl.tools.checkstyle.api.AbstractCheck; | |
25 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
26 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
27 | ||
28 | /** | |
29 | * <p> | |
30 | * A check for 'TODO:' comments. To check for other patterns in Java comments, set | |
31 | * property format. | |
32 | * </p> | |
33 | * <p> | |
34 | * An example of how to configure the check is: | |
35 | * </p> | |
36 | * | |
37 | * <pre> | |
38 | * <module name="TodoComment"/> | |
39 | * </pre> | |
40 | * <p> | |
41 | * An example of how to configure the check for comments that contain | |
42 | * {@code TODO} or {@code FIXME}is: | |
43 | * </p> | |
44 | * | |
45 | * <pre> | |
46 | * <module name="TodoComment"> | |
47 | * <property name="format" value="(TODO)|(FIXME)"/> | |
48 | * </module> | |
49 | * </pre> | |
50 | * @author Oliver Burn | |
51 | * @author Baratali Izmailov | |
52 | */ | |
53 | public class TodoCommentCheck | |
54 | extends AbstractCheck { | |
55 | ||
56 | /** | |
57 | * A key is pointing to the warning message text in "messages.properties" | |
58 | * file. | |
59 | */ | |
60 | public static final String MSG_KEY = "todo.match"; | |
61 | ||
62 | /** | |
63 | * Regular expression pattern compiled from format. | |
64 | */ | |
65 | private Pattern format = Pattern.compile("TODO:"); | |
66 | ||
67 | @Override | |
68 | public boolean isCommentNodesRequired() { | |
69 |
1
1. isCommentNodesRequired : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
70 | } | |
71 | ||
72 | /** | |
73 | * Setter for 'todo' comment pattern. | |
74 | * @param pattern | |
75 | * pattern of 'todo' comment. | |
76 | */ | |
77 | public void setFormat(Pattern pattern) { | |
78 | format = pattern; | |
79 | } | |
80 | ||
81 | @Override | |
82 | public int[] getDefaultTokens() { | |
83 |
1
1. getDefaultTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck::getDefaultTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return getAcceptableTokens(); |
84 | } | |
85 | ||
86 | @Override | |
87 | public int[] getAcceptableTokens() { | |
88 |
1
1. getAcceptableTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck::getAcceptableTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] {TokenTypes.COMMENT_CONTENT }; |
89 | } | |
90 | ||
91 | @Override | |
92 | public int[] getRequiredTokens() { | |
93 |
1
1. getRequiredTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck::getRequiredTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return getAcceptableTokens(); |
94 | } | |
95 | ||
96 | @Override | |
97 | public void visitToken(DetailAST ast) { | |
98 | final String[] lines = ast.getText().split("\n"); | |
99 | ||
100 |
3
1. visitToken : changed conditional boundary → KILLED 2. visitToken : Changed increment from 1 to -1 → KILLED 3. visitToken : negated conditional → KILLED |
for (int i = 0; i < lines.length; i++) { |
101 |
1
1. visitToken : negated conditional → KILLED |
if (format.matcher(lines[i]).find()) { |
102 |
2
1. visitToken : Replaced integer addition with subtraction → KILLED 2. visitToken : removed call to com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck::log → KILLED |
log(ast.getLineNo() + i, MSG_KEY, format.pattern()); |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
Mutations | ||
69 |
1.1 |
|
83 |
1.1 |
|
88 |
1.1 |
|
93 |
1.1 |
|
100 |
1.1 2.2 3.3 |
|
101 |
1.1 |
|
102 |
1.1 2.2 |