mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java redundant cast: check binary operation compatibility (IDEA-221292)
GitOrigin-RevId: 0fceb94966dd38a30e26c621dbf546ac3383e7e1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d1d229a88c
commit
49ab34989f
@@ -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();}
|
||||
}
|
||||
Reference in New Issue
Block a user