IDEA-121920 (X/X can be replaced with X - incorrect arithmetic)

This commit is contained in:
Bas Leijdekkers
2014-03-11 18:16:13 +01:00
parent 7f73d5ebdd
commit 58a3377455
3 changed files with 10 additions and 1 deletions
@@ -120,7 +120,7 @@ public class PointlessArithmeticExpressionInspection
}
}
else if (tokenType.equals(JavaTokenType.DIV)) {
if (ExpressionUtils.isOne(expression)) {
if (ExpressionUtils.isOne(rhs)) {
return lhs.getText();
}
return "1";
@@ -110,4 +110,6 @@ class Main {
final Main main = new Main(12);
return (CONST + (new Main(5).i) * 8) - (Main.CONST + new Main(5).i * (8));
}
int one = 5/5;
}
@@ -147,4 +147,11 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
<description>&lt;code&gt;(CONST + (new Main(5).i) * 8) - (Main.CONST + new Main(5).i * (8))&lt;/code&gt; can be replaced with '0' #loc</description>
</problem>
<problem>
<file>PointlessArithmeticExpression.java</file>
<line>114</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
<description>&lt;code&gt;5/5&lt;/code&gt; can be replaced with '1' #loc</description>
</problem>
</problems>