1 20 package com.puppycrawl.tools.checkstyle.checks.whitespace; 21 22 import com.puppycrawl.tools.checkstyle.api.Check; 23 import com.puppycrawl.tools.checkstyle.api.DetailAST; 24 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 25 26 64 public class NoWhitespaceAfterCheck extends Check 65 { 66 67 private boolean mAllowLineBreaks = true; 68 69 70 public int[] getDefaultTokens() 71 { 72 return new int[] { 73 TokenTypes.ARRAY_INIT, 74 TokenTypes.INC, 75 TokenTypes.DEC, 76 TokenTypes.UNARY_MINUS, 77 TokenTypes.UNARY_PLUS, 78 TokenTypes.BNOT, 79 TokenTypes.LNOT, 80 TokenTypes.DOT, 81 }; 82 } 83 84 85 public int[] getAcceptableTokens() 86 { 87 return new int[] { 88 TokenTypes.ARRAY_INIT, 89 TokenTypes.INC, 90 TokenTypes.DEC, 91 TokenTypes.UNARY_MINUS, 92 TokenTypes.UNARY_PLUS, 93 TokenTypes.BNOT, 94 TokenTypes.LNOT, 95 TokenTypes.DOT, 96 TokenTypes.TYPECAST, 97 }; 98 } 99 100 101 public void visitToken(DetailAST aAST) 102 { 103 DetailAST targetAST = aAST; 104 if (targetAST.getType() == TokenTypes.TYPECAST) { 105 targetAST = targetAST.findFirstToken(TokenTypes.RPAREN); 106 } 107 final String line = getLines()[aAST.getLineNo() - 1]; 108 final int after = 109 targetAST.getColumnNo() + targetAST.getText().length(); 110 111 if ((after >= line.length()) 112 || Character.isWhitespace(line.charAt(after))) 113 { 114 boolean flag = !mAllowLineBreaks; 115 for (int i = after + 1; !flag && (i < line.length()); i++) { 116 if (!Character.isWhitespace(line.charAt(i))) { 117 flag = true; 118 } 119 } 120 if (flag) { 121 log(targetAST.getLineNo(), after, 122 "ws.followed", targetAST.getText()); 123 } 124 } 125 } 126 127 132 public void setAllowLineBreaks(boolean aAllowLineBreaks) 133 { 134 mAllowLineBreaks = aAllowLineBreaks; 135 } 136 } 137 | Popular Tags |