IG: ignore casting class types to primitive (IDEA-170332)

This commit is contained in:
Bas Leijdekkers
2017-04-07 11:31:05 +02:00
parent ee1712af7e
commit e640c10083
2 changed files with 16 additions and 1 deletions
@@ -121,6 +121,7 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
}
final PsiType operandType = operand.getType();
if (castType.equals(operandType) || isPrimitiveNumericCastNecessary(expression)) {
// equal types is caught by "Redundant type cast" inspection
return;
}
final PsiTypeElement typeElement = expression.getCastType();
@@ -140,7 +141,7 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
return true;
}
final PsiType operandType = operand.getType();
if (operandType == null) {
if (!(operandType instanceof PsiPrimitiveType)) {
return true;
}
PsiElement parent = expression.getParent();
@@ -88,3 +88,17 @@ enum Numeric {
Numeric(byte b) {}
}
class S {
static void doSomething() {
// V --- this cast is reported as unnecessary
if ( (int) whatever() < 0 ) {
}
}
@SuppressWarnings("unchecked")
private static <T> T whatever() {
return (T) (Object) 0;
}
}