Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
89   476   60   3.87
38   254   0.67   11.5
23     2.61  
2    
 
  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)
 
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    * &lt;module name="HiddenField"/&gt;
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    * &lt;module name="HiddenField"&gt;
50    * &lt;property name="tokens" value="VARIABLE_DEF"/&gt;
51    * &lt;/module&gt;
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    * &lt;module name="HiddenField"&gt;
59    * &lt;property name="ignoreSetter" value="true"/&gt;
60    * &lt;/module&gt;
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    * &lt;module name="HiddenField"&gt;
68    * &lt;property name="ignoreConstructorParameter" value="true"/&gt;
69    * &lt;/module&gt;
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 toggle 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 toggle public int[] getAcceptableTokens()
108    {
109  1 return new int[] {
110    TokenTypes.VARIABLE_DEF,
111    TokenTypes.PARAMETER_DEF,
112    };
113    }
114   
115    /** {@inheritDoc} */