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 ForHandler extends BlockParentHandler 30 { 31 39 public ForHandler(IndentationCheck aIndentCheck, 40 DetailAST aAst, ExpressionHandler aParent) 41 { 42 super(aIndentCheck, "for", aAst, aParent); 43 } 44 45 48 private void checkForParams() 49 { 50 final IndentLevel expected = 51 new IndentLevel(getLevel(), getBasicOffset()); 52 final DetailAST init = getMainAst().findFirstToken(TokenTypes.FOR_INIT); 53 54 if (init != null) { 55 checkExpressionSubtree(init, expected, false, false); 56 57 final DetailAST cond = 58 getMainAst().findFirstToken(TokenTypes.FOR_CONDITION); 59 checkExpressionSubtree(cond, expected, false, false); 60 61 final DetailAST iter = 62 getMainAst().findFirstToken(TokenTypes.FOR_ITERATOR); 63 checkExpressionSubtree(iter, expected, false, false); 64 } 65 else { 67 final DetailAST forEach = 68 getMainAst().findFirstToken(TokenTypes.FOR_EACH_CLAUSE); 69 checkExpressionSubtree(forEach, expected, false, false); 70 } 71 } 72 73 76 public void checkIndentation() 77 { 78 checkForParams(); 79 super.checkIndentation(); 80 } 81 82 91 public IndentLevel suggestedChildLevel(ExpressionHandler aChild) 92 { 93 if (aChild instanceof ElseHandler) { 94 return getLevel(); 95 } 96 return super.suggestedChildLevel(aChild); 97 } 98 } 99 | Popular Tags |