From a0111f91d08c3b55544d15a840abcd894419ead3 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 30 Sep 2019 11:20:38 +0200 Subject: [PATCH] IDEA-220464 Smart-cast completion doesn't insert GitOrigin-RevId: 175651a3f6cf5736ca7676b9fe80b569d4260962 --- .../codeInspection/dataFlow/ControlFlowAnalyzer.java | 3 --- .../completion/smartType/CastToTypeWithWildcard-out.java | 8 ++++++++ .../completion/smartType/CastToTypeWithWildcard.java | 8 ++++++++ .../completion/SmartTypeCompletionDfaTest.groovy | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard-out.java create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index 5c48158efbfc..674f14c70320 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1599,9 +1599,6 @@ public class ControlFlowAnalyzer extends JavaElementVisitor { if (checkType != null) { operand.accept(this); PsiType type = checkType.getType(); - if (type instanceof PsiClassType) { - type = ((PsiClassType)type).rawType(); - } addInstruction(new PushInstruction(myFactory.createTypeValue(type, Nullability.NOT_NULL), null)); addInstruction(new InstanceofInstruction(expression, operand, type)); } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard-out.java b/java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard-out.java new file mode 100644 index 000000000000..791054a88768 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard-out.java @@ -0,0 +1,8 @@ +import java.util.List; + +class Foo { + { + Object o; + int size = o instanceof List ? ((List) o).size() : + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard.java b/java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard.java new file mode 100644 index 000000000000..2d274741e2fe --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/CastToTypeWithWildcard.java @@ -0,0 +1,8 @@ +import java.util.List; + +class Foo { + { + Object o; + int size = o instanceof List ? o.size + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/SmartTypeCompletionDfaTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/SmartTypeCompletionDfaTest.groovy index eca7b524f0ac..f22a8d62bea4 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/SmartTypeCompletionDfaTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/SmartTypeCompletionDfaTest.groovy @@ -80,4 +80,6 @@ class SmartTypeCompletionDfaTest extends LightFixtureCompletionTestCase { void testInstanceofedInsideAnonymous() { doTest() } + void testCastToTypeWithWildcard() { doTest() } + }