Skip to content

Commit

Permalink
Issue checkstyle#3496: Enforce ReturnCount max=1 in com.puppycrawl.to…
Browse files Browse the repository at this point in the history
…ols.checkstyle.api
  • Loading branch information
Vladlis authored and timurt committed May 6, 2017
1 parent 7239144 commit 3535712
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 27 deletions.
3 changes: 1 addition & 2 deletions config/suppressions.xml
Expand Up @@ -91,6 +91,5 @@
<suppress checks="CyclomaticComplexity" files="CustomImportOrderCheck\.java"/>

<!-- Until https://github.com/checkstyle/checkstyle/issues/3496 -->
<suppress id="returnCountMaxOne" files=".*[\\/]api[\\/]|
|.*[\\/]coding[\\/]|.*[\\/]indentation[\\/]"/>
<suppress id="returnCountMaxOne" files=".*[\\/]coding[\\/]|.*[\\/]indentation[\\/]"/>
</suppressions>
Expand Up @@ -107,6 +107,7 @@ public void parseInputSource(InputSource inputSource)
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
final InputSource inputSource;
if (publicIdToResourceNameMap.keySet().contains(publicId)) {
final String dtdResourceName =
publicIdToResourceNameMap.get(publicId);
Expand All @@ -115,9 +116,12 @@ public InputSource resolveEntity(String publicId, String systemId)
final InputStream dtdIs =
loader.getResourceAsStream(dtdResourceName);

return new InputSource(dtdIs);
inputSource = new InputSource(dtdIs);
}
return super.resolveEntity(publicId, systemId);
else {
inputSource = super.resolveEntity(publicId, systemId);
}
return inputSource;
}

@Override
Expand Down
Expand Up @@ -119,13 +119,17 @@ protected String getMessageBundle() {
* used by the module.
*/
private static String getMessageBundle(final String className) {
final String messageBundle;
final int endIndex = className.lastIndexOf('.');
final String messages = "messages";
if (endIndex < 0) {
return messages;
messageBundle = messages;
}
final String packageName = className.substring(0, endIndex);
return packageName + "." + messages;
else {
final String packageName = className.substring(0, endIndex);
messageBundle = packageName + "." + messages;
}
return messageBundle;
}

/**
Expand Down
Expand Up @@ -115,12 +115,11 @@ public int getColumn() {
* @return the audit event severity level
*/
public SeverityLevel getSeverityLevel() {
if (localizedMessage == null) {
return SeverityLevel.INFO;
}
else {
return localizedMessage.getSeverityLevel();
SeverityLevel severityLevel = SeverityLevel.INFO;
if (localizedMessage != null) {
severityLevel = localizedMessage.getSeverityLevel();
}
return severityLevel;
}

/**
Expand Down
Expand Up @@ -369,16 +369,21 @@ public boolean inPackageInfo() {
*/
private boolean hasIntersectionWithBlockComment(int startLineNo, int startColNo,
int endLineNo, int endColNo) {
boolean hasIntersection = false;
// Check C comments (all comments should be checked)
final Collection<List<TextBlock>> values = clangComments.values();
for (final List<TextBlock> row : values) {
for (final TextBlock comment : row) {
if (comment.intersects(startLineNo, startColNo, endLineNo, endColNo)) {
return true;
hasIntersection = true;
break;
}
}
if (hasIntersection) {
break;
}
}
return false;
return hasIntersection;
}

/**
Expand All @@ -391,15 +396,17 @@ private boolean hasIntersectionWithBlockComment(int startLineNo, int startColNo,
*/
private boolean hasIntersectionWithSingleLineComment(int startLineNo, int startColNo,
int endLineNo, int endColNo) {
boolean hasIntersection = false;
// Check CPP comments (line searching is possible)
for (int lineNumber = startLineNo; lineNumber <= endLineNo;
lineNumber++) {
final TextBlock comment = cppComments.get(lineNumber);
if (comment != null && comment.intersects(startLineNo, startColNo,
endLineNo, endColNo)) {
return true;
hasIntersection = true;
break;
}
}
return false;
return hasIntersection;
}
}
Expand Up @@ -229,12 +229,14 @@ private static String readFile(final File inputFile, final CharsetDecoder decode
* @return an object representing the denoted text file
*/
public static FileText fromLines(File file, List<String> lines) {
final FileText fileText;
if (lines instanceof FileText) {
return (FileText) lines;
fileText = (FileText) lines;
}
else {
return new FileText(file, lines);
fileText = new FileText(file, lines);
}
return fileText;
}

/**
Expand Down
Expand Up @@ -83,12 +83,14 @@ public int hashCode() {

@Override
public boolean accept(AuditEvent event) {
boolean result = true;
for (Filter filter : filters) {
if (!filter.accept(event)) {
return false;
result = false;
break;
}
}
return true;
return result;
}

/** Clears the FilterSet. */
Expand Down
Expand Up @@ -62,12 +62,14 @@ public int getColumn() {

@Override
public int compareTo(LineColumn lineColumn) {
final int result;
if (line == lineColumn.line) {
return Integer.compare(column, lineColumn.column);
result = Integer.compare(column, lineColumn.column);
}
else {
return Integer.compare(line, lineColumn.line);
result = Integer.compare(line, lineColumn.line);
}
return result;
}

@Override
Expand Down
Expand Up @@ -279,12 +279,12 @@ public String getMessage() {
* if there is no custom message
*/
private String getCustomMessage() {

if (customMessage == null) {
return null;
String message = null;
if (customMessage != null) {
final MessageFormat formatter = new MessageFormat(customMessage, Locale.ROOT);
message = formatter.format(args);
}
final MessageFormat formatter = new MessageFormat(customMessage, Locale.ROOT);
return formatter.format(args);
return message;
}

/**
Expand Down

0 comments on commit 3535712

Please sign in to comment.