1 20 package com.puppycrawl.tools.checkstyle.checks.blocks; 21 22 23 import com.puppycrawl.tools.checkstyle.api.Check; 24 import com.puppycrawl.tools.checkstyle.api.DetailAST; 25 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 26 27 56 public class NeedBracesCheck extends Check 57 { 58 59 public int[] getDefaultTokens() 60 { 61 return new int[] { 62 TokenTypes.LITERAL_DO, 63 TokenTypes.LITERAL_ELSE, 64 TokenTypes.LITERAL_FOR, 65 TokenTypes.LITERAL_IF, 66 TokenTypes.LITERAL_WHILE, 67 }; 68 } 69 70 71 public void visitToken(DetailAST aAST) 72 { 73 final DetailAST slistAST = aAST.findFirstToken(TokenTypes.SLIST); 74 boolean isElseIf = false; 75 if ((aAST.getType() == TokenTypes.LITERAL_ELSE) 76 && (aAST.findFirstToken(TokenTypes.LITERAL_IF) != null)) 77 { 78 isElseIf = true; 79 } 80 if ((slistAST == null) && !isElseIf) { 81 log(aAST.getLineNo(), "needBraces", aAST.getText()); 82 } 83 } 84 } 85 | Popular Tags |