Skip to content

Commit

Permalink
Issue checkstyle#7734: Update AbstractChecks to log DetailAST - Inden…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
Abhishek-kumar09 committed Apr 5, 2020
1 parent 5562feb commit 9be34f1
Show file tree
Hide file tree
Showing 5 changed files with 574 additions and 570 deletions.
Expand Up @@ -127,10 +127,11 @@ public void testCorrectChained() throws Exception {
@Test
public void testWarnChained() throws Exception {
final String[] expected = {
"18: " + getCheckMessage(IndentationCheck.class, MSG_CHILD_ERROR, "method call", 4, 8),
"23: " + getCheckMessage(IndentationCheck.class, MSG_ERROR, ".", 4, 8),
"24: " + getCheckMessage(IndentationCheck.class, MSG_ERROR, ".", 4, 8),
"27: " + getCheckMessage(IndentationCheck.class, MSG_ERROR, "new", 4, 8),
"18:5: " + getCheckMessage(IndentationCheck.class,
MSG_CHILD_ERROR, "method call", 4, 8),
"23:5: " + getCheckMessage(IndentationCheck.class, MSG_ERROR, ".", 4, 8),
"24:5: " + getCheckMessage(IndentationCheck.class, MSG_ERROR, ".", 4, 8),
"27:5: " + getCheckMessage(IndentationCheck.class, MSG_ERROR, "new", 4, 8),
};

final Configuration checkConfig = getModuleConfig("Indentation");
Expand Down
Expand Up @@ -143,25 +143,26 @@ protected final void logError(DetailAST ast, String subtypeName,
if (expectedIndent.isMultiLevel()) {
messageKey = IndentationCheck.MSG_ERROR_MULTI;
}
indentCheck.indentationLog(ast.getLineNo(), messageKey,
indentCheck.indentationLog(ast.getLineNo(), ast.getColumnNo(), messageKey,
typeName + typeStr, actualIndent, expectedIndent);
}

/**
* Log child indentation error.
*
* @param line the expression that caused the error
* @param column the position that caused the error
* @param actualIndent the actual indent level of the expression
* @param expectedIndent the expected indent level of the expression
*/
private void logChildError(int line,
private void logChildError(int line, int column,
int actualIndent,
IndentLevel expectedIndent) {
String messageKey = IndentationCheck.MSG_CHILD_ERROR;
if (expectedIndent.isMultiLevel()) {
messageKey = IndentationCheck.MSG_CHILD_ERROR_MULTI;
}
indentCheck.indentationLog(line, messageKey,
indentCheck.indentationLog(line, column, messageKey,
typeName, actualIndent, expectedIndent);
}

Expand Down Expand Up @@ -316,7 +317,7 @@ private void checkLineIndent(int lineNum, int colNum,
// the correct indentation level
if (mustMatch && !indentLevel.isAcceptable(start)
|| !mustMatch && colNum == start && indentLevel.isGreaterThan(start)) {
logChildError(lineNum, start, indentLevel);
logChildError(lineNum, colNum, start, indentLevel);
}
}

Expand Down
Expand Up @@ -451,15 +451,16 @@ public void setLineWrappingIndentation(int lineWrappingIndentation) {
* Log a violation message.
*
* @param line the line number where the violation was found
* @param column the column number where the violation was found
* @param key the message that describes the violation
* @param args the details of the message
*
* @see java.text.MessageFormat
*/
public void indentationLog(int line, String key, Object... args) {
public void indentationLog(int line, int column, String key, Object... args) {
if (!incorrectIndentationLines.contains(line)) {
incorrectIndentationLines.add(line);
log(line, key, args);
log(line, column, key, args);
}
}

Expand Down
Expand Up @@ -354,14 +354,14 @@ private int getLineStart(String line) {
private void logWarningMessage(DetailAST currentNode, int currentIndent) {
if (indentCheck.isForceStrictCondition()) {
if (expandedTabsColumnNo(currentNode) != currentIndent) {
indentCheck.indentationLog(currentNode.getLineNo(),
indentCheck.indentationLog(currentNode.getLineNo(), currentNode.getColumnNo(),
IndentationCheck.MSG_ERROR, currentNode.getText(),
expandedTabsColumnNo(currentNode), currentIndent);
}
}
else {
if (expandedTabsColumnNo(currentNode) < currentIndent) {
indentCheck.indentationLog(currentNode.getLineNo(),
indentCheck.indentationLog(currentNode.getLineNo(), currentNode.getColumnNo(),
IndentationCheck.MSG_ERROR, currentNode.getText(),
expandedTabsColumnNo(currentNode), currentIndent);
}
Expand Down

0 comments on commit 9be34f1

Please sign in to comment.