mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cast conflict should not be reported when additional check is performed in the same binary expr
This commit is contained in:
@@ -113,6 +113,9 @@ public class InstanceOfUtils {
|
||||
}
|
||||
else if (tokenType == JavaTokenType.OROR) {
|
||||
for (PsiExpression operand : expression.getOperands()) {
|
||||
if (operand instanceof PsiPrefixExpression && ((PsiPrefixExpression)operand).getOperationTokenType() == JavaTokenType.EXCL) {
|
||||
inElse = true;
|
||||
}
|
||||
checkExpression(operand);
|
||||
}
|
||||
if (inElse && conflictingInstanceof != null) {
|
||||
@@ -125,8 +128,7 @@ public class InstanceOfUtils {
|
||||
public void visitIfStatement(PsiIfStatement ifStatement) {
|
||||
final PsiStatement branch = ifStatement.getElseBranch();
|
||||
inElse = branch != null &&
|
||||
PsiTreeUtil.isAncestor(branch, referenceExpression,
|
||||
true);
|
||||
PsiTreeUtil.isAncestor(branch, referenceExpression, true);
|
||||
if (inElse) {
|
||||
if (branch instanceof PsiBlockStatement) {
|
||||
final PsiBlockStatement blockStatement =
|
||||
@@ -161,8 +163,7 @@ public class InstanceOfUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConditionalExpression(
|
||||
PsiConditionalExpression expression) {
|
||||
public void visitConditionalExpression(PsiConditionalExpression expression) {
|
||||
final PsiExpression elseExpression =
|
||||
expression.getElseExpression();
|
||||
inElse = elseExpression != null &&
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface I1 {}
|
||||
interface I2 extends I1{}
|
||||
interface I3 extends I1 {}
|
||||
|
||||
class PP {
|
||||
void f(Object o) {
|
||||
if (o instanceof I1) {
|
||||
if (!(o instanceof I2) || ((I2)o).getClass() != null){}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
+4
@@ -38,6 +38,10 @@ public class CastConflictsWithInstanceofInspectionTest extends IGInspectionTestC
|
||||
public void testPolyadic() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotOr() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest("com/siyeh/igtest/bugs/castConflictingInstanceof/" + getTestName(true), new CastConflictsWithInstanceofInspection());
|
||||
|
||||
Reference in New Issue
Block a user