| 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.naming; | |
| 21 | ||
| 22 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 23 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 24 | import com.puppycrawl.tools.checkstyle.utils.CommonUtils; | |
| 25 | import com.puppycrawl.tools.checkstyle.utils.ScopeUtils; | |
| 26 | ||
| 27 | /** | |
| 28 | * <p> | |
| 29 | * Checks that local final variable names conform to a format specified | |
| 30 | * by the format property. A catch parameter and resources in try statements | |
| 31 | * are considered to be a local variables.The format is a | |
| 32 | * {@link java.util.regex.Pattern regular expression} and defaults to | |
| 33 | * <strong>^[a-z][a-zA-Z0-9]*$</strong>. | |
| 34 | * </p> | |
| 35 | * <p> | |
| 36 | * An example of how to configure the check is: | |
| 37 | * </p> | |
| 38 | * <pre> | |
| 39 | * <module name="LocalFinalVariableName"/> | |
| 40 | * </pre> | |
| 41 | * <p> | |
| 42 | * An example of how to configure the check for names that are only upper case | |
| 43 | * letters and digits is: | |
| 44 | * </p> | |
| 45 | * <pre> | |
| 46 | * <module name="LocalFinalVariableName"> | |
| 47 | * <property name="format" value="^[A-Z][A-Z0-9]*$"/> | |
| 48 | * </module> | |
| 49 | * </pre> | |
| 50 | * | |
| 51 | * @author Rick Giles | |
| 52 | */ | |
| 53 | public class LocalFinalVariableNameCheck | |
| 54 | extends AbstractNameCheck { | |
| 55 | ||
| 56 | /** Creates a new {@code LocalFinalVariableNameCheck} instance. */ | |
| 57 | public LocalFinalVariableNameCheck() { | |
| 58 | super("^[a-z][a-zA-Z0-9]*$"); | |
| 59 | } | |
| 60 | ||
| 61 | @Override | |
| 62 | public int[] getDefaultTokens() { | |
| 63 |
1
1. getDefaultTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheck::getDefaultTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return getAcceptableTokens(); |
| 64 | } | |
| 65 | ||
| 66 | @Override | |
| 67 | public int[] getAcceptableTokens() { | |
| 68 |
1
1. getAcceptableTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheck::getAcceptableTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] { |
| 69 | TokenTypes.VARIABLE_DEF, | |
| 70 | TokenTypes.PARAMETER_DEF, | |
| 71 | TokenTypes.RESOURCE, | |
| 72 | }; | |
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 | public int[] getRequiredTokens() { | |
| 77 |
1
1. getRequiredTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheck::getRequiredTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return CommonUtils.EMPTY_INT_ARRAY; |
| 78 | } | |
| 79 | ||
| 80 | @Override | |
| 81 | protected final boolean mustCheckName(DetailAST ast) { | |
| 82 | final DetailAST modifiersAST = | |
| 83 | ast.findFirstToken(TokenTypes.MODIFIERS); | |
| 84 |
1
1. mustCheckName : negated conditional → KILLED |
final boolean isFinal = ast.getType() == TokenTypes.RESOURCE |
| 85 |
1
1. mustCheckName : negated conditional → KILLED |
|| modifiersAST.findFirstToken(TokenTypes.FINAL) != null; |
| 86 |
3
1. mustCheckName : negated conditional → KILLED 2. mustCheckName : negated conditional → KILLED 3. mustCheckName : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return isFinal && ScopeUtils.isLocalVariableDef(ast); |
| 87 | } | |
| 88 | ||
| 89 | } | |
Mutations | ||
| 63 |
1.1 |
|
| 68 |
1.1 |
|
| 77 |
1.1 |
|
| 84 |
1.1 |
|
| 85 |
1.1 |
|
| 86 |
1.1 2.2 3.3 |