Fix EA-126019: Handle 'null' PsiType as nullable Any in "Create" actions
This commit is contained in:
+4
@@ -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
|
||||
|
||||
|
||||
+16
@@ -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(),
|
||||
|
||||
+4
@@ -516,6 +516,10 @@ private fun PsiType.collectTypeParameters(): List<PsiTypeParameter> {
|
||||
|
||||
|
||||
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 }
|
||||
|
||||
+4
@@ -524,6 +524,10 @@ private fun PsiType.collectTypeParameters(): List<PsiTypeParameter> {
|
||||
|
||||
|
||||
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 }
|
||||
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
class Dep {
|
||||
fun foo(): Any? {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
+8
@@ -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.<selection><caret></selection>foo();
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
class Dep {}
|
||||
+8
@@ -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.<caret>foo();
|
||||
}
|
||||
}
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user