From f0a1247707ff9d7bcdcc65a49f6fcd0543cc4d13 Mon Sep 17 00:00:00 2001 From: "Konstantin.Nisht" Date: Fri, 27 Sep 2019 11:44:35 +0300 Subject: [PATCH] avoid creating intersections from unresolved classes GitOrigin-RevId: 3df59f4427f120185f8da6744500530402fbbfc0 --- .../intentions/style/inference/InferenceProcessUtil.kt | 5 +++-- .../InferMethodParametersTypesIntentionTest.groovy | 3 +++ .../inferMethodParametersTypes/UnresolvedCode2.groovy | 7 +++++++ .../UnresolvedCode2_after.groovy | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2.groovy create mode 100644 plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2_after.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/inference/InferenceProcessUtil.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/inference/InferenceProcessUtil.kt index a0fc5a531b10..f89f9f7802e9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/inference/InferenceProcessUtil.kt +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/inference/InferenceProcessUtil.kt @@ -98,7 +98,8 @@ fun PsiType.forceWildcardsAsTypeArguments(): PsiType { val resolvedClass = classType.resolve() if (resolvedClass != null) { return factory.createType(resolvedClass, *mappedParameters.toTypedArray()) - } else { + } + else { return PsiWildcardType.createUnbounded(manager) } } @@ -243,7 +244,7 @@ fun PsiSubstitutor.removeForeignTypeParameters(method: GrMethod): PsiSubstitutor } override fun visitIntersectionType(intersectionType: PsiIntersectionType?): PsiType? { - return compress(intersectionType?.conjuncts?.filterNotNull()?.map { it.accept(this) }) + return compress(intersectionType?.conjuncts?.filterNotNull()?.mapNotNull { it.accept(this) }) } override fun visitWildcardType(wildcardType: PsiWildcardType?): PsiType? { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InferMethodParametersTypesIntentionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InferMethodParametersTypesIntentionTest.groovy index 9c3115b0c19e..55f21b9f2bc2 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InferMethodParametersTypesIntentionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InferMethodParametersTypesIntentionTest.groovy @@ -517,4 +517,7 @@ class AA { static void foo(Integer a) {} } doTest(true) } + void testUnresolvedCode2() { + doTest(true) + } } diff --git a/plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2.groovy b/plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2.groovy new file mode 100644 index 000000000000..3ec4eb6dfee7 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2.groovy @@ -0,0 +1,7 @@ +def foo(a) { + +} + +def void m() { + foo(null as T) +} diff --git a/plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2_after.groovy b/plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2_after.groovy new file mode 100644 index 000000000000..0b1d9eca1e7e --- /dev/null +++ b/plugins/groovy/testdata/refactoring/inferMethodParametersTypes/UnresolvedCode2_after.groovy @@ -0,0 +1,7 @@ +void foo(Object a) { + +} + +def void m() { + foo(null as T) +}