mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant cast: check binary comparison assignability (IDEA-209944)
GitOrigin-RevId: 4276128fb33224de60afc7661e478ca172205f51
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2ceebfedf1
commit
7f603ae6b1
@@ -697,6 +697,14 @@ public class RedundantCastUtil {
|
||||
addToResults(typeCast);
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiBinaryExpression) {
|
||||
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)) {
|
||||
addToResults(typeCast);
|
||||
}
|
||||
}
|
||||
else if (TypeConversionUtil.isAssignable(castTo, opType, false) &&
|
||||
(expectedTypeByParent == null || TypeConversionUtil.isAssignable(expectedTypeByParent, opType, false))) {
|
||||
addToResults(typeCast);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class MyClass {
|
||||
public <O> Class<O> getValueClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isBooleanClass() {
|
||||
return (Class<?>) getValueClass() == Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@ public class RedundantCast15Test extends LightCodeInsightFixtureTestCase {
|
||||
public void testForEachValueIDEA126166() { doTest();}
|
||||
public void testCaseThrowable() { doTest();}
|
||||
public void testSafeTempVarName() { doTest();}
|
||||
public void testBinaryComparison() { doTest();}
|
||||
|
||||
public void testTypeParameterAccessChecksJava7() {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user