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 SlistHandler extends BlockParentHandler 30 { 31 39 public SlistHandler(IndentationCheck aIndentCheck, 40 DetailAST aAst, ExpressionHandler aParent) 41 { 42 super(aIndentCheck, "block", aAst, aParent); 43 } 44 45 54 public IndentLevel suggestedChildLevel(ExpressionHandler aChild) 55 { 56 65 if (((getParent() instanceof BlockParentHandler) 67 && !(getParent() instanceof SlistHandler)) 68 || ((getParent() instanceof CaseHandler) 69 && (aChild instanceof SlistHandler))) 70 { 71 return getParent().suggestedChildLevel(aChild); 72 } 73 return super.suggestedChildLevel(aChild); 74 } 75 76 81 protected DetailAST getNonlistChild() 82 { 83 return null; 88 } 89 90 95 protected DetailAST getListChild() 96 { 97 return getMainAst(); 98 } 99 100 105 protected DetailAST getLCurly() 106 { 107 return getMainAst(); 108 } 109 110 115 protected DetailAST getRCurly() 116 { 117 return getMainAst().findFirstToken(TokenTypes.RCURLY); 118 } 119 120 125 protected DetailAST getToplevelAST() 126 { 127 return null; 128 } 129 130 135 private boolean hasBlockParent() 136 { 137 final int parentType = getMainAst().getParent().getType(); 138 return (parentType == TokenTypes.LITERAL_IF) 139 || (parentType == TokenTypes.LITERAL_FOR) 140 || (parentType == TokenTypes.LITERAL_WHILE) 141 || (parentType == TokenTypes.LITERAL_DO) 142 || (parentType == TokenTypes.LITERAL_ELSE) 143 || (parentType == TokenTypes.LITERAL_TRY) 144 || (parentType == TokenTypes.LITERAL_CATCH) 145 || (parentType == TokenTypes.LITERAL_FINALLY) 146 || (parentType == TokenTypes.CTOR_DEF) 147 || (parentType == TokenTypes.METHOD_DEF) 148 || (parentType == TokenTypes.STATIC_INIT); 149 } 150 151 154 public void checkIndentation() 155 { 156 if (hasBlockParent()) { 159 return; 160 } 161 super.checkIndentation(); 162 } 163 } 164 | Popular Tags |