Skip to content

Commit

Permalink
Issue checkstyle#10924: Refactor NoWhitespaceBeforeCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MUzairS15 committed Mar 16, 2022
1 parent 7697df3 commit 2aa0429
Showing 1 changed file with 5 additions and 8 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CodePointUtil;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

/**
Expand Down Expand Up @@ -209,19 +210,15 @@ public int[] getRequiredTokens() {

@Override
public void visitToken(DetailAST ast) {
final String line = getLine(ast.getLineNo() - 1);
final int[] line = getLineCodePoints(ast.getLineNo() - 1);
final int before = ast.getColumnNo() - 1;
final int[] codePoints = line.codePoints().toArray();

if ((before == -1 || CommonUtil.isCodePointWhitespace(codePoints, before))
if ((before == -1 || CommonUtil.isCodePointWhitespace(line, before))
&& !isInEmptyForInitializerOrCondition(ast)) {
boolean flag = !allowLineBreaks;
// verify all characters before '.' are whitespace
for (int i = 0; i <= before - 1; i++) {
if (!CommonUtil.isCodePointWhitespace(codePoints, i)) {
flag = true;
break;
}
if (before > -1 && !CodePointUtil.hasWhitespaceBefore(before, line)) {
flag = true;
}
if (flag) {
log(ast, MSG_KEY, ast.getText());
Expand Down

0 comments on commit 2aa0429

Please sign in to comment.