1 20 package com.puppycrawl.tools.checkstyle.checks.whitespace; 21 22 import com.puppycrawl.tools.checkstyle.api.DetailAST; 23 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 24 import com.puppycrawl.tools.checkstyle.api.Utils; 25 import com.puppycrawl.tools.checkstyle.checks.AbstractOption; 26 import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck; 27 28 91 public class OperatorWrapCheck 92 extends AbstractOptionCheck 93 { 94 97 public OperatorWrapCheck() 98 { 99 super(OperatorWrapOption.NL); 100 } 101 102 103 public int[] getDefaultTokens() 104 { 105 return new int[] { 106 TokenTypes.QUESTION, TokenTypes.COLON, TokenTypes.EQUAL, TokenTypes.NOT_EQUAL, TokenTypes.DIV, TokenTypes.PLUS, TokenTypes.MINUS, TokenTypes.STAR, TokenTypes.MOD, TokenTypes.SR, TokenTypes.BSR, TokenTypes.GE, TokenTypes.GT, TokenTypes.SL, TokenTypes.LE, TokenTypes.LT, TokenTypes.BXOR, TokenTypes.BOR, TokenTypes.LOR, TokenTypes.BAND, TokenTypes.LAND, TokenTypes.LITERAL_INSTANCEOF, 128 }; 129 } 130 131 132 public int[] getAcceptableTokens() 133 { 134 return new int[] { 135 TokenTypes.QUESTION, TokenTypes.COLON, TokenTypes.EQUAL, TokenTypes.NOT_EQUAL, TokenTypes.DIV, TokenTypes.PLUS, TokenTypes.MINUS, TokenTypes.STAR, TokenTypes.MOD, TokenTypes.SR, TokenTypes.BSR, TokenTypes.GE, TokenTypes.GT, TokenTypes.SL, TokenTypes.LE, TokenTypes.LT, TokenTypes.BXOR, TokenTypes.BOR, TokenTypes.LOR, TokenTypes.BAND, TokenTypes.LAND, TokenTypes.LITERAL_INSTANCEOF, 157 TokenTypes.ASSIGN, TokenTypes.DIV_ASSIGN, TokenTypes.PLUS_ASSIGN, TokenTypes.MINUS_ASSIGN, TokenTypes.STAR_ASSIGN, TokenTypes.MOD_ASSIGN, TokenTypes.SR_ASSIGN, TokenTypes.BSR_ASSIGN, TokenTypes.SL_ASSIGN, TokenTypes.BXOR_ASSIGN, TokenTypes.BOR_ASSIGN, TokenTypes.BAND_ASSIGN, 170 }; 171 } 172 173 public void visitToken(DetailAST aAST) 174 { 175 if (aAST.getType() == TokenTypes.COLON) { 176 final DetailAST parent = aAST.getParent(); 177 if ((parent.getType() == TokenTypes.LITERAL_DEFAULT) 178 || (parent.getType() == TokenTypes.LITERAL_CASE)) 179 { 180 return; 182 } 183 } 184 final AbstractOption wOp = getAbstractOption(); 185 186 final String text = aAST.getText(); 187 final int colNo = aAST.getColumnNo(); 188 final int lineNo = aAST.getLineNo(); 189 final String currentLine = getLines()[lineNo - 1]; 190 191 if ((wOp == OperatorWrapOption.NL) 196 && !text.equals(currentLine.trim()) 197 && (currentLine.substring(colNo + text.length()) 198 .trim().length() == 0)) 199 { 200 log(lineNo, colNo, "line.new", text); 201 } 202 else if ((wOp == OperatorWrapOption.EOL) 203 && Utils.whitespaceBefore(colNo - 1, currentLine)) 204 { 205 log(lineNo, colNo, "line.previous", text); 206 } 207 } 208 } 209 | Popular Tags |