Skip to content

Commit

Permalink
Issue checkstyle#3496: Enforce ReturnCount max=1 in com.google.checks…
Browse files Browse the repository at this point in the history
…tyle.test.base package
  • Loading branch information
Vladlis committed Apr 20, 2017
1 parent ae50093 commit c814024
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/suppressions.xml
Expand Up @@ -95,6 +95,6 @@
|.*[\\/]coding[\\/]|.*[\\/]design[\\/]|.*[\\/]imports[\\/]|.*[\\/]indentation[\\/]|.*[\\/]javadoc[\\/]|
|.*[\\/]naming[\\/]|.*[\\/]regexp[\\/]|.*[\\/]sizes[\\/]|.*[\\/]whitespace[\\/]|.*[\\/]doclets[\\/]|.*[\\/]gui[\\/]|
|.*[\\/]utils[\\/]|.*[\\/]doclets[\\/]|.*[\\/]internal[\\/]|.*[\\/]checkstyle[\\/]BaseCheckTestSupport\.java|
|.*[\\/]base[\\/]|(AbstractDeclarationCollector|AbstractTypeAwareCheck|LineSeparatorOption|NewlineAtEndOfFileCheck|
|(AbstractDeclarationCollector|AbstractTypeAwareCheck|LineSeparatorOption|NewlineAtEndOfFileCheck|
|SuppressWarningsHolder|JavadocDetailNodeParser|TreeWalker)\.java"/>
</suppressions>
Expand Up @@ -218,16 +218,18 @@ protected void verify(Checker checker,
*/
protected String getCheckMessage(Class<? extends AbstractViolationReporter> aClass,
String messageKey, Object... arguments) {
final Properties pr = new Properties();
String checkMessage;
try {
final Properties pr = new Properties();
pr.load(aClass.getResourceAsStream("messages.properties"));
final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey),
Locale.ROOT);
checkMessage = formatter.format(arguments);
}
catch (IOException ex) {
return null;
checkMessage = null;
}
final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey),
Locale.ROOT);
return formatter.format(arguments);
return checkMessage;
}

/**
Expand All @@ -237,13 +239,15 @@ protected String getCheckMessage(Class<? extends AbstractViolationReporter> aCla
*/
protected String getCheckMessage(Map<String, String> messages, String messageKey,
Object... arguments) {
String checkMessage = null;
for (Map.Entry<String, String> entry : messages.entrySet()) {
if (messageKey.equals(entry.getKey())) {
final MessageFormat formatter = new MessageFormat(entry.getValue(), Locale.ROOT);
return formatter.format(arguments);
checkMessage = formatter.format(arguments);
break;
}
}
return null;
return checkMessage;
}

/**
Expand Down Expand Up @@ -320,10 +324,11 @@ else if (checkName.equals(currentConfig.getName())) {

private static String removeDeviceFromPathOnWindows(String path) {
final String os = System.getProperty("os.name", "Unix");
String fixedPath = path;
if (os.startsWith("Windows")) {
return path.substring(path.indexOf(':') + 1);
fixedPath = path.substring(path.indexOf(':') + 1);
}
return path;
return fixedPath;
}

/**
Expand Down
Expand Up @@ -202,12 +202,14 @@ private static CommentType getCommentType(String comment) {
}

private static int getLineStart(String line, final int tabWidth) {
int lineStart = 0;
for (int index = 0; index < line.length(); ++index) {
if (!Character.isWhitespace(line.charAt(index))) {
return CommonUtils.lengthExpandedTabs(line, index, tabWidth);
lineStart = CommonUtils.lengthExpandedTabs(line, index, tabWidth);
break;
}
}
return 0;
return lineStart;
}

private enum CommentType {
Expand Down

0 comments on commit c814024

Please sign in to comment.