1 package com.puppycrawl.tools.checkstyle.checks.whitespace; 20 21 import com.puppycrawl.tools.checkstyle.api.DetailAST; 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 import com.puppycrawl.tools.checkstyle.api.Utils; 24 import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck; 25 26 64 65 public class MethodParamPadCheck 66 extends AbstractOptionCheck 67 { 68 71 public MethodParamPadCheck() 72 { 73 super(PadOption.NOSPACE); 74 } 75 76 78 private boolean mAllowLineBreaks; 79 80 81 public int[] getDefaultTokens() 82 { 83 return new int[] { 84 TokenTypes.CTOR_DEF, 85 TokenTypes.LITERAL_NEW, 86 TokenTypes.METHOD_CALL, 87 TokenTypes.METHOD_DEF, 88 TokenTypes.SUPER_CTOR_CALL, 89 }; 90 } 91 92 93 public void visitToken(DetailAST aAST) 94 { 95 final DetailAST parenAST; 96 if ((aAST.getType() == TokenTypes.METHOD_CALL)) { 97 parenAST = aAST; 98 } 99 else { 100 parenAST = aAST.findFirstToken(TokenTypes.LPAREN); 101 if (parenAST == null) { 103 return; 104 } 105 } 106 107 final String line = getLines()[parenAST.getLineNo() - 1]; 108 if (Utils.whitespaceBefore(parenAST.getColumnNo(), line)) { 109 if (!mAllowLineBreaks) { 110 log(parenAST, "line.previous", parenAST.getText()); 111 } 112 } 113 else { 114 final int before = parenAST.getColumnNo() - 1; 115 if ((PadOption.NOSPACE == getAbstractOption()) 116 && (Character.isWhitespace(line.charAt(before)))) 117 { 118 log(parenAST , "ws.preceded", parenAST.getText()); 119 } 120 else if ((PadOption.SPACE == getAbstractOption()) 121 && !Character.isWhitespace(line.charAt(before))) 122 { 123 log(parenAST, "ws.notPreceded", parenAST.getText()); 124 } 125 } 126 } 127 128 133 public void setAllowLineBreaks(boolean aAllowLineBreaks) 134 { 135 mAllowLineBreaks = aAllowLineBreaks; 136 } 137 } 138 | Popular Tags |