1 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 29 public class ClassDefHandler extends BlockParentHandler 30 { 31 39 public ClassDefHandler(IndentationCheck aIndentCheck, 40 DetailAST aAst, 41 ExpressionHandler aParent) 42 { 43 super(aIndentCheck, 44 (aAst.getType() == TokenTypes.CLASS_DEF) 45 ? "class def" : ((aAst.getType() == TokenTypes.ENUM_DEF) 46 ? "enum def" : "interface def"), 47 aAst, aParent); 48 } 49 50 55 protected DetailAST getLCurly() 56 { 57 return getMainAst().findFirstToken(TokenTypes.OBJBLOCK) 58 .findFirstToken(TokenTypes.LCURLY); 59 } 60 61 66 protected DetailAST getRCurly() 67 { 68 return getMainAst().findFirstToken(TokenTypes.OBJBLOCK) 69 .findFirstToken(TokenTypes.RCURLY); 70 } 71 72 77 protected DetailAST getToplevelAST() 78 { 79 return null; 80 } 82 83 88 protected DetailAST getListChild() 89 { 90 return getMainAst().findFirstToken(TokenTypes.OBJBLOCK); 91 } 92 93 96 public void checkIndentation() 97 { 98 checkModifiers(); 100 101 final LineSet lines = new LineSet(); 102 103 final DetailAST ident = getMainAst().findFirstToken(TokenTypes.IDENT); 107 final int lineStart = getLineStart(ident); 108 if (!getLevel().accept(lineStart)) { 109 logError(ident, "ident", lineStart); 110 } 111 112 lines.addLineAndCol(new Integer (ident.getLineNo()), lineStart); 113 114 final DetailAST impl = getMainAst().findFirstToken( 115 TokenTypes.IMPLEMENTS_CLAUSE); 116 if ((impl != null) && (impl.getFirstChild() != null)) { 117 findSubtreeLines(lines, impl, false); 118 } 119 120 final DetailAST ext = 121 getMainAst().findFirstToken(TokenTypes.EXTENDS_CLAUSE); 122 if ((ext != null) && (ext.getFirstChild() != null)) { 123 findSubtreeLines(lines, ext, false); 124 } 125 126 checkLinesIndent(ident.getLineNo(), lines.lastLine(), getLevel()); 127 128 super.checkIndentation(); 129 } 130 131 132 protected int[] getCheckedChildren() 133 { 134 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 } 145 | Popular Tags |