1 package com.puppycrawl.tools.checkstyle.checks.blocks; 20 21 import com.puppycrawl.tools.checkstyle.api.Check; 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 import com.puppycrawl.tools.checkstyle.api.DetailAST; 24 25 87 public class AvoidNestedBlocksCheck extends Check 88 { 89 93 private boolean mAllowInSwitchCase; 94 95 96 public int[] getDefaultTokens() 97 { 98 return new int[] {TokenTypes.SLIST}; 99 } 100 101 102 public void visitToken(DetailAST aAST) 103 { 104 final DetailAST parent = aAST.getParent(); 105 if (parent.getType() == TokenTypes.SLIST) { 106 if (mAllowInSwitchCase 107 && (parent.getParent().getType() == TokenTypes.CASE_GROUP) 108 && (parent.getNumberOfChildren() == 1)) 109 { 110 return; 111 } 112 log(aAST.getLineNo(), aAST.getColumnNo(), "block.nested"); 113 } 114 } 115 116 121 public void setAllowInSwitchCase(boolean aAllowInSwitchCase) 122 { 123 mAllowInSwitchCase = aAllowInSwitchCase; 124 } 125 } 126 | Popular Tags |