Issue #2836: moved error message fields to the check that reports them

This commit is contained in:
rnveach 2016-01-20 14:36:49 -05:00 committed by Roman Ivanov
parent b199c033b7
commit 28da7d5666
5 changed files with 39 additions and 46 deletions

View File

@ -31,31 +31,6 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
* @author jrichard
*/
public abstract class AbstractExpressionHandler {
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_ERROR = "indentation.error";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_ERROR_MULTI = "indentation.error.multi";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_CHILD_ERROR = "indentation.child.error";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_CHILD_ERROR_MULTI = "indentation.child.error.multi";
/**
* The instance of {@code IndentationCheck} using this handler.
*/
@ -162,9 +137,9 @@ public abstract class AbstractExpressionHandler {
else {
typeStr = " " + subtypeName;
}
String messageKey = MSG_ERROR;
String messageKey = IndentationCheck.MSG_ERROR;
if (expectedIndent.isMultiLevel()) {
messageKey = MSG_ERROR_MULTI;
messageKey = IndentationCheck.MSG_ERROR_MULTI;
}
indentCheck.indentationLog(ast.getLineNo(), messageKey,
typeName + typeStr, actualIndent, expectedIndent);
@ -180,9 +155,9 @@ public abstract class AbstractExpressionHandler {
private void logChildError(int line,
int actualIndent,
IndentLevel expectedIndent) {
String messageKey = MSG_CHILD_ERROR;
String messageKey = IndentationCheck.MSG_CHILD_ERROR;
if (expectedIndent.isMultiLevel()) {
messageKey = MSG_CHILD_ERROR_MULTI;
messageKey = IndentationCheck.MSG_CHILD_ERROR_MULTI;
}
indentCheck.indentationLog(line, messageKey,
typeName, actualIndent, expectedIndent);

View File

@ -80,6 +80,30 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
* @author maxvetrenko
*/
public class IndentationCheck extends Check {
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_ERROR = "indentation.error";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_ERROR_MULTI = "indentation.error.multi";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_CHILD_ERROR = "indentation.child.error";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_CHILD_ERROR_MULTI = "indentation.child.error.multi";
/** Default indentation amount - based on Sun. */
private static final int DEFAULT_INDENTATION = 4;

View File

@ -37,12 +37,6 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
*/
public class LineWrappingHandler {
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
private static final String MSG_INDENTATION_ERROR = "indentation.error";
/**
* The current instance of {@code IndentationCheck} class using this
* handler. This field used to get access to private fields of
@ -269,14 +263,14 @@ public class LineWrappingHandler {
if (forceStrictCondition) {
if (currentNode.getColumnNo() != currentIndent) {
indentCheck.indentationLog(currentNode.getLineNo(),
MSG_INDENTATION_ERROR, currentNode.getText(),
IndentationCheck.MSG_ERROR, currentNode.getText(),
currentNode.getColumnNo(), currentIndent);
}
}
else {
if (currentNode.getColumnNo() < currentIndent) {
indentCheck.indentationLog(currentNode.getLineNo(),
MSG_INDENTATION_ERROR, currentNode.getText(),
IndentationCheck.MSG_ERROR, currentNode.getText(),
currentNode.getColumnNo(), currentIndent);
}
}

View File

@ -74,6 +74,11 @@ public abstract class AbstractJavadocCheck extends Check {
public static final String MSG_JAVADOC_WRONG_SINGLETON_TAG =
"javadoc.wrong.singleton.html.tag";
/**
* Parse error while rule recognition.
*/
public static final String MSG_JAVADOC_PARSE_RULE_ERROR = "javadoc.parse.rule.error";
/**
* Key is "line:column". Value is {@link DetailNode} tree. Map is stored in {@link ThreadLocal}
* to guarantee basic thread safety and avoid shared, mutable state when not necessary.
@ -555,11 +560,6 @@ public abstract class AbstractJavadocCheck extends Check {
*/
private static class DescriptiveErrorListener extends BaseErrorListener {
/**
* Parse error while rule recognition.
*/
private static final String MSG_JAVADOC_PARSE_RULE_ERROR = "javadoc.parse.rule.error";
/**
* Offset is line number of beginning of the Javadoc comment. Log
* messages should have line number in scope of file, not in scope of

View File

@ -19,10 +19,10 @@
package com.puppycrawl.tools.checkstyle.checks.indentation;
import static com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler.MSG_CHILD_ERROR;
import static com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler.MSG_CHILD_ERROR_MULTI;
import static com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler.MSG_ERROR;
import static com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler.MSG_ERROR_MULTI;
import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR;
import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR_MULTI;
import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR;
import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR_MULTI;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;