From 501bac130ef4f528d5cf2c0dca8d3855f65836f2 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 9 Nov 2012 13:35:04 +0100 Subject: [PATCH] IDEA-94181 Boolean truth inference --- .../dataFlow/ControlFlowAnalyzer.java | 10 ++++------ .../fixture/LastConstantConditionInAnd.java | 14 ++++++++++++++ .../inspection/dataFlow/unboxingNPE/expected.xml | 9 +++++++++ .../DataFlowInspectionFixtureTest.java | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/LastConstantConditionInAnd.java diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index c4eb8a206e2a..5edaf3d192d6 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1094,15 +1094,13 @@ class ControlFlowAnalyzer extends JavaElementVisitor { PsiExpression operand = operands[i]; operand.accept(this); generateBoxingUnboxingInstructionFor(operand, exprType); - PsiExpression nextOperand = i == operands.length - 1 ? null : operands[i + 1]; - if (nextOperand != null) { - ConditionalGotoInstruction onFail = new ConditionalGotoInstruction(-1, true, operand); - branchToFail.add(onFail); - addInstruction(onFail); - } + ConditionalGotoInstruction onFail = new ConditionalGotoInstruction(-1, true, operand); + branchToFail.add(onFail); + addInstruction(onFail); } + addInstruction(new PushInstruction(myFactory.getConstFactory().getTrue(), null)); GotoInstruction toSuccess = new GotoInstruction(-1); addInstruction(toSuccess); PushInstruction pushFalse = new PushInstruction(myFactory.getConstFactory().getFalse(), null); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/LastConstantConditionInAnd.java b/java/java-tests/testData/inspection/dataFlow/fixture/LastConstantConditionInAnd.java new file mode 100644 index 000000000000..be27aa71b714 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/LastConstantConditionInAnd.java @@ -0,0 +1,14 @@ +class Fun { + private void parseDeclarator(Object builder, boolean isTuple) { + if (!isTuple) { + return; + } + else { + if (smth() && isTuple) { + System.out.println(); + } + } + } + + boolean smth() { return true; } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml b/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml index b0d1a3312766..000168e3d991 100644 --- a/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml +++ b/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml @@ -375,4 +375,13 @@ Constant conditions & exceptions Unboxing of <code>i</code> may produce <code>java.lang.NullPointerException</code>. + + + Test.java + 67 + <default> + Constant conditions & exceptions + Condition <code>i</code> is always <code>true</code> when reached + + diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index 61f527ea101b..229e2768179b 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -138,5 +138,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testMethodCallFlushesField() { doTest(); } public void testUnknownFloatMayBeNaN() { doTest(); } + public void testLastConstantConditionInAnd() { doTest(); } }