diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt index 657ccf79fcf..017eec2dcb2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt @@ -7,10 +7,13 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.core.setType import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression +import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtNullableType import org.jetbrains.kotlin.psi.KtProperty @@ -27,7 +30,9 @@ class ConvertNullablePropertyToLateinitIntention : SelfTargetingIntentionvar foo: String? = null } \ No newline at end of file diff --git a/idea/testData/intentions/convertNullablePropertyToLateinit/local.kt.after b/idea/testData/intentions/convertNullablePropertyToLateinit/local.kt.after new file mode 100644 index 00000000000..3c5363223c5 --- /dev/null +++ b/idea/testData/intentions/convertNullablePropertyToLateinit/local.kt.after @@ -0,0 +1,3 @@ +fun test() { + lateinit var foo: String +} \ No newline at end of file diff --git a/idea/testData/intentions/convertNullablePropertyToLateinit/localLegacy.kt b/idea/testData/intentions/convertNullablePropertyToLateinit/localLegacy.kt new file mode 100644 index 00000000000..82344cec259 --- /dev/null +++ b/idea/testData/intentions/convertNullablePropertyToLateinit/localLegacy.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false +// LANGUAGE_VERSION: 1.1 +fun test() { + var foo: String? = null +} \ No newline at end of file diff --git a/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt b/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt index eb0d9a45001..4cd62eb2004 100644 --- a/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt +++ b/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt @@ -1,2 +1 @@ -// IS_APPLICABLE: false var foo: String? = null \ No newline at end of file diff --git a/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt.after b/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt.after new file mode 100644 index 00000000000..15a285408ee --- /dev/null +++ b/idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt.after @@ -0,0 +1 @@ +lateinit var foo: String \ No newline at end of file diff --git a/idea/testData/intentions/convertNullablePropertyToLateinit/topLevelLegacy.kt b/idea/testData/intentions/convertNullablePropertyToLateinit/topLevelLegacy.kt new file mode 100644 index 00000000000..5617ddf78c5 --- /dev/null +++ b/idea/testData/intentions/convertNullablePropertyToLateinit/topLevelLegacy.kt @@ -0,0 +1,3 @@ +// IS_APPLICABLE: false +// LANGUAGE_VERSION: 1.1 +var foo: String? = null \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt index a01372f9620..4cca5998324 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt @@ -33,9 +33,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil import com.intellij.testFramework.PlatformTestUtil import junit.framework.ComparisonFailure import junit.framework.TestCase -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil -import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.* import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils @@ -106,6 +104,7 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() { val pathToFiles = mapOf(*(sourceFilePaths zip psiFiles).toTypedArray()) val fileText = FileUtil.loadFile(mainFile, true) + val configured = configureCompilerOptions(fileText, project, module) ConfigLibraryUtil.configureLibrariesByDirective(myModule, PlatformTestUtil.getCommunityPath(), fileText) @@ -124,9 +123,11 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() { if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) { DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile) } - } - finally { + } finally { ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText) + if (configured) { + rollbackCompilerOptions(project, module) + } } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index d9e10a40bab..17729b8a2a2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -5910,6 +5910,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/convertNullablePropertyToLateinit/local.kt"); } + @TestMetadata("localLegacy.kt") + public void testLocalLegacy() throws Exception { + runTest("idea/testData/intentions/convertNullablePropertyToLateinit/localLegacy.kt"); + } + @TestMetadata("nonNullInitializer.kt") public void testNonNullInitializer() throws Exception { runTest("idea/testData/intentions/convertNullablePropertyToLateinit/nonNullInitializer.kt"); @@ -5940,6 +5945,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/convertNullablePropertyToLateinit/topLevel.kt"); } + @TestMetadata("topLevelLegacy.kt") + public void testTopLevelLegacy() throws Exception { + runTest("idea/testData/intentions/convertNullablePropertyToLateinit/topLevelLegacy.kt"); + } + @TestMetadata("unsignedInt.kt") public void testUnsignedInt() throws Exception { runTest("idea/testData/intentions/convertNullablePropertyToLateinit/unsignedInt.kt");