java redundant cast: check binary operation compatibility (IDEA-221292)

GitOrigin-RevId: 0fceb94966dd38a30e26c621dbf546ac3383e7e1
This commit is contained in:
Anna Kozlova
2020-05-04 11:32:03 +00:00
committed by intellij-monorepo-bot
parent d1d229a88c
commit 49ab34989f
3 changed files with 11 additions and 1 deletions
@@ -721,7 +721,7 @@ public class RedundantCastUtil {
PsiExpression lOperand = ((PsiBinaryExpression)parent).getLOperand();
PsiExpression rOperand = ((PsiBinaryExpression)parent).getROperand();
PsiType oppositeType = lOperand == typeCast ? rOperand != null ? rOperand.getType() : null : lOperand.getType();
if (oppositeType != null && TypeConversionUtil.areTypesConvertible(opType, oppositeType)) {
if (oppositeType != null && TypeConversionUtil.isBinaryOperatorApplicable(((PsiBinaryExpression)parent).getOperationTokenType(), opType, oppositeType, false)) {
addToResults(typeCast);
}
}
@@ -0,0 +1,9 @@
class Test {
void m(Object a) {
if ((Boolean)a && (Boolean)a) { }
}
Object concat(Object x, Object y) {
return x + (String) y;
}
}
@@ -46,4 +46,5 @@ public class RedundantCast18Test extends LightDaemonAnalyzerTestCase {
public void testCastWithClassHierarchyWithPrivateMethods() { doTest(); }
public void testFieldInitializer() { doTest();}
public void testDiamondWithUpperBounds() { doTest();}
public void testBinaryConversions() { doTest();}
}