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.AbstractOptionCheck; 26 import com.puppycrawl.tools.checkstyle.checks.AbstractOption; 27 28 51 public class EmptyForInitializerPadCheck 52 extends AbstractOptionCheck 53 { 54 57 public EmptyForInitializerPadCheck() 58 { 59 super(PadOption.NOSPACE); 60 } 61 62 63 public int[] getDefaultTokens() 64 { 65 return new int[] {TokenTypes.FOR_INIT, 66 }; 67 } 68 69 70 public void visitToken(DetailAST aAST) 71 { 72 if (aAST.getChildCount() == 0) { 73 final DetailAST semi = (DetailAST) aAST.getNextSibling(); 75 final int semiLineIdx = semi.getLineNo() - 1; 76 final String line = getLines()[semiLineIdx]; 77 final int before = semi.getColumnNo() - 1; 78 if (!Utils.whitespaceBefore(before, line)) { 80 final AbstractOption abstractOption = getAbstractOption(); 81 if ((PadOption.NOSPACE == abstractOption) 82 && (Character.isWhitespace(line.charAt(before)))) 83 { 84 log(semi.getLineNo(), before, "ws.preceded", ";"); 85 } 86 else if ((PadOption.SPACE == abstractOption) 87 && !Character.isWhitespace(line.charAt(before))) 88 { 89 log(semi.getLineNo(), before, "ws.notPreceded", ";"); 90 } 91 } 92 } 93 } 94 } 95 | Popular Tags |