RedundantCastUtil: report safe widening primitive casts

Fixes IDEA-154832 IDEA add unnecessary cast to double on method inline

GitOrigin-RevId: 1e8dbd1466f74bdab9584a860f4e188b025fba1c
This commit is contained in:
Tagir Valeev
2019-04-23 13:15:33 +03:00
committed by intellij-monorepo-bot
parent 505bdd1c87
commit bfde8b00af
6 changed files with 45 additions and 1 deletions
@@ -0,0 +1,18 @@
import org.jetbrains.annotations.*;
class A {
double widen(int x) {
return (<warning descr="Casting 'x' to 'double' is redundant">double</warning>) x;
}
double widenDataLoss(long x) {
return (double) x;
}
void call(short a, byte b, long c) {
widen((<warning descr="Casting 'a' to 'int' is redundant">int</warning>)a);
widen((<warning descr="Casting 'b' to 'int' is redundant">int</warning>)b);
widen((int)c);
}
}
@@ -0,0 +1,12 @@
class UnnecessaryDoubleCast {
public void check() {
<caret>eq(25, 25.49);
}
private static void eq(double expected, double actual) {
assertDoubleEquals(expected, actual);
}
public static void assertDoubleEquals(double v, double v2) {
}
}
@@ -0,0 +1,8 @@
class UnnecessaryDoubleCast {
public void check() {
assertDoubleEquals(25, 25.49);
}
public static void assertDoubleEquals(double v, double v2) {
}
}