diff --git a/idea/resources-en/inspectionDescriptions/ObsoleteKotlinJsPackages.html b/idea/resources-en/inspectionDescriptions/ObsoleteKotlinJsPackages.html new file mode 100644 index 00000000000..04ebed2fd4b --- /dev/null +++ b/idea/resources-en/inspectionDescriptions/ObsoleteKotlinJsPackages.html @@ -0,0 +1,6 @@ + + +This inspection reports usages of 'kotlin.dom' and 'kotlin.browser' packages which were moved to 'kotlinx.dom' and 'kotlinx.browser' +respectively in Kotlin 1.4+. + + \ No newline at end of file diff --git a/idea/resources-en/messages/KotlinBundle.properties b/idea/resources-en/messages/KotlinBundle.properties index c53f84c71d9..70671e0293b 100644 --- a/idea/resources-en/messages/KotlinBundle.properties +++ b/idea/resources-en/messages/KotlinBundle.properties @@ -1314,11 +1314,16 @@ missing.documentation=Missing documentation library.should.be.updated.to.be.compatible.with.kotlin.1.3=Library should be updated to be compatible with Kotlin 1.3 it.s.prohibited.to.call.0.with.min.value.step.since.1.3=It''s prohibited to call {0} with MIN_VALUE step since 1.3 obsolete.coroutine.usage.in.whole.fix.family.name=Fix experimental coroutines usages in the project +obsolete.kotlin.js.packages.usage.in.whole.fix.family.name=Fix 'kotlin.dom' and 'kotlin.browser' packages usages in the project apply.in.the.project.0=Apply in the project: {0} obsolete.coroutine.usage.fix.family.name=Fix experimental coroutines usage +obsolete.kotlin.browser.usage.fix.family.name=Fix 'kotlin.browser' package usage +obsolete.kotlin.dom.usage.fix.family.name=Fix 'kotlin.dom' package usage 0.is.expected.to.be.used.since.kotlin.1.3=`{0}` is expected to be used since Kotlin 1.3 methods.are.absent.in.coroutines.class.since.1.3=Methods are absent in coroutines class since 1.3 experimental.coroutines.usages.are.obsolete.since.1.3=Experimental coroutines usages are obsolete since 1.3 +kotlin.browser.usages.are.obsolete.since.1.3='kotlin.browser' package usages are obsolete since 1.4 +kotlin.dom.usages.are.obsolete.since.1.3='kotlin.dom' package usages are obsolete since 1.4 replace.substring.call.with.droplast.call=Replace 'substring' call with 'dropLast' call replace.substring.call.with.indexing.operation.call=Replace 'substring' call with indexing operation call replace.substring.call.with.substringbefore.call=Replace 'substring' call with 'substringBefore' call @@ -2028,6 +2033,7 @@ inspection.suspicious.as.dynamic.display.name=Suspicious 'asDynamic' member invo inspection.convert.call.chain.into.sequence.display.name=Call chain on collection could be converted into 'Sequence' to improve performance inspection.redundant.with.display.name=Redundant 'with' call inspection.obsolete.experimental.coroutines.display.name=Experimental coroutines usages are deprecated since 1.3 +inspection.obsolete.kotlin.js.packages.display.name='kotlin.browser' and 'kotlin.dom' packages are deprecated since 1.4 inspection.warning.on.main.unused.parameter.migration.display.name=Unused `args` on `main` since 1.4 inspection.prohibit.repeated.use.site.target.annotations.migration.display.name=Repeatable annotation without `@Repeatable` are not allowed since 1.4 inspection.prohibit.use.site.target.annotations.on.super.types.migration.display.name=Annotations on superclass are meaningless since 1.4 diff --git a/idea/resources/META-INF/inspections.xml b/idea/resources/META-INF/inspections.xml index 4f009feab37..125d7ea792d 100644 --- a/idea/resources/META-INF/inspections.xml +++ b/idea/resources/META-INF/inspections.xml @@ -2162,6 +2162,15 @@ language="kotlin" key="inspection.obsolete.experimental.coroutines.display.name" bundle="messages.KotlinBundle"/> + + = listOf( + KotlinBrowserImportUsageProblem, + KotlinDomImportUsageProblem + ) +} + +private object ObsoleteKotlinJsPackagesUsagesInWholeProjectFix : ObsoleteCodeInWholeProjectFix() { + override val inspectionName: String = ObsoleteKotlinJsPackagesInspection().shortName + override fun getFamilyName(): String = KotlinBundle.message("obsolete.kotlin.js.packages.usage.in.whole.fix.family.name") +} + +private class ObsoleteKotlinBrowserUsageFix(delegate: ObsoleteCodeFix) : ObsoleteCodeFixDelegateQuickFix(delegate) { + override fun getFamilyName(): String = KotlinBundle.message("obsolete.kotlin.browser.usage.fix.family.name") +} + +private class ObsoleteKotlinDomUsageFix(delegate: ObsoleteCodeFix) : ObsoleteCodeFixDelegateQuickFix(delegate) { + override fun getFamilyName(): String = KotlinBundle.message("obsolete.kotlin.dom.usage.fix.family.name") +} + +private object KotlinBrowserImportUsageProblem : ObsoleteImportsUsage() { + override val textMarker: String = "browser" + override val packageBindings: Map = mapOf("kotlin.browser" to "kotlinx.browser") + + override val wholeProjectFix: LocalQuickFix = ObsoleteKotlinJsPackagesUsagesInWholeProjectFix + override fun problemMessage(): String = KotlinBundle.message("kotlin.browser.usages.are.obsolete.since.1.3") + + override fun wrapFix(fix: ObsoleteCodeFix): LocalQuickFix = ObsoleteKotlinBrowserUsageFix(fix) +} + +private object KotlinDomImportUsageProblem : ObsoleteImportsUsage() { + override val textMarker: String = "dom" + override val packageBindings: Map = mapOf("kotlin.dom" to "kotlinx.dom") + + override val wholeProjectFix: LocalQuickFix = ObsoleteKotlinJsPackagesUsagesInWholeProjectFix + override fun problemMessage(): String = KotlinBundle.message("kotlin.dom.usages.are.obsolete.since.1.3") + + override fun wrapFix(fix: ObsoleteCodeFix): LocalQuickFix = ObsoleteKotlinDomUsageFix(fix) +} diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/.inspection b/idea/testData/quickfix/obsoleteKotlinJsPackages/.inspection new file mode 100644 index 00000000000..46e5ecbbaf1 --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.migration.ObsoleteKotlinJsPackagesInspection \ No newline at end of file diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt new file mode 100644 index 00000000000..29c044018d3 --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt @@ -0,0 +1,7 @@ +// "Fix 'kotlin.browser' package usage" "true" +// JS + +package test + +import kotlin.browser.localStorage +import kotlin.dom.addClass \ No newline at end of file diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt.after b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt.after new file mode 100644 index 00000000000..39788ab1df4 --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt.after @@ -0,0 +1,7 @@ +// "Fix 'kotlin.browser' package usage" "true" +// JS + +package test + +import kotlinx.browser.localStorage +import kotlin.dom.addClass \ No newline at end of file diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt new file mode 100644 index 00000000000..0925108565e --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt @@ -0,0 +1,7 @@ +// "Fix 'kotlin.browser' package usage" "true" +// JS + +package test + +import kotlin.browser.* +import kotlin.dom.* diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt.after b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt.after new file mode 100644 index 00000000000..be16f7a41ba --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt.after @@ -0,0 +1,7 @@ +// "Fix 'kotlin.browser' package usage" "true" +// JS + +package test + +import kotlinx.browser.* +import kotlin.dom.* diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt new file mode 100644 index 00000000000..48bc1a22ff6 --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt @@ -0,0 +1,7 @@ +// "Fix 'kotlin.dom' package usage" "true" +// JS + +package test + +import kotlin.browser.localStorage +import kotlin.dom.addClass \ No newline at end of file diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt.after b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt.after new file mode 100644 index 00000000000..03ae880f49b --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt.after @@ -0,0 +1,7 @@ +// "Fix 'kotlin.dom' package usage" "true" +// JS + +package test + +import kotlin.browser.localStorage +import kotlinx.dom.addClass \ No newline at end of file diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt new file mode 100644 index 00000000000..272dd8dfbc5 --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt @@ -0,0 +1,7 @@ +// "Fix 'kotlin.dom' package usage" "true" +// JS + +package test + +import kotlin.browser.* +import kotlin.dom.* diff --git a/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt.after b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt.after new file mode 100644 index 00000000000..d3f95448d41 --- /dev/null +++ b/idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt.after @@ -0,0 +1,7 @@ +// "Fix 'kotlin.dom' package usage" "true" +// JS + +package test + +import kotlin.browser.* +import kotlinx.dom.* diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index c771acb36eb..2cffbc371d0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -3531,6 +3531,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/obsoleteKotlinJsPackages") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ObsoleteKotlinJsPackages extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, this, testDataFilePath); + } + + public void testAllFilesPresentInObsoleteKotlinJsPackages() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/obsoleteKotlinJsPackages"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), null, true); + } + } + @TestMetadata("idea/testData/quickfix/optimizeImports") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 5885dc71fe1..6a39f5d6ed0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -9886,6 +9886,39 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/obsoleteKotlinJsPackages") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ObsoleteKotlinJsPackages extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInObsoleteKotlinJsPackages() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/obsoleteKotlinJsPackages"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true); + } + + @TestMetadata("kotlinBrowserPropertyImport.kt") + public void testKotlinBrowserPropertyImport() throws Exception { + runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt"); + } + + @TestMetadata("kotlinBrowserStarImport.kt") + public void testKotlinBrowserStarImport() throws Exception { + runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt"); + } + + @TestMetadata("kotlinDomPropertyImport.kt") + public void testKotlinDomPropertyImport() throws Exception { + runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt"); + } + + @TestMetadata("kotlinDomStarImport.kt") + public void testKotlinDomStarImport() throws Exception { + runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt"); + } + } + @TestMetadata("idea/testData/quickfix/optimizeImports") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)