Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../../img/srcFileCovDistChart8.png 75% of files have more coverage
6   69   3   2
0   23   0.5   3
3     1  
1    
 
  MissingSwitchDefaultCheck       Line # 45 77.8% 0.7777778
3.1 6 3 3 0.5
 
  (1)
 
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 com.puppycrawl.tools.checkstyle.api.TokenTypes;
22    import com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck;
23   
24    /**
25    * <p>
26    * Checks that switch statement has &quot;default&quot; clause.
27    * </p>
28    * <p>
29    * Rationale: It's usually a good idea to introduce a
30    * default case in every switch statement. Even if
31    * the developer is sure that all currently possible
32    * cases are covered, this should be expressed in the
33    * default branch, e.g. by using an assertion. This way
34    * the code is protected aginst later changes, e.g.
35    * introduction of new types in an enumeration type.
36    * </p>
37    * <p>
38    * An example of how to configure the check is:
39    * </p>
40    * <pre>
41    * &lt;module name="MissingSwitchDefault"/&gt;
42    * </pre>
43    * @author o_sukhodolsky
44    */
 
45    public class MissingSwitchDefaultCheck extends DescendantTokenCheck
46    {
47    /** Creates new instance of the check. */
 
48  1 toggle public MissingSwitchDefaultCheck()
49    {
50  1 setLimitedTokens(new String[] {
51    TokenTypes.getTokenName(TokenTypes.LITERAL_DEFAULT),
52    });
53  1 setMinimumNumber(1);
54  1 setMaximumDepth(2);
55  1 setMinimumMessage("missing.switch.default");
56    }
57   
58    /** {@inheritDoc} */
 
59  1 toggle public int[] getDefaultTokens()
60    {
61  1 return new int[]{TokenTypes.LITERAL_SWITCH};
62    }
63   
64    /** {@inheritDoc} */
 
65  0 toggle public int[] getAcceptableTokens()
66    {
67  0 return getDefaultTokens();
68    }
69    }