Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
51   238   33   3.4
10   136   0.65   7.5
15     2.2  
2    
 
  ExecutableStatementCountCheck       Line # 32 91% 0.9104478
29.6 46 29 29 0.63
  ExecutableStatementCountCheck.Context       Line # 193 100% 1.0
4 5 4 4 0.8
 
  (5)
 
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.sizes;
20   
21    import java.util.Stack;
22   
23    import com.puppycrawl.tools.checkstyle.api.Check;
24    import com.puppycrawl.tools.checkstyle.api.DetailAST;
25    import com.puppycrawl.tools.checkstyle.api.TokenTypes;
26   
27    /**
28    * Restricts the number of executable statements to a specified limit
29    * (default = 30).
30    * @author Simon Harris
31    */
 
32    public final class ExecutableStatementCountCheck
33    extends Check
34    {
35    /** default threshold */
36    private static final int DEFAULT_MAX = 30;
37   
38    /** threshold to report error for */
39    private int mMax;
40   
41    /** Stack of method contexts. */
42    private final Stack mContextStack = new Stack();
43   
44    /** Current method context. */
45    private Context mContext;
46   
47    /** Constructs a <code>ExecutableStatementCountCheck</code>. */
 
48  5 toggle public ExecutableStatementCountCheck()
49    {
50  5 setMax(DEFAULT_MAX);
51    }
52   
53    /** {@inheritDoc} */
 
54  5 toggle public int[] getDefaultTokens()
55    {
56  5 return new int[] {
57    TokenTypes.CTOR_DEF,
58    TokenTypes.METHOD_DEF,
59    TokenTypes.INSTANCE_INIT,
60    TokenTypes.STATIC_INIT,
61    TokenTypes.SLIST,
62    };
63    }
64   
65    /** {@inheritDoc} */
 
66  4 toggle public int[] getRequiredTokens()
67    {
68  4 return new int[] {TokenTypes.SLIST};
69    }
70   
71    /**
72    * Gets the maximum threshold.
73    * @return the maximum threshold.
74    */
 
75  40 toggle public int getMax()
76    {
77  40 return mMax;
78    }
79   
80    /**
81    * Sets the maximum threshold.
82    * @param aMax the maximum threshold.
83    */
 
84  10 toggle public void setMax(int aMax)
85    {
86  10 mMax = aMax;
87    }
88   
89    /** {@inheritDoc} */
 
90  5 toggle public void beginTree(DetailAST aRootAST)
91    {
92  5 mContext = null;
93  5 mContextStack.clear();
94    }
95   
96    /** {@inheritDoc} */
 
97  190 toggle public void visitToken(DetailAST aAST)
98    {
99  190 switch (aAST.getType()) {
100  4 case TokenTypes.CTOR_DEF:
101  12 case TokenTypes.METHOD_DEF:
102  2 case TokenTypes.INSTANCE_INIT:
103  2 case TokenTypes.STATIC_INIT:
104  20 visitMemberDef(aAST);
105  20 break;
106  170 case TokenTypes.SLIST:
107  170 visitSlist(aAST);
108  170 break;
109  0 default:
110  0 throw new IllegalStateException(aAST.toString());
111    }
112    }
113   
114    /** {@inheritDoc} */
 
115  190 toggle public void leaveToken(DetailAST aAST)
116    {
117  190 switch (aAST.getType()) {
118  4 case TokenTypes.CTOR_DEF:
119  12 case TokenTypes.METHOD_DEF:
120  2 case TokenTypes.INSTANCE_INIT:
121  2 case TokenTypes.STATIC_INIT:
122  20 leaveMemberDef(aAST);
123  20 break;