Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
57   339   44   2.71
24   169   0.77   21
21     2.1  
1    
 
  BlockParentHandler       Line # 41 97.1% 0.9705882
44.05 57 44 44 0.77
 
  ( 10 of 31)
 
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.indentation;
20   
21    import com.puppycrawl.tools.checkstyle.api.DetailAST;
22    import com.puppycrawl.tools.checkstyle.api.TokenTypes;
23   
24    /**
25    * Handler for parents of blocks ('if', 'else', 'while', etc).
26    * <P>
27    * The "block" handler classes use a common superclass BlockParentHandler,
28    * employing the Template Method pattern.
29    * <P>
30    * <UL>
31    * <LI>template method to get the lcurly</LI>
32    * <LI>template method to get the rcurly</LI>
33    * <LI>if curlys aren't present, then template method to get expressions
34    * is called</LI>
35    * <LI>now all the repetitous code which checks for BOL, if curlys are on
36    * same line, etc. can be collapsed into the superclass</LI>
37    * </UL>
38    *
39    * @author jrichard
40    */
 
41    public class BlockParentHandler extends ExpressionHandler
42    {
43    /**
44    * Children checked by parent handlers.
45    */
46    private static final int[] CHECKED_CHILDREN = new int[] {
47    TokenTypes.VARIABLE_DEF,
48    TokenTypes.EXPR,
49    TokenTypes.OBJBLOCK,
50    TokenTypes.LITERAL_BREAK,
51    TokenTypes.LITERAL_RETURN,
52    TokenTypes.LITERAL_THROW,
53    TokenTypes.LITERAL_CONTINUE,
54    };
55   
56    /**
57    * Returns array of token types which should be checked among childrens.
58    * @return array of token types to check.
59    */
 
60  445 toggle protected int[] getCheckedChildren()
61    {
62  445 return CHECKED_CHILDREN;
63    }
64   
65    /**
66    * Construct an instance of this handler with the given indentation check,
67    * name, abstract syntax tree, and parent handler.
68    *
69    * @param aIndentCheck the indentation check
70    * @param aName the name of the handler
71    * @param aAst the abstract syntax tree
72    * @param aParent the parent handler
73    */
 
74  1259 toggle public BlockParentHandler(IndentationCheck aIndentCheck,
75    String aName, DetailAST aAst, ExpressionHandler aParent)
76    {
77  1259 super(aIndentCheck, aName, aAst, aParent);
78    }
79   
80    /**
81    * Get the top level expression being managed by this handler.
82    *
83    * @return the top level expression
84    */
 
85  243 toggle protected DetailAST getToplevelAST()
86    {
87  243 return getMainAst();
88    }
89   
90    /**
91    * Check the indent of the top level token.
92    */
 
93  595 toggle protected void checkToplevelToken()
94    {
95  595 final DetailAST toplevel = getToplevelAST();
96   
97  595 if ((toplevel == null)
98    || getLevel().accept(expandedTabsColumnNo(toplevel)))
99    {
100  545 return;
101    }
102  50 if (!toplevelMustStartLine() && !startsLine(toplevel)) {
103  15 return;
104    }
105  35 logError(toplevel, "", expandedTabsColumnNo(toplevel));
106    }
107