diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index dfd6257ea2c..4efec6aec9b 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -22,6 +22,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess +import com.intellij.pom.java.LanguageLevel import com.intellij.psi.PsiClassOwner import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager @@ -177,6 +178,9 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME_WITH_FULL_JDK") -> KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK + InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME_WITH_JDK_10") -> + KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstance(LanguageLevel.JDK_10) + InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME_WITH_REFLECT") -> KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_WITH_REFLECT diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinWithJdkAndRuntimeLightProjectDescriptor.java b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinWithJdkAndRuntimeLightProjectDescriptor.java index 994bb2bddfe..4acec287728 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinWithJdkAndRuntimeLightProjectDescriptor.java +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinWithJdkAndRuntimeLightProjectDescriptor.java @@ -16,7 +16,11 @@ package org.jetbrains.kotlin.idea.test; +import com.intellij.openapi.module.Module; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.LanguageLevelModuleExtension; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.kotlin.utils.PathUtil; @@ -37,6 +41,18 @@ public class KotlinWithJdkAndRuntimeLightProjectDescriptor extends KotlinJdkAndL @NotNull public static final KotlinWithJdkAndRuntimeLightProjectDescriptor INSTANCE = new KotlinWithJdkAndRuntimeLightProjectDescriptor(); + public static KotlinWithJdkAndRuntimeLightProjectDescriptor getInstance(LanguageLevel level) { + return new KotlinWithJdkAndRuntimeLightProjectDescriptor() { + @Override + public void configureModule( + @NotNull Module module, @NotNull ModifiableRootModel model + ) { + super.configureModule(module, model); + model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(level); + } + }; + } + @NotNull public static final KotlinWithJdkAndRuntimeLightProjectDescriptor INSTANCE_WITH_KOTLIN_TEST = new KotlinWithJdkAndRuntimeLightProjectDescriptor( Arrays.asList(ForTestCompileRuntime.runtimeJarForTests(), diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt index 2828eaf8636..fcb46593d56 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt @@ -516,6 +516,10 @@ private fun PsiType.collectTypeParameters(): List { internal fun PsiType.resolveToKotlinType(resolutionFacade: ResolutionFacade): KotlinType? { + if (this == PsiType.NULL) { + return resolutionFacade.moduleDescriptor.builtIns.nullableAnyType + } + val typeParameters = collectTypeParameters() val components = resolutionFacade.getFrontendService(JavaResolverComponents::class.java) val rootContext = LazyJavaResolverContext(components, TypeParameterResolver.EMPTY) { null } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt.191 b/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt.191 index 52e11d4e4ec..1979d79ffa7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt.191 +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/crossLanguage/KotlinElementActionsFactory.kt.191 @@ -524,6 +524,10 @@ private fun PsiType.collectTypeParameters(): List { internal fun PsiType.resolveToKotlinType(resolutionFacade: ResolutionFacade): KotlinType? { + if (this == PsiType.NULL) { + return resolutionFacade.moduleDescriptor.builtIns.nullableAnyType + } + val typeParameters = collectTypeParameters() val components = resolutionFacade.getFrontendService(JavaResolverComponents::class.java) val rootContext = LazyJavaResolverContext(components, TypeParameterResolver.EMPTY) { null } diff --git a/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.after.Dependency.kt b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.after.Dependency.kt new file mode 100644 index 00000000000..519b1a1c5dc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.after.Dependency.kt @@ -0,0 +1,5 @@ +class Dep { + fun foo(): Any? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.after.java b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.after.java new file mode 100644 index 00000000000..b1aabc72bea --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.after.java @@ -0,0 +1,8 @@ +// "Add method 'foo' to 'Dep'" "true" +// RUNTIME_WITH_JDK_10 +class J { + void test() { + Dep dep = new Dep(); + var foo = dep.foo(); + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Dependency.kt b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Dependency.kt new file mode 100644 index 00000000000..3bb3dd240fc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Dependency.kt @@ -0,0 +1 @@ +class Dep {} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Main.java b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Main.java new file mode 100644 index 00000000000..c6bbd458425 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Main.java @@ -0,0 +1,8 @@ +// "Add method 'foo' to 'Dep'" "true" +// RUNTIME_WITH_JDK_10 +class J { + void test() { + Dep dep = new Dep(); + var foo = dep.foo(); + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 0cd4800805b..901f0ab41d8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -2049,6 +2049,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes runTest("idea/testData/quickfix/createFromUsage/createFunction/fromJava/companionMember.before.Main.java"); } + @TestMetadata("nullType.before.Main.java") + public void testNullType() throws Exception { + runTest("idea/testData/quickfix/createFromUsage/createFunction/fromJava/nullType.before.Main.java"); + } + @TestMetadata("topLevel.before.Main.java") public void testTopLevel() throws Exception { runTest("idea/testData/quickfix/createFromUsage/createFunction/fromJava/topLevel.before.Main.java");