1 package com.puppycrawl.tools.checkstyle.checks.indentation; 20 21 import com.puppycrawl.tools.checkstyle.api.Check; 22 import com.puppycrawl.tools.checkstyle.api.DetailAST; 23 import com.puppycrawl.tools.checkstyle.api.ScopeUtils; 24 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 25 26 import org.apache.commons.collections.ArrayStack; 27 28 30 33 36 41 55 56 110 111 public class IndentationCheck extends Check 112 { 113 114 private static final int DEFAULT_INDENTATION = 4; 115 116 117 private int mBasicOffset = DEFAULT_INDENTATION; 118 119 120 private int mCaseIndentationAmount = DEFAULT_INDENTATION; 121 122 123 private int mBraceAdjustment; 124 125 126 private final ArrayStack mHandlers = new ArrayStack(); 127 128 129 private final HandlerFactory mHandlerFactory = new HandlerFactory(); 130 131 132 public IndentationCheck() 133 { 134 } 135 136 141 public void setBasicOffset(int aBasicOffset) 142 { 143 mBasicOffset = aBasicOffset; 144 } 145 146 151 public int getBasicOffset() 152 { 153 return mBasicOffset; 154 } 155 156 161 public void setBraceAdjustment(int aAdjustmentAmount) 162 { 163 mBraceAdjustment = aAdjustmentAmount; 164 } 165 166 171 public int getBraceAdjustement() 172 { 173 return mBraceAdjustment; 174 } 175 176 181 public void setCaseIndent(int aAmount) 182 { 183 mCaseIndentationAmount = aAmount; 184 } 185 186 191 public int getCaseIndent() 192 { 193 return mCaseIndentationAmount; 194 } 195 196 205 public void indentationLog(int aLine, String aKey, Object [] aArgs) 206 { 207 super.log(aLine, aKey, aArgs); 208 } 209 210 215 public int getIndentationTabWidth() 216 { 217 return getTabWidth(); 218 } 219 220 225 public int[] getDefaultTokens() 226 { 227 return mHandlerFactory.getHandledTypes(); 228 } 229 230 233 public void beginTree(DetailAST aAst) 234 { 235 mHandlerFactory.clearCreatedHandlers(); 236 mHandlers.clear(); 237 mHandlers.push(new PrimordialHandler(this)); 238 } 239 240 243 public void visitToken(DetailAST aAST) 244 { 245 if ((aAST.getType() == TokenTypes.VARIABLE_DEF) 246 && ScopeUtils.isLocalVariableDef(aAST)) 247 { 248 return; 250 } 251 252 final ExpressionHandler handler = mHandlerFactory.getHandler(this, aAST, 253 (ExpressionHandler) mHandlers.peek()); 254 mHandlers.push(handler); 255 try { 256 handler.checkIndentation(); 257 } 258 catch (final NullPointerException npe) { 259 npe.printStackTrace(); 260 } 261 } 262 263 266 public void leaveToken(DetailAST aAST) 267 { 268 if ((aAST.getType() == TokenTypes.VARIABLE_DEF) 269 && ScopeUtils.isLocalVariableDef(aAST)) 270 { 271 return; 273 } 274 mHandlers.pop(); 275 } 276 277 282 final HandlerFactory getHandlerFactory() 283 { 284 return mHandlerFactory; 285 } 286 } 287 | Popular Tags |