mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
DataFlowInstructionVisitor#isInstanceofRedundant fixed
GitOrigin-RevId: eacf2331a6aca6d00a5dbdb1a62d8249fab9ad1e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a68034133d
commit
ccb7c7addc
@@ -202,10 +202,14 @@ final class DataFlowInstructionVisitor extends StandardInstructionVisitor {
|
||||
|
||||
public boolean isInstanceofRedundant(InstanceofInstruction instruction) {
|
||||
PsiExpression expression = instruction.getExpression();
|
||||
return expression != null && !myUsefulInstanceofs.contains(instruction) && myReachable.contains(instruction) &&
|
||||
myConstantExpressions.get(new ExpressionChunk(expression, null)) != ConstantResult.TRUE &&
|
||||
(!(expression instanceof PsiMethodReferenceExpression) ||
|
||||
!DfaConstValue.isConstant(myMethodReferenceResults.get(expression), Boolean.TRUE));
|
||||
if (expression == null || myUsefulInstanceofs.contains(instruction) || !myReachable.contains(instruction)) return false;
|
||||
if (expression instanceof PsiMethodReferenceExpression) {
|
||||
DfaValue value = myMethodReferenceResults.get(expression);
|
||||
return !(value instanceof DfaConstValue) || !(((DfaConstValue)value).getValue() instanceof Boolean);
|
||||
} else {
|
||||
ConstantResult result = myConstantExpressions.get(new ExpressionChunk(expression, null));
|
||||
return result != ConstantResult.TRUE && result != ConstantResult.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,4 +11,8 @@ class C {
|
||||
System.out.println("Something");
|
||||
}
|
||||
}
|
||||
void bar(A a) {
|
||||
if (<warning descr="Condition 'a instanceof A' is redundant and can be replaced with a null check">a instanceof A</warning>) {}
|
||||
else if (<warning descr="Condition 'a instanceof B' is always 'false'">a instanceof B</warning>) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user