Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Issue checkstyle#4722: fix SimplifiableIfStatement, suppress MissingP…
Browse files Browse the repository at this point in the history
…ackageInfo violation
  • Loading branch information
vasylieva committed Jul 18, 2017
1 parent c870b6d commit 1e5af25
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 31 deletions.
7 changes: 5 additions & 2 deletions config/intellij-idea-inspections.xml
Expand Up @@ -1424,8 +1424,9 @@
<option name="ignoreObjectMethods" value="true" />
<option name="ignoreAnonymousClassMethods" value="false" />
</inspection_tool>
<inspection_tool class="MissingPackageInfo" enabled="false" level="WARNING" enabled_by_default="true">
<inspection_tool class="MissingPackageInfo" enabled="true" level="WARNING" enabled_by_default="false">
<scope name="Tests" level="WARNING" enabled="false" />
<scope name="Production" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="MissortedModifiers" enabled="true" level="ERROR" enabled_by_default="true">
<option name="m_requireAnnotationsFirst" value="true" />
Expand Down Expand Up @@ -1852,7 +1853,7 @@
<inspection_tool class="SimplifiableAnnotation" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifiableConditionalExpression" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifiableEqualsExpression" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="SimplifiableIfStatement" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifiableJUnitAssertion" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifyNegatedBinaryExpression" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- suppressed till GSoC project completion .... -->
Expand Down Expand Up @@ -2059,6 +2060,8 @@
<option value="UseOfSystemOutOrSystemErr" />
<option value="SuspiciousArrayCast" />
<option value="AbstractClassWithOnlyOneDirectInheritor" />
<!-- in some cases it makes the logic even more complicated -->
<option value="SimplifiableIfStatement" />
</list>
</option>
</inspection_tool>
Expand Down
Expand Up @@ -197,14 +197,9 @@ protected boolean hasText(final DetailAST slistAST) {
else {
final String firstLine = lines[slistLineNo - 1].substring(slistColNo + 1);
final String lastLine = lines[rcurlyLineNo - 1].substring(0, rcurlyColNo);
if (CommonUtils.isBlank(firstLine)
&& CommonUtils.isBlank(lastLine)) {
// check if all lines are also only whitespace
returnValue = !checkIsAllLinesAreWhitespace(lines, slistLineNo, rcurlyLineNo);
}
else {
returnValue = true;
}
// check if all lines are also only whitespace
returnValue = !(CommonUtils.isBlank(firstLine) && CommonUtils.isBlank(lastLine))
|| !checkIsAllLinesAreWhitespace(lines, slistLineNo, rcurlyLineNo);
}
return returnValue;
}
Expand Down
Expand Up @@ -191,6 +191,7 @@ private static boolean isInNoBraceControlStatement(DetailAST ast) {
*
* @param ast assignment AST
* @return whether the context of the assignment AST indicates the idiom
* @noinspection SimplifiableIfStatement
*/
private static boolean isInWhileIdiom(DetailAST ast) {
if (!isComparison(ast.getParent())) {
Expand Down
Expand Up @@ -230,6 +230,7 @@ public void visitToken(DetailAST ast) {
* @param ast input DetailAST node.
* @return true if it is an ignore situation found for given input DetailAST
* node.
* @noinspection SimplifiableIfStatement
*/
private boolean isIgnoreSituation(DetailAST ast) {
final DetailAST modifiers = ast.getFirstChild();
Expand All @@ -249,8 +250,7 @@ && isInterfaceDeclaration(ast)) {
}
}
else if (ast.getType() == TokenTypes.METHOD_DEF) {
result = ignoreOverriddenMethods
&& hasOverrideAnnotation(modifiers);
result = ignoreOverriddenMethods && hasOverrideAnnotation(modifiers);
}
else {
result = CheckUtils.isReceiverParameter(ast);
Expand Down
Expand Up @@ -306,16 +306,8 @@ private boolean isMatchFolder(String folderPath) {
result = true;
}
else {
final boolean useMatch;

// null pattern means 'match' applies to the folderPattern matching
if (fileNamePattern == null) {
useMatch = match;
}
else {
useMatch = true;
}

final boolean useMatch = fileNamePattern != null || match;
result = folderPattern.matcher(folderPath).find() == useMatch;
}

Expand All @@ -330,17 +322,8 @@ private boolean isMatchFolder(String folderPath) {
* @return true if they do match.
*/
private boolean isMatchFile(String fileName) {
final boolean result;

// null pattern always matches, regardless of value of 'match'
if (fileNamePattern == null) {
result = true;
}
else {
result = fileNamePattern.matcher(fileName).find() == match;
}

return result;
return fileNamePattern == null || fileNamePattern.matcher(fileName).find() == match;
}

/** Logs the errors for the check. */
Expand Down

0 comments on commit 1e5af25

Please sign in to comment.