1 package com.puppycrawl.tools.checkstyle.checks.whitespace; 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 55 public class WhitespaceAfterCheck 56 extends Check 57 { 58 59 public int[] getDefaultTokens() 60 { 61 return new int[] { 62 TokenTypes.COMMA, 63 TokenTypes.SEMI, 64 TokenTypes.TYPECAST, 65 }; 66 } 67 68 69 public void visitToken(DetailAST aAST) 70 { 71 final Object [] message; 72 final DetailAST targetAST; 73 if (aAST.getType() == TokenTypes.TYPECAST) { 74 targetAST = aAST.findFirstToken(TokenTypes.RPAREN); 75 message = new Object []{"cast"}; 77 } 78 else { 79 targetAST = aAST; 80 message = new Object []{aAST.getText()}; 81 } 82 final String line = getLines()[targetAST.getLineNo() - 1]; 83 final int after = 84 targetAST.getColumnNo() + targetAST.getText().length(); 85 86 if (after < line.length()) { 87 88 final char charAfter = line.charAt(after); 89 if ((targetAST.getType() == TokenTypes.SEMI) 90 && ((charAfter == ';') || (charAfter == ')'))) 91 { 92 return; 93 } 94 if (!Character.isWhitespace(charAfter)) { 95 if (targetAST.getType() == TokenTypes.SEMI) { 97 final DetailAST sibling = 98 (DetailAST) targetAST.getNextSibling(); 99 if ((sibling != null) 100 && (sibling.getType() == TokenTypes.FOR_ITERATOR) 101 && (sibling.getChildCount() == 0)) 102 { 103 return; 104 } 105 } 106 log(targetAST.getLineNo(), 107 targetAST.getColumnNo() + targetAST.getText().length(), 108 "ws.notFollowed", 109 message); 110 } 111 } 112 } 113 } 114 | Popular Tags |