diff --git a/idea/testData/quickfix/autoImports/afterLibraryClassJsRuntime.kt b/idea/testData/quickfix/autoImports/afterLibraryClassJsRuntime.kt new file mode 100644 index 00000000000..165319aee97 --- /dev/null +++ b/idea/testData/quickfix/autoImports/afterLibraryClassJsRuntime.kt @@ -0,0 +1,10 @@ +// "Import" "true" +// ERROR: Please specify constructor invocation; classifier 'HTMLStyleElement' does not have a companion object + +package test + +import kotlin.js.dom.html.HTMLStyleElement + +fun foo() { + HTMLStyleElement +} diff --git a/idea/testData/quickfix/autoImports/afterLibraryPropertyJsRuntime.kt b/idea/testData/quickfix/autoImports/afterLibraryPropertyJsRuntime.kt new file mode 100644 index 00000000000..4cbcb3c35cd --- /dev/null +++ b/idea/testData/quickfix/autoImports/afterLibraryPropertyJsRuntime.kt @@ -0,0 +1,9 @@ +// "Import" "true" + +package test + +import kotlin.js.dom.html5.localStorage + +fun foo() { + localStorage +} diff --git a/idea/testData/quickfix/autoImports/afterLibraryTopLevelFunctionImportJsRuntime.kt b/idea/testData/quickfix/autoImports/afterLibraryTopLevelFunctionImportJsRuntime.kt new file mode 100644 index 00000000000..9191f37fa61 --- /dev/null +++ b/idea/testData/quickfix/autoImports/afterLibraryTopLevelFunctionImportJsRuntime.kt @@ -0,0 +1,8 @@ +// "Import" "true" +package some + +import jquery.jq + +fun testFun() { + jq() +} diff --git a/idea/testData/quickfix/autoImports/beforeLibraryClassJsRuntime.kt b/idea/testData/quickfix/autoImports/beforeLibraryClassJsRuntime.kt new file mode 100644 index 00000000000..d085e1a51a4 --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeLibraryClassJsRuntime.kt @@ -0,0 +1,8 @@ +// "Import" "true" +// ERROR: Please specify constructor invocation; classifier 'HTMLStyleElement' does not have a companion object + +package test + +fun foo() { + HTMLStyleElement +} diff --git a/idea/testData/quickfix/autoImports/beforeLibraryPropertyJsRuntime.kt b/idea/testData/quickfix/autoImports/beforeLibraryPropertyJsRuntime.kt new file mode 100644 index 00000000000..5b2f39b0d5e --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeLibraryPropertyJsRuntime.kt @@ -0,0 +1,7 @@ +// "Import" "true" + +package test + +fun foo() { + localStorage +} diff --git a/idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportJsRuntime.kt b/idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportJsRuntime.kt new file mode 100644 index 00000000000..ce2c54ee0a6 --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportJsRuntime.kt @@ -0,0 +1,6 @@ +// "Import" "true" +package some + +fun testFun() { + jq() +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java index 63fda4d6c19..4d52b746804 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java @@ -67,12 +67,8 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase { } protected void doTest(@NotNull String beforeFileName) throws Exception { - boolean isWithRuntime = beforeFileName.endsWith("Runtime.kt"); - try { - if (isWithRuntime) { - ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK()); - } + configureRuntimeIfNeeded(beforeFileName); enableInspections(beforeFileName); @@ -81,9 +77,25 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase { checkForUnexpectedErrors(); } finally { - if (isWithRuntime) { - ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK()); - } + unConfigureRuntimeIfNeeded(beforeFileName); + } + } + + private static void configureRuntimeIfNeeded(@NotNull String beforeFileName) { + if (beforeFileName.endsWith("JsRuntime.kt")) { + ConfigLibraryUtil.configureKotlinJsRuntime(getModule(), getFullJavaJDK()); + } + else if (beforeFileName.endsWith("Runtime.kt")) { + ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK()); + } + } + + private void unConfigureRuntimeIfNeeded(@NotNull String beforeFileName) { + if (beforeFileName.endsWith("JsRuntime.kt")) { + ConfigLibraryUtil.unConfigureKotlinJsRuntime(getModule(), getProjectJDK()); + } + else if (beforeFileName.endsWith("Runtime.kt")) { + ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK()); } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 7160a0be7f1..17dc4ce0d33 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -395,12 +395,30 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("beforeLibraryClassJsRuntime.kt") + public void testLibraryClassJsRuntime() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryClassJsRuntime.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLibraryPropertyJsRuntime.kt") + public void testLibraryPropertyJsRuntime() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryPropertyJsRuntime.kt"); + doTest(fileName); + } + @TestMetadata("beforeLibraryPropertyRuntime.kt") public void testLibraryPropertyRuntime() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryPropertyRuntime.kt"); doTest(fileName); } + @TestMetadata("beforeLibraryTopLevelFunctionImportJsRuntime.kt") + public void testLibraryTopLevelFunctionImportJsRuntime() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportJsRuntime.kt"); + doTest(fileName); + } + @TestMetadata("beforeLibraryTopLevelFunctionImportRuntime.kt") public void testLibraryTopLevelFunctionImportRuntime() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportRuntime.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/test/ConfigLibraryUtil.java b/idea/tests/org/jetbrains/kotlin/test/ConfigLibraryUtil.java index 358d9133e3b..1cfe617def5 100644 --- a/idea/tests/org/jetbrains/kotlin/test/ConfigLibraryUtil.java +++ b/idea/tests/org/jetbrains/kotlin/test/ConfigLibraryUtil.java @@ -60,6 +60,10 @@ public class ConfigLibraryUtil { unConfigureLibrary(module, sdk, DEFAULT_JAVA_RUNTIME_LIB_NAME); } + public static void unConfigureKotlinJsRuntime(Module module, Sdk sdk) { + unConfigureLibrary(module, sdk, DEFAULT_KOTLIN_JS_STDLIB_NAME); + } + public static void configureLibrary(Module module, Sdk sdk, NewLibraryEditor libraryEditor) { configureSdk(module, sdk); addLibrary(libraryEditor, module);