Create ParseErrorMessage if error message is null. Added comments for a few methods.

This commit is contained in:
Baratali Izmailov 2014-11-24 21:12:48 +03:00 committed by Roman Ivanov
parent 825d1be152
commit be6a7ca77b
2 changed files with 38 additions and 1 deletions

View File

@ -54,6 +54,17 @@ import com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser;
*/
public abstract class AbstractJavadocCheck extends Check
{
/**
* Error message key for common javadoc errors.
*/
private static final String PARSE_ERROR_MESSAGE_KEY = "javadoc.parse.error";
/**
* Unrecognized error from antlr parser
*/
private static final String UNRECOGNIZED_ANTLR_ERROR_MESSAGE_KEY =
"javadoc.unrecognized.antlr.error";
/**
* key is "line:column"
* value is DetailNode tree
@ -115,24 +126,40 @@ public abstract class AbstractJavadocCheck extends Check
{
}
/**
* Defined final to not allow JavadocChecks to change default tokens.
* @return default tokens
*/
@Override
public final int[] getDefaultTokens()
{
return new int[] {TokenTypes.BLOCK_COMMENT_BEGIN };
}
/**
* Defined final to not allow JavadocChecks to change acceptable tokens.
* @return acceptable tokens
*/
@Override
public final int[] getAcceptableTokens()
{
return super.getAcceptableTokens();
}
/**
* Defined final to not allow JavadocChecks to change required tokens.
* @return required tokens
*/
@Override
public final int[] getRequiredTokens()
{
return super.getRequiredTokens();
}
/**
* Defined final because all JavadocChecks require comment nodes.
* @return true
*/
@Override
public final boolean isCommentNodesRequired()
{
@ -142,6 +169,7 @@ public abstract class AbstractJavadocCheck extends Check
@Override
public final void beginTree(DetailAST aRootAST)
{
TREE_CACHE.clear();
}
@Override
@ -217,7 +245,7 @@ public abstract class AbstractJavadocCheck extends Check
catch (IOException e) {
// Antlr can not initiate its ANTLRInputStream
parseErrorMessage = new ParseErrorMessage(aJavadocCommentAst.getLineNo(),
"javadoc.parse.error",
PARSE_ERROR_MESSAGE_KEY,
aJavadocCommentAst.getColumnNo(), e.getMessage());
}
catch (ParseCancellationException e) {
@ -225,6 +253,13 @@ public abstract class AbstractJavadocCheck extends Check
// and parser throws this runtime exception to stop parsing.
// Just stop processing current Javadoc comment.
parseErrorMessage = mErrorListener.getErrorMessage();
// There are cases when antlr error listener does not handle syntax error
if (parseErrorMessage == null) {
parseErrorMessage = new ParseErrorMessage(aJavadocCommentAst.getLineNo(),
UNRECOGNIZED_ANTLR_ERROR_MESSAGE_KEY,
aJavadocCommentAst.getColumnNo(), e.getMessage());
}
}
if (parseErrorMessage == null) {

View File

@ -1,3 +1,5 @@
javadoc.parse.error=Javadoc comment at column {0} has parse error. Details: {1}
javadoc.unrecognized.antlr.error=Javadoc comment at column {0} has parse error. Unrecognized error from ANTLR parser: {1}
javadoc.parse.token.error=Javadoc comment at column {0} has parse error. Details: {1}
javadoc.parse.rule.error=Javadoc comment at column {0} has parse error. Details: {1} while parsing {2}
javadoc.missed.html.close=Javadoc comment at column {0} has parse error. Missed HTML close tag ''{1}''. Sometimes it means that close tag missed for one of previous tags.