|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HiddenFieldCheck | Line # 74 | 99.2% |
0.9918699
|
50 | 75 | 50 | 50 | 0.67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HiddenFieldCheck.FieldFrame | Line # 386 | 92.6% |
0.9259259
|
10.04 | 14 | 10 | 10 | 0.71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (7) | |||
| Result | |||
|
0.81333333
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreSetter
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreSetter
|
1 PASS | |
|
0.73333335
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreAbstractMethods
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreAbstractMethods
|
1 PASS | |
|
0.70666665
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreConstructorParameter
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreConstructorParameter
|
1 PASS | |
|
0.7
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreFormat
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testIgnoreFormat
|
1 PASS | |
|
0.6666667
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testNoParameters
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testNoParameters
|
1 PASS | |
|
0.6666667
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testDefault
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testDefault
|
1 PASS | |
|
0.6333333
|
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testReordered
com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheckTest.testReordered
|
1 PASS | |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2005 Oliver Burn | |
| 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 | package com.puppycrawl.tools.checkstyle.checks.coding; | |
| 20 | ||
| 21 | import java.util.HashSet; | |
| 22 | import java.util.Set; | |
| 23 | import java.util.regex.Pattern; | |
| 24 | import java.util.regex.PatternSyntaxException; | |
| 25 | ||
| 26 | import org.apache.commons.beanutils.ConversionException; | |
| 27 | ||
| 28 | import com.puppycrawl.tools.checkstyle.api.Check; | |
| 29 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 30 | import com.puppycrawl.tools.checkstyle.api.ScopeUtils; | |
| 31 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 32 | import com.puppycrawl.tools.checkstyle.api.Utils; | |
| 33 | ||
| 34 | /** | |
| 35 | * <p>Checks that a local variable or a parameter does not shadow | |
| 36 | * a field that is defined in the same class. | |
| 37 | * </p> | |
| 38 | * <p> | |
| 39 | * An example of how to configure the check is: | |
| 40 | * </p> | |
| 41 | * <pre> | |
| 42 | * <module name="HiddenField"/> | |
| 43 | * </pre> | |
| 44 | * <p> | |
| 45 | * An example of how to configure the check so that it checks variables but not | |
| 46 | * parameters is: | |
| 47 | * </p> | |
| 48 | * <pre> | |
| 49 | * <module name="HiddenField"> | |
| 50 | * <property name="tokens" value="VARIABLE_DEF"/> | |
| 51 | * </module> | |
| 52 | * </pre> | |
| 53 | * <p> | |
| 54 | * An example of how to configure the check so that it ignores the parameter of | |
| 55 | * a setter method is: | |
| 56 | * </p> | |
| 57 | * <pre> | |
| 58 | * <module name="HiddenField"> | |
| 59 | * <property name="ignoreSetter" value="true"/> | |
| 60 | * </module> | |
| 61 | * </pre> | |
| 62 | * <p> | |
| 63 | * An example of how to configure the check so that it ignores constructor | |
| 64 | * parameters is: | |
| 65 | * </p> | |
| 66 | * <pre> | |
| 67 | * <module name="HiddenField"> | |
| 68 | * <property name="ignoreConstructorParameter" value="true"/> | |
| 69 | * </module> | |
| 70 | * </pre> | |
| 71 | * @author Rick Giles | |
| 72 | * @version 1.0 | |
| 73 | */ | |
| 74 | public class HiddenFieldCheck | |
| 75 | extends Check | |
| 76 | { | |
| 77 | /** stack of sets of field names, | |
| 78 | * one for each class of a set of nested classes. | |
| 79 | */ | |
| 80 | private FieldFrame mCurrentFrame; | |
| 81 | ||
| 82 | /** the regexp to match against */ | |
| 83 | private Pattern mRegexp; | |
| 84 | ||
| 85 | /** controls whether to check the parameter of a property setter method */ | |
| 86 | private boolean mIgnoreSetter; | |
| 87 | ||
| 88 | /** controls whether to check the parameter of a constructor */ | |
| 89 | private boolean mIgnoreConstructorParameter; | |
| 90 | ||
| 91 | /** controls whether to check the parameter of abstract methods. */ | |
| 92 | private boolean mIgnoreAbstractMethods; | |
| 93 | ||
| 94 | /** {@inheritDoc} */ | |
| 95 | 6 |
public int[] getDefaultTokens() |
| 96 | { | |
| 97 | 6 | return new int[] { |
| 98 | TokenTypes.VARIABLE_DEF, | |
| 99 | TokenTypes.PARAMETER_DEF, | |
| 100 | TokenTypes.CLASS_DEF, | |
| 101 | TokenTypes.ENUM_DEF, | |
| 102 | TokenTypes.ENUM_CONSTANT_DEF, | |
| 103 | }; | |
| 104 | } | |
| 105 | ||
| 106 | /** {@inheritDoc} */ | |
| 107 | 1 |
public int[] getAcceptableTokens() |
| 108 | { | |
| 109 | 1 | return new int[] { |
| 110 | TokenTypes.VARIABLE_DEF, | |
| 111 | TokenTypes.PARAMETER_DEF, | |
| 112 | }; | |
| 113 | } | |
| 114 | ||
| 115 | /** {@inheritDoc} */ | |