| 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.ScopeUtils; | |
| 25 | ||
| 26 | /** | |
| 27 | * <p> | |
| 28 | * Checks that instance variable names conform to a format specified | |
| 29 | * by the format property. The format is a | |
| 30 | * {@link java.util.regex.Pattern regular expression} | |
| 31 | * and defaults to | |
| 32 | * <strong>^[a-z][a-zA-Z0-9]*$</strong>. | |
| 33 | * </p> | |
| 34 | * <p> | |
| 35 | * An example of how to configure the check is: | |
| 36 | * </p> | |
| 37 | * <pre> | |
| 38 | * <module name="MemberName"/> | |
| 39 | * </pre> | |
| 40 | * <p> | |
| 41 | * An example of how to configure the check for names that begin with | |
| 42 | * "m", followed by an upper case letter, and then letters and | |
| 43 | * digits is: | |
| 44 | * </p> | |
| 45 | * <pre> | |
| 46 | * <module name="MemberName"> | |
| 47 | * <property name="format" value="^m[A-Z][a-zA-Z0-9]*$"/> | |
| 48 | * </module> | |
| 49 | * </pre> | |
| 50 | * @author Rick Giles | |
| 51 | */ | |
| 52 | public class MemberNameCheck | |
| 53 | extends AbstractAccessControlNameCheck { | |
| 54 | ||
| 55 | /** Creates a new {@code MemberNameCheck} instance. */ | |
| 56 | public MemberNameCheck() { | |
| 57 | super("^[a-z][a-zA-Z0-9]*$"); | |
| 58 | } | |
| 59 | ||
| 60 | @Override | |
| 61 | public int[] getDefaultTokens() { | |
| 62 |
1
1. getDefaultTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheck::getDefaultTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return getRequiredTokens(); |
| 63 | } | |
| 64 | ||
| 65 | @Override | |
| 66 | public int[] getAcceptableTokens() { | |
| 67 |
1
1. getAcceptableTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheck::getAcceptableTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return getRequiredTokens(); |
| 68 | } | |
| 69 | ||
| 70 | @Override | |
| 71 | public int[] getRequiredTokens() { | |
| 72 |
1
1. getRequiredTokens : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheck::getRequiredTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] {TokenTypes.VARIABLE_DEF}; |
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 | protected final boolean mustCheckName(DetailAST ast) { | |
| 77 | final DetailAST modifiersAST = | |
| 78 | ast.findFirstToken(TokenTypes.MODIFIERS); | |
| 79 |
1
1. mustCheckName : negated conditional → KILLED |
final boolean isStatic = modifiersAST.findFirstToken(TokenTypes.LITERAL_STATIC) != null; |
| 80 | ||
| 81 |
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 !isStatic && !ScopeUtils.isInInterfaceOrAnnotationBlock(ast) |
| 82 |
1
1. mustCheckName : negated conditional → KILLED |
&& !ScopeUtils.isLocalVariableDef(ast) |
| 83 |
1
1. mustCheckName : negated conditional → KILLED |
&& shouldCheckInScope(modifiersAST); |
| 84 | } | |
| 85 | ||
| 86 | } | |
Mutations | ||
| 62 |
1.1 |
|
| 67 |
1.1 |
|
| 72 |
1.1 |
|
| 79 |
1.1 |
|
| 81 |
1.1 2.2 3.3 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |