Skip to content

Commit

Permalink
Issue #2836: moved error message fields to the check that reports them
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Jan 21, 2016
1 parent b199c03 commit 28da7d5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 46 deletions.
Expand Up @@ -31,31 +31,6 @@
* @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.
*/
Expand Down Expand Up @@ -162,9 +137,9 @@ protected final void logError(DetailAST ast, String subtypeName,
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);
Expand All @@ -180,9 +155,9 @@ protected final void logError(DetailAST ast, String subtypeName,
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);
Expand Down
Expand Up @@ -80,6 +80,30 @@
* @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;

Expand Down
Expand Up @@ -37,12 +37,6 @@
*/
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
Expand Down Expand Up @@ -269,14 +263,14 @@ private void logWarningMessage(DetailAST currentNode, int currentIndent) {
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);
}
}
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -555,11 +560,6 @@ private void walk(DetailNode root) {
*/
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
Expand Down
Expand Up @@ -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;

Expand Down

0 comments on commit 28da7d5

Please sign in to comment.