|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ClassDefHandler | Line # 29 | 100% |
1.0
|
12 | 21 | 12 | 12 | 0.57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( 10 of 31) | |||
| Result | |||
|
0.92105263
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testInvalidClassDefWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testInvalidClassDefWithChecker
|
1 PASS | |
|
0.8684211
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidClassDefWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidClassDefWithChecker
|
1 PASS | |
|
0.84210527
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidInterfaceDefWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidInterfaceDefWithChecker
|
1 PASS | |
|
0.84210527
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.test15Extensions
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.test15Extensions
|
1 PASS | |
|
0.81578946
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidMethodWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidMethodWithChecker
|
1 PASS | |
|
0.81578946
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidAssignWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidAssignWithChecker
|
1 PASS | |
|
0.81578946
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidBlockWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidBlockWithChecker
|
1 PASS | |
|
0.7631579
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testInvalidBlockWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testInvalidBlockWithChecker
|
1 PASS | |
|
0.7631579
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidDoWhileWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidDoWhileWithChecker
|
1 PASS | |
|
0.7631579
|
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidIfWithChecker
com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheckTest.testValidIfWithChecker
|
1 PASS | |
| 21 tests are not displayed. This report was configured to show the top 10 tests that covered this file. | |||
| 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 class definitions. | |
| 26 | * | |
| 27 | * @author jrichard | |
| 28 | */ | |
| 29 | public class ClassDefHandler extends BlockParentHandler | |
| 30 | { | |
| 31 | /** | |
| 32 | * Construct an instance of this handler with the given indentation check, | |
| 33 | * abstract syntax tree, and parent handler. | |
| 34 | * | |
| 35 | * @param aIndentCheck the indentation check | |
| 36 | * @param aAst the abstract syntax tree | |
| 37 | * @param aParent the parent handler | |
| 38 | */ | |
| 39 | 80 |
public ClassDefHandler(IndentationCheck aIndentCheck, |
| 40 | DetailAST aAst, | |
| 41 | ExpressionHandler aParent) | |
| 42 | { | |
| 43 | 80 | super(aIndentCheck, |
| 44 | 80 | (aAst.getType() == TokenTypes.CLASS_DEF) |
| 45 | 10 | ? "class def" : ((aAst.getType() == TokenTypes.ENUM_DEF) |
| 46 | ? "enum def" : "interface def"), | |
| 47 | aAst, aParent); | |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Get the left curly brace portion of the expression we are handling. | |
| 52 | * | |
| 53 | * @return the left curly brace expression | |
| 54 | */ | |
| 55 | 400 |
protected DetailAST getLCurly() |
| 56 | { | |
| 57 | 400 | return getMainAst().findFirstToken(TokenTypes.OBJBLOCK) |
| 58 | .findFirstToken(TokenTypes.LCURLY); | |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Get the right curly brace portion of the expression we are handling. | |
| 63 | * | |
| 64 | * @return the right curly brace expression | |
| 65 | */ | |
| 66 | 320 |
protected DetailAST getRCurly() |
| 67 | { | |
| 68 | 320 | return getMainAst().findFirstToken(TokenTypes.OBJBLOCK) |
| 69 | .findFirstToken(TokenTypes.RCURLY); | |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * There is no top level expression for this handler. | |
| 74 | * | |
| 75 | * @return null | |
| 76 | */ | |
| 77 | 80 |
protected DetailAST getToplevelAST() |
| 78 | { | |
| 79 | 80 | return null; |
| 80 | // note: ident checked by hand in check indentation; | |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Get the child element representing the list of statements. | |
| 85 | * | |
| 86 | * @return the statement list child | |
| 87 | */ | |
| 88 | 80 |
protected DetailAST getListChild() |
| 89 | { | |
| 90 | 80 | return getMainAst().findFirstToken(TokenTypes.OBJBLOCK); |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Check the indentation of the expression we are handling. | |
| 95 | */ | |
| 96 | 80 |
public void checkIndentation() |
| 97 | { | |
| 98 | // TODO: still need to better deal with the modifiers and "class" | |
| 99 | 80 | checkModifiers(); |
| 100 | ||
| 101 | 80 | final LineSet lines = new LineSet(); |
| 102 | ||
| 103 | // checks that line with class name starts at correct indentation, | |
| 104 | // and following lines (in implements and extends clauses) are | |
| 105 | // indented at least one level | |
| 106 | 80 | final DetailAST ident = getMainAst().findFirstToken(TokenTypes.IDENT); |
| 107 | 80 | final int lineStart = getLineStart(ident); |
| 108 | 80 | if (!getLevel().accept(lineStart)) { |
| 109 | 9 | logError(ident, "ident", lineStart); |
| 110 | } | |
| 111 | ||
| 112 | 80 | lines.addLineAndCol(new Integer(ident.getLineNo()), lineStart); |
| 113 | ||
| 114 | 80 | final DetailAST impl = getMainAst().findFirstToken( |
| 115 | TokenTypes.IMPLEMENTS_CLAUSE); | |
| 116 | 80 | if ((impl != null) && (impl.getFirstChild() != null)) { |
| 117 | 18 | findSubtreeLines(lines, impl, false); |
| 118 | } | |
| 119 | ||
| 120 | 80 | final DetailAST ext = |
| 121 | getMainAst().findFirstToken(TokenTypes.EXTENDS_CLAUSE); | |
| 122 | 80 | if ((ext != null) && (ext.getFirstChild() != null)) { |
| 123 | 20 | findSubtreeLines(lines, ext, false); |
| 124 | } | |
| 125 | ||
| 126 | 80 | checkLinesIndent(ident.getLineNo(), lines.lastLine(), getLevel()); |
| 127 | ||
| 128 | 80 | super.checkIndentation(); |
| 129 | } | |
| 130 | ||
| 131 | /** {@inheritDoc} */ | |
| 132 | 74 |
protected int[] getCheckedChildren() |
| 133 | { | |
| 134 | 74 | return new int[] { |
| 135 | TokenTypes.EXPR, | |
| 136 | TokenTypes.OBJBLOCK, | |
| 137 | TokenTypes.LITERAL_BREAK, | |
| 138 | TokenTypes.LITERAL_RETURN, | |
| 139 | TokenTypes.LITERAL_THROW, | |
| 140 | TokenTypes.LITERAL_CONTINUE, | |
| 141 | }; | |
| 142 | } | |
| 143 | ||
| 144 | } | |
|
|||||||||||||