| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2018 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.coding; | |
| 21 | ||
| 22 | import com.puppycrawl.tools.checkstyle.StatelessCheck; | |
| 23 | import com.puppycrawl.tools.checkstyle.api.AbstractCheck; | |
| 24 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 25 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 26 | import com.puppycrawl.tools.checkstyle.utils.CommonUtils; | |
| 27 | import com.puppycrawl.tools.checkstyle.utils.JavadocUtils; | |
| 28 | import com.puppycrawl.tools.checkstyle.utils.TokenUtils; | |
| 29 | ||
| 30 | /** | |
| 31 | * <p> | |
| 32 | * Checks for illegal tokens. By default labels are prohibited. | |
| 33 | * </p> | |
| 34 | * <p> | |
| 35 | * Rationale: Certain language features can harm readability, lead to | |
| 36 | * confusion or are not obvious to novice developers. Other features | |
| 37 | * may be discouraged in certain frameworks, such as not having | |
| 38 | * native methods in EJB components. | |
| 39 | * </p> | |
| 40 | * <p> | |
| 41 | * An example of how to configure the check is: | |
| 42 | * </p> | |
| 43 | * <pre> | |
| 44 | * <module name="IllegalToken"/> | |
| 45 | * </pre> | |
| 46 | * <p> An example of how to configure the check to forbid | |
| 47 | * a {@link TokenTypes#LITERAL_NATIVE LITERAL_NATIVE} token is: | |
| 48 | * </p> | |
| 49 | * <pre> | |
| 50 | * <module name="IllegalToken"> | |
| 51 | * <property name="tokens" value="LITERAL_NATIVE"/> | |
| 52 | * </module> | |
| 53 | * </pre> | |
| 54 | * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a> | |
| 55 | * @author Rick Giles | |
| 56 | */ | |
| 57 | @StatelessCheck | |
| 58 | public class IllegalTokenCheck | |
| 59 | extends AbstractCheck { | |
| 60 | ||
| 61 | /** | |
| 62 | * A key is pointing to the warning message text in "messages.properties" | |
| 63 | * file. | |
| 64 | */ | |
| 65 | public static final String MSG_KEY = "illegal.token"; | |
| 66 | ||
| 67 | @Override | |
| 68 | public int[] getDefaultTokens() { | |
| 69 |
1
1. getDefaultTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenCheck::getDefaultTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] { |
| 70 | TokenTypes.LABELED_STAT, | |
| 71 | }; | |
| 72 | } | |
| 73 | ||
| 74 | @Override | |
| 75 | public int[] getAcceptableTokens() { | |
| 76 |
1
1. getAcceptableTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenCheck::getAcceptableTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return TokenUtils.getAllTokenIds(); |
| 77 | } | |
| 78 | ||
| 79 | @Override | |
| 80 | public int[] getRequiredTokens() { | |
| 81 |
1
1. getRequiredTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenCheck::getRequiredTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return CommonUtils.EMPTY_INT_ARRAY; |
| 82 | } | |
| 83 | ||
| 84 | @Override | |
| 85 | public boolean isCommentNodesRequired() { | |
| 86 |
1
1. isCommentNodesRequired : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 87 | } | |
| 88 | ||
| 89 | @Override | |
| 90 | public void visitToken(DetailAST ast) { | |
| 91 |
1
1. visitToken : removed call to com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenCheck::log → KILLED |
log( |
| 92 | ast.getLineNo(), | |
| 93 | ast.getColumnNo(), | |
| 94 | MSG_KEY, | |
| 95 | convertToString(ast) | |
| 96 | ); | |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Converts given AST node to string representation. | |
| 101 | * @param ast node to be represented as string | |
| 102 | * @return string representation of AST node | |
| 103 | */ | |
| 104 | private static String convertToString(DetailAST ast) { | |
| 105 | final String tokenText; | |
| 106 | switch (ast.getType()) { | |
| 107 | case TokenTypes.LABELED_STAT: | |
| 108 | tokenText = ast.getFirstChild().getText() + ast.getText(); | |
| 109 | break; | |
| 110 | // multiline tokens need to become singlelined | |
| 111 | case TokenTypes.COMMENT_CONTENT: | |
| 112 | tokenText = JavadocUtils.escapeAllControlChars(ast.getText()); | |
| 113 | break; | |
| 114 | default: | |
| 115 | tokenText = ast.getText(); | |
| 116 | break; | |
| 117 | } | |
| 118 |
1
1. convertToString : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenCheck::convertToString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return tokenText; |
| 119 | } | |
| 120 | ||
| 121 | } | |
Mutations | ||
| 69 |
1.1 |
|
| 76 |
1.1 |
|
| 81 |
1.1 |
|
| 86 |
1.1 |
|
| 91 |
1.1 |
|
| 118 |
1.1 |