private void checkForReport(StatementTree statement, Tree startTree, Tree endTree, String name) { if (!(statement.is(Tree.Kind.BLOCK) || statement.firstToken().column() > startTree.firstToken().column())) { context.reportIssue(this, startTree, endTree, "Use indentation to denote the code conditionally executed by this \"" + name + "\".", Collections.singletonList(new JavaFileScannerContext.Location("", statement)), null); } } }
private void checkForReport(StatementTree statement, Tree startTree, Tree endTree, String name) { if (!(statement.is(Tree.Kind.BLOCK) || statement.firstToken().column() > startTree.firstToken().column())) { context.reportIssue(this, startTree, endTree, "Use indentation to denote the code conditionally executed by this \"" + name + "\".", Collections.singletonList(new JavaFileScannerContext.Location("", statement)), null); } } }
private boolean isSameLine(IfStatementTree ifStmt) { StatementTree thenStmt = ifStmt.thenStatement(); if (thenStmt.is(Tree.Kind.BLOCK)) { return false; } return ifStmt.firstToken().line() == thenStmt.firstToken().line(); }
private void check(StatementTree current, StatementTree previous) { StatementTree block = null; boolean condition = false; if (previous.is(Tree.Kind.FOR_EACH_STATEMENT)) { block = ((ForEachStatement) previous).statement(); } else if (previous.is(Tree.Kind.FOR_STATEMENT)) { block = ((ForStatementTree) previous).statement(); } else if (previous.is(Tree.Kind.WHILE_STATEMENT)) { block = ((WhileStatementTree) previous).statement(); } else if (previous.is(Tree.Kind.IF_STATEMENT)) { block = getIfStatementLastBlock(previous); condition = true; } if (block != null && !block.is(Tree.Kind.BLOCK)) { SyntaxToken previousToken = block.firstToken(); int previousColumn = previousToken.column(); int previousLine = previousToken.line(); SyntaxToken currentToken = current.firstToken(); int currentColumn = currentToken.column(); int currentLine = currentToken.line(); if ((previousColumn == currentColumn && previousLine + 1 == currentLine) || (previousLine == previous.firstToken().line() && previous.firstToken().column() < currentColumn)) { int lines = 1 + currentLine - previousLine; context.reportIssue(this, current, getMessage(condition, lines)); } } }
private void check(StatementTree current, StatementTree previous) { StatementTree block = null; boolean condition = false; if (previous.is(Tree.Kind.FOR_EACH_STATEMENT)) { block = ((ForEachStatement) previous).statement(); } else if (previous.is(Tree.Kind.FOR_STATEMENT)) { block = ((ForStatementTree) previous).statement(); } else if (previous.is(Tree.Kind.WHILE_STATEMENT)) { block = ((WhileStatementTree) previous).statement(); } else if (previous.is(Tree.Kind.IF_STATEMENT)) { block = getIfStatementLastBlock(previous); condition = true; } if (block != null && !block.is(Tree.Kind.BLOCK)) { SyntaxToken previousToken = block.firstToken(); int previousColumn = previousToken.column(); int previousLine = previousToken.line(); SyntaxToken currentToken = current.firstToken(); int currentColumn = currentToken.column(); int currentLine = currentToken.line(); if ((previousColumn == currentColumn && previousLine + 1 == currentLine) || (previousLine == previous.firstToken().line() && previous.firstToken().column() < currentColumn)) { int lines = 1 + currentLine - previousLine; context.reportIssue(this, current, getMessage(condition, lines)); } } }