| 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 com.puppycrawl.tools.checkstyle.api.AbstractCheck; | |
| 23 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 24 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 25 | import com.puppycrawl.tools.checkstyle.utils.CommonUtils; | |
| 26 | ||
| 27 | /** | |
| 28 | * <p>Checks that chosen statements are not line-wrapped. | |
| 29 | * By default this Check restricts wrapping import and package statements, | |
| 30 | * but it's possible to check any statement. | |
| 31 | * </p> | |
| 32 | * | |
| 33 | * <p>Examples of line-wrapped statements (bad case): | |
| 34 | * <pre>{@code package com.puppycrawl. | |
| 35 | * tools.checkstyle.checks; | |
| 36 | * | |
| 37 | * import com.puppycrawl.tools. | |
| 38 | * checkstyle.api.AbstractCheck; | |
| 39 | * }</pre> | |
| 40 | * | |
| 41 | * <p> | |
| 42 | * To configure the check to force no line-wrapping | |
| 43 | * in package and import statements (default values): | |
| 44 | * </p> | |
| 45 | * <pre class="body"> | |
| 46 | * <module name="NoLineWrap"/> | |
| 47 | * </pre> | |
| 48 | * | |
| 49 | * <p> | |
| 50 | * To configure the check to force no line-wrapping only | |
| 51 | * in import statements: | |
| 52 | * </p> | |
| 53 | * <pre class="body"> | |
| 54 | * <module name="NoLineWrap"> | |
| 55 | * <property name="tokens" value="IMPORT"/> | |
| 56 | * </module> | |
| 57 | * </pre> | |
| 58 | * | |
| 59 | * <p>Examples of not line-wrapped statements (good case): | |
| 60 | * <pre>{@code import com.puppycrawl.tools.checkstyle.api.AbstractCheck; | |
| 61 | * }</pre> | |
| 62 | * | |
| 63 | * @author maxvetrenko | |
| 64 | */ | |
| 65 | public class NoLineWrapCheck extends AbstractCheck { | |
| 66 | ||
| 67 | /** | |
| 68 | * A key is pointing to the warning message text in "messages.properties" | |
| 69 | * file. | |
| 70 | */ | |
| 71 | public static final String MSG_KEY = "no.line.wrap"; | |
| 72 | ||
| 73 | @Override | |
| 74 | public int[] getDefaultTokens() { | |
| 75 |
1
1. getDefaultTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/whitespace/NoLineWrapCheck::getDefaultTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] {TokenTypes.PACKAGE_DEF, TokenTypes.IMPORT, TokenTypes.STATIC_IMPORT}; |
| 76 | } | |
| 77 | ||
| 78 | @Override | |
| 79 | public int[] getAcceptableTokens() { | |
| 80 |
1
1. getAcceptableTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/whitespace/NoLineWrapCheck::getAcceptableTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] { |
| 81 | TokenTypes.IMPORT, | |
| 82 | TokenTypes.STATIC_IMPORT, | |
| 83 | TokenTypes.PACKAGE_DEF, | |
| 84 | TokenTypes.CLASS_DEF, | |
| 85 | TokenTypes.METHOD_DEF, | |
| 86 | TokenTypes.CTOR_DEF, | |
| 87 | TokenTypes.ENUM_DEF, | |
| 88 | TokenTypes.INTERFACE_DEF, | |
| 89 | }; | |
| 90 | } | |
| 91 | ||
| 92 | @Override | |
| 93 | public int[] getRequiredTokens() { | |
| 94 |
1
1. getRequiredTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/whitespace/NoLineWrapCheck::getRequiredTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return CommonUtils.EMPTY_INT_ARRAY; |
| 95 | } | |
| 96 | ||
| 97 | @Override | |
| 98 | public void visitToken(DetailAST ast) { | |
| 99 |
1
1. visitToken : negated conditional → KILLED |
if (ast.getLineNo() != ast.getLastChild().getLineNo()) { |
| 100 |
1
1. visitToken : removed call to com/puppycrawl/tools/checkstyle/checks/whitespace/NoLineWrapCheck::log → KILLED |
log(ast.getLineNo(), MSG_KEY, ast.getText()); |
| 101 | } | |
| 102 | } | |
| 103 | } | |
Mutations | ||
| 75 |
1.1 |
|
| 80 |
1.1 |
|
| 94 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |