mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-146649 "Redundant type cast" warning expected when casting primitive to the same type
GitOrigin-RevId: 1ee7941e5f78e525a3edd92f539e21bd720b096e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bfde8b00af
commit
bec9b23504
@@ -469,17 +469,22 @@ public class RedundantCastUtil {
|
||||
|
||||
final PsiType topCastType = typeCast.getType();
|
||||
if (expr instanceof PsiTypeCastExpression) {
|
||||
PsiTypeElement typeElement = ((PsiTypeCastExpression)expr).getCastType();
|
||||
PsiTypeCastExpression innerCast = (PsiTypeCastExpression)expr;
|
||||
PsiTypeElement typeElement = innerCast.getCastType();
|
||||
if (typeElement == null) return;
|
||||
PsiType castType = typeElement.getType();
|
||||
final PsiExpression innerOperand = ((PsiTypeCastExpression)expr).getOperand();
|
||||
final PsiExpression innerOperand = innerCast.getOperand();
|
||||
final PsiType operandType = innerOperand != null ? innerOperand.getType() : null;
|
||||
if (!(castType instanceof PsiPrimitiveType) && !(topCastType instanceof PsiPrimitiveType)) {
|
||||
if (operandType != null && topCastType != null && TypeConversionUtil.areTypesConvertible(operandType, topCastType)) {
|
||||
addToResults((PsiTypeCastExpression)expr);
|
||||
addToResults(innerCast);
|
||||
}
|
||||
} else if (Comparing.equal(PsiPrimitiveType.getUnboxedType(operandType), topCastType)) {
|
||||
addToResults((PsiTypeCastExpression)expr);
|
||||
addToResults(innerCast);
|
||||
}
|
||||
else if (operandType != null && operandType.equals(castType)) {
|
||||
// like (int)(long)1L
|
||||
addToResults(innerCast);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class A {
|
||||
void method() {
|
||||
int v = (int)(<warning descr="Casting '1L' to 'long' is redundant">long</warning>)1L;
|
||||
}
|
||||
}
|
||||
@@ -80,4 +80,5 @@ public class RedundantCast15Test extends LightCodeInsightFixtureTestCase {
|
||||
public void testDifferentNullness() { doTest();}
|
||||
|
||||
public void testPrimitiveWidening() { doTest(); }
|
||||
public void testCastLongLiteral() { doTest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user