OverflowingLoopInspection: do not highlight in case of -=- 1

This commit is contained in:
Roman.Ivanov
2019-04-02 10:05:11 +07:00
parent 4ba1315514
commit be87aa1df8
2 changed files with 9 additions and 3 deletions
@@ -135,9 +135,9 @@ public class OverflowingLoopIndexInspection extends AbstractBaseJavaLocalInspect
boolean negative = number.longValue() < 0;
IElementType op = assignment.getOperationTokenType();
if (conditionType == ConditionType.VarGreater) {
return op == JavaTokenType.PLUSEQ || (op == JavaTokenType.MINUSEQ && negative);
return (op == JavaTokenType.PLUSEQ && !negative) || (op == JavaTokenType.MINUSEQ && negative);
} else {
return op == JavaTokenType.MINUSEQ || (op == JavaTokenType.PLUSEQ && negative);
return (op == JavaTokenType.MINUSEQ && !negative) || (op == JavaTokenType.PLUSEQ && negative);
}
}
return false;
@@ -30,7 +30,7 @@ public class OverflowingLoop {
}
void minusEqAddNegative(int s) {
<warning descr="Loop executes zero or billions times">for</warning> (int i = s; i > 12; i += -12) {
for (int i = s; i > 12; i += -12) {
System.out.println(i + 23);
}
}
@@ -61,4 +61,10 @@ public class OverflowingLoop {
i+= 100;
}
}
void minusEqMinus(int s) {
for (int i = 0; i < 10; i -=- 1) {
System.out.println("asdsakdj");
}
}
}