Issue #1555: Flip negated if-else

Fixes `NegatedIfElse` inspection violation.

Description:
>Reports if statements which contain else branches and whose conditions are negated. Flipping the order of the if and else branches will usually increase the clarity of such statements.
This commit is contained in:
Michal Kordas 2015-08-29 23:07:05 +02:00 committed by Roman Ivanov
parent e81ca8290b
commit f293a21076
1 changed files with 12 additions and 12 deletions

View File

@ -467,7 +467,18 @@ public class CustomImportOrderCheck extends Check {
final String importGroup = importObject.getImportGroup();
final String fullImportIdent = importObject.getImportFullPath();
if (!importGroup.equals(currentGroup)) {
if (importGroup.equals(currentGroup)) {
if (sortImportsInGroupAlphabetically
&& previousImportFromCurrentGroup != null
&& compareImports(fullImportIdent, previousImportFromCurrentGroup) < 0) {
log(importObject.getLineNumber(), MSG_LEX,
fullImportIdent, previousImportFromCurrentGroup);
}
else {
previousImportFromCurrentGroup = fullImportIdent;
}
}
else {
//not the last group, last one is always NON_GROUP
if (customImportOrderRules.size() > currentGroupNumber + 1) {
final String nextGroup = getNextImportGroup(currentGroupNumber + 1);
@ -490,17 +501,6 @@ public class CustomImportOrderCheck extends Check {
importGroup, currentGroup, fullImportIdent);
}
}
else {
if (sortImportsInGroupAlphabetically
&& previousImportFromCurrentGroup != null
&& compareImports(fullImportIdent, previousImportFromCurrentGroup) < 0) {
log(importObject.getLineNumber(), MSG_LEX,
fullImportIdent, previousImportFromCurrentGroup);
}
else {
previousImportFromCurrentGroup = fullImportIdent;
}
}
}
}