Issue #1566: MultipleStringLiterals violations fixed
This commit is contained in:
parent
8aec5bba7e
commit
085ce12db0
|
|
@ -319,6 +319,7 @@
|
|||
<module name="AvoidInlineConditionals"/>
|
||||
<module name="IllegalType"/>
|
||||
<module name="TrailingComment"/>
|
||||
<module name="MultipleStringLiterals"/>
|
||||
|
||||
<!--
|
||||
<module name="ClassDataAbstractionCoupling"/>
|
||||
|
|
@ -330,7 +331,6 @@
|
|||
<module name="JavadocTagContinuationIndentation"/>
|
||||
<module name="JavaNCSS"/>
|
||||
<module name="MissingCtor"/>
|
||||
<module name="MultipleStringLiterals"/>
|
||||
<module name="NPathComplexity"/>
|
||||
<module name="OneTopLevelClass"/>
|
||||
<module name="OverloadMethodsDeclarationOrder"/>
|
||||
|
|
|
|||
|
|
@ -67,4 +67,7 @@
|
|||
<!-- Till https://github.com/checkstyle/checkstyle/issues/1854 -->
|
||||
<suppress checks="TrailingComment" files="(InnerAssignmentCheck\.java|OperatorWrapCheck\.java|XMLLoggerTest\.java|AbbreviationAsWordInNameCheckTest\.java)"/>
|
||||
|
||||
<!-- Fixing these cases will decrease code readability -->
|
||||
<suppress checks="MultipleStringLiterals" files="JavadocStyleCheck\.java|AbstractTypeAwareCheck\.java|XMLLogger\.java"/>
|
||||
<suppress checks="MultipleStringLiterals" files=".*[\\/]src[\\/]test[\\/]"/>
|
||||
</suppressions>
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ public final class ConfigurationLoader {
|
|||
private static final String UNABLE_TO_PARSE_EXCEPTION_PREFIX = "unable to parse"
|
||||
+ " configuration stream";
|
||||
|
||||
/** Dollar sign literal. */
|
||||
private static final char DOLLAR_SIGN = '$';
|
||||
|
||||
/** The SAX document handler */
|
||||
private final InternalLoader saxHandler;
|
||||
|
||||
|
|
@ -261,9 +264,9 @@ public final class ConfigurationLoader {
|
|||
return loader.configuration;
|
||||
}
|
||||
catch (final SAXParseException e) {
|
||||
throw new CheckstyleException(UNABLE_TO_PARSE_EXCEPTION_PREFIX
|
||||
+ " - " + e.getMessage() + ":" + e.getLineNumber()
|
||||
+ ":" + e.getColumnNumber(), e);
|
||||
final String message = String.format("%s - %s:%s:%s", UNABLE_TO_PARSE_EXCEPTION_PREFIX,
|
||||
e.getMessage(), e.getLineNumber(), e.getColumnNumber());
|
||||
throw new CheckstyleException(message, e);
|
||||
}
|
||||
catch (final ParserConfigurationException | IOException | SAXException e) {
|
||||
throw new CheckstyleException(UNABLE_TO_PARSE_EXCEPTION_PREFIX, e);
|
||||
|
|
@ -352,7 +355,7 @@ public final class ConfigurationLoader {
|
|||
throws CheckstyleException {
|
||||
int prev = 0;
|
||||
//search for the next instance of $ from the 'prev' position
|
||||
int pos = value.indexOf('$', prev);
|
||||
int pos = value.indexOf(DOLLAR_SIGN, prev);
|
||||
while (pos >= 0) {
|
||||
|
||||
//if there was any text before this, add it as a fragment
|
||||
|
|
@ -362,13 +365,13 @@ public final class ConfigurationLoader {
|
|||
//if we are at the end of the string, we tack on a $
|
||||
//then move past it
|
||||
if (pos == value.length() - 1) {
|
||||
fragments.add("$");
|
||||
fragments.add(String.valueOf(DOLLAR_SIGN));
|
||||
prev = pos + 1;
|
||||
}
|
||||
else if (value.charAt(pos + 1) != '{') {
|
||||
if (value.charAt(pos + 1) == '$') {
|
||||
if (value.charAt(pos + 1) == DOLLAR_SIGN) {
|
||||
//backwards compatibility two $ map to one mode
|
||||
fragments.add("$");
|
||||
fragments.add(String.valueOf(DOLLAR_SIGN));
|
||||
prev = pos + 2;
|
||||
}
|
||||
else {
|
||||
|
|
@ -392,7 +395,7 @@ public final class ConfigurationLoader {
|
|||
}
|
||||
|
||||
//search for the next instance of $ from the 'prev' position
|
||||
pos = value.indexOf('$', prev);
|
||||
pos = value.indexOf(DOLLAR_SIGN, prev);
|
||||
}
|
||||
//no more $ signs found
|
||||
//if there is any tail to the file, append it
|
||||
|
|
|
|||
|
|
@ -265,9 +265,10 @@ public final class TreeWalker
|
|||
registerCheck(token, check);
|
||||
}
|
||||
else {
|
||||
throw new CheckstyleException("Token \""
|
||||
+ token + "\" was not found in Acceptable tokens list"
|
||||
+ " in check " + check.getClass().getName());
|
||||
final String message = String.format("Token \"%s\" was not found in "
|
||||
+ "Acceptable tokens list in check %s",
|
||||
token, check.getClass().getName());
|
||||
throw new CheckstyleException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -293,8 +294,9 @@ public final class TreeWalker
|
|||
Arrays.sort(defaultTokens);
|
||||
for (final int token : check.getRequiredTokens()) {
|
||||
if (Arrays.binarySearch(defaultTokens, token) < 0) {
|
||||
throw new CheckstyleException("Token \"" + token + "\" from required tokens was"
|
||||
+ " not found in default tokens list in check " + check);
|
||||
final String message = String.format("Token \"%s\" from required tokens was"
|
||||
+ " not found in default tokens list in check %s", token, check);
|
||||
throw new CheckstyleException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ public class CheckstyleAntTask extends Task {
|
|||
/** Poor man's enum for an plain formatter */
|
||||
private static final String E_PLAIN = "plain";
|
||||
|
||||
/** Suffix for time string. */
|
||||
private static final String TIME_SUFFIX = " ms.";
|
||||
|
||||
/** Class path to locate class files */
|
||||
private Path classpath;
|
||||
|
||||
|
|
@ -252,7 +255,7 @@ public class CheckstyleAntTask extends Task {
|
|||
}
|
||||
finally {
|
||||
final long endTime = System.currentTimeMillis();
|
||||
log("Total execution took " + (endTime - startTime) + " ms.",
|
||||
log("Total execution took " + (endTime - startTime) + TIME_SUFFIX,
|
||||
Project.MSG_VERBOSE);
|
||||
}
|
||||
}
|
||||
|
|
@ -295,7 +298,7 @@ public class CheckstyleAntTask extends Task {
|
|||
long startTime = System.currentTimeMillis();
|
||||
final List<File> files = scanFileSets();
|
||||
long endTime = System.currentTimeMillis();
|
||||
log("To locate the files took " + (endTime - startTime) + " ms.",
|
||||
log("To locate the files took " + (endTime - startTime) + TIME_SUFFIX,
|
||||
Project.MSG_VERBOSE);
|
||||
|
||||
log("Running Checkstyle " + version + " on " + files.size()
|
||||
|
|
@ -305,7 +308,7 @@ public class CheckstyleAntTask extends Task {
|
|||
startTime = System.currentTimeMillis();
|
||||
final int numErrs = checker.process(files);
|
||||
endTime = System.currentTimeMillis();
|
||||
log("To process the files took " + (endTime - startTime) + " ms.",
|
||||
log("To process the files took " + (endTime - startTime) + TIME_SUFFIX,
|
||||
Project.MSG_VERBOSE);
|
||||
final int numWarnings = warningCounter.getCount();
|
||||
final boolean ok = numErrs <= maxErrors
|
||||
|
|
|
|||
|
|
@ -159,10 +159,9 @@ public class AutomaticBean
|
|||
final PropertyDescriptor pd =
|
||||
PropertyUtils.getPropertyDescriptor(this, key);
|
||||
if (pd == null) {
|
||||
throw new CheckstyleException(
|
||||
"Property '" + key + "' in module "
|
||||
+ moduleName
|
||||
+ " does not exist, please check the documentation");
|
||||
final String message = String.format("Property '%s' in module %s does not "
|
||||
+ "exist, please check the documentation", key, moduleName);
|
||||
throw new CheckstyleException(message);
|
||||
}
|
||||
}
|
||||
// finally we can set the bean property
|
||||
|
|
@ -174,14 +173,14 @@ public class AutomaticBean
|
|||
// as we do PropertyUtils.getPropertyDescriptor before beanUtils.copyProperty
|
||||
// so we have to join these exceptions with InvocationTargetException
|
||||
// to satisfy UTs coverage
|
||||
throw new CheckstyleException(
|
||||
"Cannot set property '" + key + "' to '" + value
|
||||
+ "' in module " + moduleName, e);
|
||||
final String message = String.format("Cannot set property '%s' to '%s' in module %s",
|
||||
key, value, moduleName);
|
||||
throw new CheckstyleException(message, e);
|
||||
}
|
||||
catch (final IllegalArgumentException | ConversionException e) {
|
||||
throw new CheckstyleException(
|
||||
"illegal value '" + value + "' for property '" + key
|
||||
+ "' of module " + moduleName, e);
|
||||
final String message = String.format("illegal value '%s' for property '%s' of "
|
||||
+ "module %s", value, key, moduleName);
|
||||
throw new CheckstyleException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,8 @@ public class Comment implements TextBlock {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Comment[" + startLineNo + ":" + startColNo + "-"
|
||||
+ endLineNo + ":" + endColNo + "]";
|
||||
final String separator = ":";
|
||||
return "Comment[" + startLineNo + separator + startColNo + "-"
|
||||
+ endLineNo + separator + endColNo + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ import com.puppycrawl.tools.checkstyle.api.Check;
|
|||
*/
|
||||
public abstract class AbstractOptionCheck<T extends Enum<T>>
|
||||
extends Check {
|
||||
|
||||
/** Semicolon literal. */
|
||||
protected static final String SEMICOLON = ";";
|
||||
|
||||
/** Since I cannot get this by going <tt>T.class</tt>. */
|
||||
private final Class<T> optionClass;
|
||||
/** The policy to enforce */
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ import java.util.Set;
|
|||
* @author Oliver Burn
|
||||
*/
|
||||
public class ClassResolver {
|
||||
|
||||
/** Period literal. */
|
||||
private static final String PERIOD = ".";
|
||||
/** Dollar sign literal. */
|
||||
private static final String DOLLAR_SIGN = "$";
|
||||
|
||||
/** Name of the package to check if the class belongs to **/
|
||||
private final String pkg;
|
||||
/** Set of imports to check against **/
|
||||
|
|
@ -77,7 +83,7 @@ public class ClassResolver {
|
|||
// when checking for "DataException", it will match on
|
||||
// "SecurityDataException". This has been the cause of a very
|
||||
// difficult bug to resolve!
|
||||
if (imp.endsWith("." + name)) {
|
||||
if (imp.endsWith(PERIOD + name)) {
|
||||
clazz = resolveQualifiedName(imp);
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
|
|
@ -88,7 +94,7 @@ public class ClassResolver {
|
|||
|
||||
// See if in the package
|
||||
if (pkg != null && !pkg.isEmpty()) {
|
||||
clazz = resolveQualifiedName(pkg + "." + name);
|
||||
clazz = resolveQualifiedName(pkg + PERIOD + name);
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
}
|
||||
|
|
@ -121,10 +127,10 @@ public class ClassResolver {
|
|||
throws ClassNotFoundException {
|
||||
Class<?> clazz = null;
|
||||
if (!currentClass.isEmpty()) {
|
||||
String innerClass = currentClass + "$" + name;
|
||||
String innerClass = currentClass + DOLLAR_SIGN + name;
|
||||
|
||||
if (!pkg.isEmpty()) {
|
||||
innerClass = pkg + "." + innerClass;
|
||||
innerClass = pkg + PERIOD + innerClass;
|
||||
}
|
||||
|
||||
if (isLoadable(innerClass)) {
|
||||
|
|
@ -198,7 +204,7 @@ public class ClassResolver {
|
|||
final int dot = name.lastIndexOf('.');
|
||||
if (dot != -1) {
|
||||
final String innerName =
|
||||
name.substring(0, dot) + "$" + name.substring(dot + 1);
|
||||
name.substring(0, dot) + DOLLAR_SIGN + name.substring(dot + 1);
|
||||
if (isLoadable(innerName)) {
|
||||
classObj = safeLoad(innerName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,10 @@ public class LeftCurlyCheck
|
|||
*/
|
||||
public static final String MSG_KEY_LINE_BREAK_AFTER = "line.break.after";
|
||||
|
||||
/** If true, Check will ignore enums*/
|
||||
/** Open curly brace literal. */
|
||||
private static final String OPEN_CURLY_BRACE = "{";
|
||||
|
||||
/** If true, Check will ignore enums. */
|
||||
private boolean ignoreEnums = true;
|
||||
|
||||
/**
|
||||
|
|
@ -289,7 +292,7 @@ public class LeftCurlyCheck
|
|||
|| braceLine.charAt(brace.getColumnNo() + 1) != '}') {
|
||||
if (getAbstractOption() == LeftCurlyOption.NL) {
|
||||
if (!Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
|
||||
log(brace, MSG_KEY_LINE_NEW, "{", brace.getColumnNo() + 1);
|
||||
log(brace, MSG_KEY_LINE_NEW, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
|
||||
}
|
||||
}
|
||||
else if (getAbstractOption() == LeftCurlyOption.EOL) {
|
||||
|
|
@ -311,10 +314,10 @@ public class LeftCurlyCheck
|
|||
*/
|
||||
private void validateEol(DetailAST brace, String braceLine) {
|
||||
if (Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
|
||||
log(brace, MSG_KEY_LINE_PREVIOUS, "{", brace.getColumnNo() + 1);
|
||||
log(brace, MSG_KEY_LINE_PREVIOUS, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
|
||||
}
|
||||
if (!hasLineBreakAfter(brace)) {
|
||||
log(brace, MSG_KEY_LINE_BREAK_AFTER, "{", brace.getColumnNo() + 1);
|
||||
log(brace, MSG_KEY_LINE_BREAK_AFTER, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -329,14 +332,14 @@ public class LeftCurlyCheck
|
|||
// not on the same line
|
||||
if (startToken.getLineNo() + 1 == brace.getLineNo()) {
|
||||
if (Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
|
||||
log(brace, MSG_KEY_LINE_PREVIOUS, "{", brace.getColumnNo() + 1);
|
||||
log(brace, MSG_KEY_LINE_PREVIOUS, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
|
||||
}
|
||||
else {
|
||||
log(brace, MSG_KEY_LINE_NEW, "{", brace.getColumnNo() + 1);
|
||||
log(brace, MSG_KEY_LINE_NEW, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
|
||||
}
|
||||
}
|
||||
else if (!Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
|
||||
log(brace, MSG_KEY_LINE_NEW, "{", brace.getColumnNo() + 1);
|
||||
log(brace, MSG_KEY_LINE_NEW, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ public class AvoidStarImportCheck
|
|||
*/
|
||||
public static final String MSG_KEY = "import.avoidStar";
|
||||
|
||||
/** Suffix for the star import. */
|
||||
private static final String STAR_IMPORT_SUFFIX = ".*";
|
||||
|
||||
/** The packages/classes to exempt from this check. */
|
||||
private final List<String> excludes = Lists.newArrayList();
|
||||
|
||||
|
|
@ -113,14 +116,13 @@ public class AvoidStarImportCheck
|
|||
*/
|
||||
public void setExcludes(String... excludesParam) {
|
||||
excludes.clear();
|
||||
final String suffix = ".*";
|
||||
|
||||
for (final String exclude : excludesParam) {
|
||||
if (exclude.endsWith(suffix)) {
|
||||
if (exclude.endsWith(STAR_IMPORT_SUFFIX)) {
|
||||
excludes.add(exclude);
|
||||
}
|
||||
else {
|
||||
excludes.add(exclude + suffix);
|
||||
excludes.add(exclude + STAR_IMPORT_SUFFIX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -163,7 +165,7 @@ public class AvoidStarImportCheck
|
|||
private void logsStarredImportViolation(DetailAST startingDot) {
|
||||
final FullIdent name = FullIdent.createFullIdent(startingDot);
|
||||
final String importText = name.getText();
|
||||
if (importText.endsWith(".*") && !excludes.contains(importText)) {
|
||||
if (importText.endsWith(STAR_IMPORT_SUFFIX) && !excludes.contains(importText)) {
|
||||
log(startingDot.getLineNo(), MSG_KEY, importText);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@ public class UnusedImportsCheck extends Check {
|
|||
private static final Pattern ARGUMENT_NAME = Pattern.compile(
|
||||
"[(,]\\s*" + CLASS_NAME.pattern());
|
||||
|
||||
/** Suffix for the star import. */
|
||||
private static final String STAR_IMPORT_SUFFIX = ".*";
|
||||
|
||||
/** Flag to indicate when time to start collecting references. */
|
||||
private boolean collect;
|
||||
/** Flag whether to process Javdoc comments. */
|
||||
|
|
@ -195,7 +198,7 @@ public class UnusedImportsCheck extends Check {
|
|||
*/
|
||||
private void processImport(DetailAST ast) {
|
||||
final FullIdent name = FullIdent.createFullIdentBelow(ast);
|
||||
if (!name.getText().endsWith(".*")) {
|
||||
if (!name.getText().endsWith(STAR_IMPORT_SUFFIX)) {
|
||||
imports.add(name);
|
||||
}
|
||||
}
|
||||
|
|
@ -208,7 +211,7 @@ public class UnusedImportsCheck extends Check {
|
|||
final FullIdent name =
|
||||
FullIdent.createFullIdent(
|
||||
ast.getFirstChild().getNextSibling());
|
||||
if (!name.getText().endsWith(".*")) {
|
||||
if (!name.getText().endsWith(STAR_IMPORT_SUFFIX)) {
|
||||
imports.add(name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ public class AtclauseOrderCheck extends AbstractJavadocCheck {
|
|||
*/
|
||||
public static final String MSG_KEY = "at.clause.order";
|
||||
|
||||
/** Comma literal. */
|
||||
private static final String COMMA_SEPARATOR = ",";
|
||||
/**
|
||||
* Default order of atclauses.
|
||||
*/
|
||||
|
|
@ -104,7 +106,7 @@ public class AtclauseOrderCheck extends AbstractJavadocCheck {
|
|||
*/
|
||||
public void setTarget(String target) {
|
||||
final List<Integer> customTarget = new ArrayList<>();
|
||||
final String[] sTarget = target.split(",");
|
||||
final String[] sTarget = target.split(COMMA_SEPARATOR);
|
||||
for (String aSTarget : sTarget) {
|
||||
customTarget.add(Utils.getTokenId(aSTarget.trim()));
|
||||
}
|
||||
|
|
@ -117,7 +119,7 @@ public class AtclauseOrderCheck extends AbstractJavadocCheck {
|
|||
*/
|
||||
public void setTagOrder(String order) {
|
||||
final List<String> customOrder = new ArrayList<>();
|
||||
final String[] sOrder = order.split(",");
|
||||
final String[] sOrder = order.split(COMMA_SEPARATOR);
|
||||
for (String aSOrder : sOrder) {
|
||||
customOrder.add(aSOrder.trim());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,12 @@ public class JavadocTypeCheck
|
|||
*/
|
||||
public static final String UNUSED_TAG_GENERAL = "javadoc.unusedTagGeneral";
|
||||
|
||||
/** Open angle bracket literal. */
|
||||
private static final String OPEN_ANGLE_BRACKET = "<";
|
||||
|
||||
/** Close angle bracket literal. */
|
||||
private static final String CLOSE_ANGLE_BRACKET = ">";
|
||||
|
||||
/** The scope to check for */
|
||||
private Scope scope = Scope.PRIVATE;
|
||||
/** The visibility scope where Javadoc comments shouldn't be checked **/
|
||||
|
|
@ -267,17 +273,18 @@ public class JavadocTypeCheck
|
|||
}
|
||||
|
||||
int tagCount = 0;
|
||||
final String tagPrefix = "@";
|
||||
for (int i = tags.size() - 1; i >= 0; i--) {
|
||||
final JavadocTag tag = tags.get(i);
|
||||
if (tag.getTagName().equals(tagName)) {
|
||||
tagCount++;
|
||||
if (!formatPattern.matcher(tag.getFirstArg()).find()) {
|
||||
log(lineNo, TAG_FORMAT, "@" + tagName, format);
|
||||
log(lineNo, TAG_FORMAT, tagPrefix + tagName, format);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tagCount == 0) {
|
||||
log(lineNo, MISSING_TAG, "@" + tagName);
|
||||
log(lineNo, MISSING_TAG, tagPrefix + tagName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -294,13 +301,14 @@ public class JavadocTypeCheck
|
|||
for (int i = tags.size() - 1; i >= 0; i--) {
|
||||
final JavadocTag tag = tags.get(i);
|
||||
if (tag.isParamTag()
|
||||
&& tag.getFirstArg().indexOf("<" + typeParamName + ">") == 0) {
|
||||
&& tag.getFirstArg().indexOf(OPEN_ANGLE_BRACKET
|
||||
+ typeParamName + CLOSE_ANGLE_BRACKET) == 0) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
log(lineNo, MISSING_TAG,
|
||||
JavadocTagInfo.PARAM.getText() + " <" + typeParamName + ">");
|
||||
log(lineNo, MISSING_TAG, JavadocTagInfo.PARAM.getText()
|
||||
+ " " + OPEN_ANGLE_BRACKET + typeParamName + CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +332,7 @@ public class JavadocTypeCheck
|
|||
log(tag.getLineNo(), tag.getColumnNo(),
|
||||
UNUSED_TAG,
|
||||
JavadocTagInfo.PARAM.getText(),
|
||||
"<" + typeParamName + ">");
|
||||
OPEN_ANGLE_BRACKET + typeParamName + CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,9 @@ public class SummaryJavadocCheck extends AbstractJavadocCheck {
|
|||
*/
|
||||
public static final String SUMMARY_JAVADOC = "summary.javaDoc";
|
||||
|
||||
/** Period literal. */
|
||||
private static final String PERIOD = ".";
|
||||
|
||||
/**
|
||||
* Regular expression for forbidden summary fragments.
|
||||
*/
|
||||
|
|
@ -81,7 +84,7 @@ public class SummaryJavadocCheck extends AbstractJavadocCheck {
|
|||
/**
|
||||
* Period symbol at the end of first javadoc sentence.
|
||||
*/
|
||||
private String period = ".";
|
||||
private String period = PERIOD;
|
||||
|
||||
/**
|
||||
* Sets custom value of regular expression for forbidden summary fragments.
|
||||
|
|
@ -138,9 +141,10 @@ public class SummaryJavadocCheck extends AbstractJavadocCheck {
|
|||
*/
|
||||
private static String getFirstSentence(DetailNode ast) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
final String periodSuffix = PERIOD + ' ';
|
||||
for (DetailNode child : ast.getChildren()) {
|
||||
if (child.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG
|
||||
&& child.getText().contains(". ")) {
|
||||
&& child.getText().contains(periodSuffix)) {
|
||||
result.append(getCharsTillDot(child));
|
||||
break;
|
||||
}
|
||||
|
|
@ -160,7 +164,7 @@ public class SummaryJavadocCheck extends AbstractJavadocCheck {
|
|||
final StringBuilder result = new StringBuilder();
|
||||
for (DetailNode child : textNode.getChildren()) {
|
||||
result.append(child.getText());
|
||||
if (".".equals(child.getText())
|
||||
if (PERIOD.equals(child.getText())
|
||||
&& JavadocUtils.getNextSibling(child).getType() == JavadocTokenTypes.WS) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,12 @@ abstract class AbstractParenPadCheck
|
|||
*/
|
||||
public static final String WS_NOT_PRECEDED = "ws.notPreceded";
|
||||
|
||||
/** Open parenthesis literal. */
|
||||
private static final char OPEN_PARENTHESIS = '(';
|
||||
|
||||
/** Close parenthesis literal. */
|
||||
private static final char CLOSE_PARENTHESIS = ')';
|
||||
|
||||
/**
|
||||
* Sets the paren pad option to nospace.
|
||||
*/
|
||||
|
|
@ -74,12 +80,12 @@ abstract class AbstractParenPadCheck
|
|||
if (after < line.length()) {
|
||||
if (getAbstractOption() == PadOption.NOSPACE
|
||||
&& Character.isWhitespace(line.charAt(after))) {
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, "(");
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, OPEN_PARENTHESIS);
|
||||
}
|
||||
else if (getAbstractOption() == PadOption.SPACE
|
||||
&& !Character.isWhitespace(line.charAt(after))
|
||||
&& line.charAt(after) != ')') {
|
||||
log(ast.getLineNo(), after, WS_NOT_FOLLOWED, "(");
|
||||
&& line.charAt(after) != CLOSE_PARENTHESIS) {
|
||||
log(ast.getLineNo(), after, WS_NOT_FOLLOWED, OPEN_PARENTHESIS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,13 +101,13 @@ abstract class AbstractParenPadCheck
|
|||
if (getAbstractOption() == PadOption.NOSPACE
|
||||
&& Character.isWhitespace(line.charAt(before))
|
||||
&& !Utils.whitespaceBefore(before, line)) {
|
||||
log(ast.getLineNo(), before, WS_PRECEDED, ")");
|
||||
log(ast.getLineNo(), before, WS_PRECEDED, CLOSE_PARENTHESIS);
|
||||
}
|
||||
else if (getAbstractOption() == PadOption.SPACE
|
||||
&& !Character.isWhitespace(line.charAt(before))
|
||||
&& line.charAt(before) != '(') {
|
||||
&& line.charAt(before) != OPEN_PARENTHESIS) {
|
||||
log(ast.getLineNo(), ast.getColumnNo(),
|
||||
WS_NOT_PRECEDED, ")");
|
||||
WS_NOT_PRECEDED, CLOSE_PARENTHESIS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,11 +96,11 @@ public class EmptyForInitializerPadCheck
|
|||
final PadOption option = getAbstractOption();
|
||||
if (option == PadOption.NOSPACE
|
||||
&& Character.isWhitespace(line.charAt(before))) {
|
||||
log(semi.getLineNo(), before, MSG_PRECEDED, ";");
|
||||
log(semi.getLineNo(), before, MSG_PRECEDED, SEMICOLON);
|
||||
}
|
||||
else if (option == PadOption.SPACE
|
||||
&& !Character.isWhitespace(line.charAt(before))) {
|
||||
log(semi.getLineNo(), before, MSG_NOT_PRECEDED, ";");
|
||||
log(semi.getLineNo(), before, MSG_NOT_PRECEDED, SEMICOLON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,11 +94,11 @@ public class EmptyForIteratorPadCheck
|
|||
if (after < line.length()) {
|
||||
if (getAbstractOption() == PadOption.NOSPACE
|
||||
&& Character.isWhitespace(line.charAt(after))) {
|
||||
log(semi.getLineNo(), after, WS_FOLLOWED, ";");
|
||||
log(semi.getLineNo(), after, WS_FOLLOWED, SEMICOLON);
|
||||
}
|
||||
else if (getAbstractOption() == PadOption.SPACE
|
||||
&& !Character.isWhitespace(line.charAt(after))) {
|
||||
log(semi.getLineNo(), after, WS_NOT_FOLLOWED, ";");
|
||||
log(semi.getLineNo(), after, WS_NOT_FOLLOWED, SEMICOLON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,12 @@ public class GenericWhitespaceCheck extends Check {
|
|||
*/
|
||||
public static final String WS_ILLEGAL_FOLLOW = "ws.illegalFollow";
|
||||
|
||||
/** Open angle bracket literal. */
|
||||
private static final String OPEN_ANGLE_BRACKET = "<";
|
||||
|
||||
/** Close angle bracket literal. */
|
||||
private static final String CLOSE_ANGLE_BRACKET = ">";
|
||||
|
||||
/** Used to count the depth of a Generic expression. */
|
||||
private int depth;
|
||||
|
||||
|
|
@ -145,7 +151,7 @@ public class GenericWhitespaceCheck extends Check {
|
|||
|
||||
if (before >= 0 && Character.isWhitespace(line.charAt(before))
|
||||
&& !Utils.whitespaceBefore(before, line)) {
|
||||
log(ast.getLineNo(), before, WS_PRECEDED, ">");
|
||||
log(ast.getLineNo(), before, WS_PRECEDED, CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
|
||||
if (after < line.length()) {
|
||||
|
|
@ -183,11 +189,11 @@ public class GenericWhitespaceCheck extends Check {
|
|||
log(ast.getLineNo(), after, WS_NOT_PRECEDED, "&");
|
||||
}
|
||||
else if (indexOfAmp - after != 1) {
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, ">");
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
else if (line.charAt(after) == ' ') {
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, ">");
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,14 +212,14 @@ public class GenericWhitespaceCheck extends Check {
|
|||
// +--- whitespace not allowed
|
||||
if (isGenericBeforeMethod(ast)) {
|
||||
if (Character.isWhitespace(charAfter)) {
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, ">");
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
else if (!Character.isWhitespace(charAfter)
|
||||
&& charAfter != '(' && charAfter != ')'
|
||||
&& charAfter != ',' && charAfter != '['
|
||||
&& charAfter != '.' && charAfter != ':') {
|
||||
log(ast.getLineNo(), after, WS_ILLEGAL_FOLLOW, ">");
|
||||
log(ast.getLineNo(), after, WS_ILLEGAL_FOLLOW, CLOSE_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -263,19 +269,19 @@ public class GenericWhitespaceCheck extends Check {
|
|||
|| grandparent.getType() == TokenTypes.METHOD_DEF)) {
|
||||
// Require whitespace
|
||||
if (!Character.isWhitespace(line.charAt(before))) {
|
||||
log(ast.getLineNo(), before, WS_NOT_PRECEDED, "<");
|
||||
log(ast.getLineNo(), before, WS_NOT_PRECEDED, OPEN_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
// Whitespace not required
|
||||
else if (Character.isWhitespace(line.charAt(before))
|
||||
&& !Utils.whitespaceBefore(before, line)) {
|
||||
log(ast.getLineNo(), before, WS_PRECEDED, "<");
|
||||
log(ast.getLineNo(), before, WS_PRECEDED, OPEN_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
|
||||
if (after < line.length()
|
||||
&& Character.isWhitespace(line.charAt(after))) {
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, "<");
|
||||
log(ast.getLineNo(), after, WS_FOLLOWED, OPEN_ANGLE_BRACKET);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -178,15 +178,17 @@ public final class SuppressionsLoader
|
|||
throw new CheckstyleException(UNABLE_TO_FIND_ERROR_MESSAGE + sourceName, e);
|
||||
}
|
||||
catch (final ParserConfigurationException | SAXException e) {
|
||||
throw new CheckstyleException("Unable to parse "
|
||||
+ sourceName + " - " + e.getMessage(), e);
|
||||
final String message = String.format("Unable to parse %s - %s",
|
||||
sourceName, e.getMessage());
|
||||
throw new CheckstyleException(message, e);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
throw new CheckstyleException("Unable to read " + sourceName, e);
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
throw new CheckstyleException("Number format exception "
|
||||
+ sourceName + " - " + e.getMessage(), e);
|
||||
final String message = String.format("Number format exception %s - %s",
|
||||
sourceName, e.getMessage());
|
||||
throw new CheckstyleException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue