diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 4f9cc8b09c3..915cfa2002d 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1588,11 +1588,6 @@ Kotlin - - org.jetbrains.kotlin.idea.intentions.ConvertClassToSealedClassIntention - Kotlin - - org.jetbrains.kotlin.idea.intentions.AddPropertyAccessorsIntention Kotlin diff --git a/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/after.kt.template deleted file mode 100644 index 6117b7cd4f1..00000000000 --- a/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/after.kt.template +++ /dev/null @@ -1,2 +0,0 @@ -sealed class Klass(private val s: String) { -} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/before.kt.template b/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/before.kt.template deleted file mode 100644 index 87261e861eb..00000000000 --- a/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/before.kt.template +++ /dev/null @@ -1,2 +0,0 @@ -open class Klass private constructor(private val s: String) { -} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/description.html b/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/description.html deleted file mode 100644 index 69b394985dc..00000000000 --- a/idea/resources/intentionDescriptions/ConvertClassToSealedClassIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention converts an open or abstract class with only private constructors to a sealed class. - - \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertClassToSealedClassIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertClassToSealedClassIntention.kt deleted file mode 100644 index 2ae0a50cc83..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertClassToSealedClassIntention.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.intentions - -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.TextRange -import org.jetbrains.kotlin.lexer.KtTokens.* -import org.jetbrains.kotlin.psi.KtClass -import org.jetbrains.kotlin.psi.KtPrimaryConstructor -import org.jetbrains.kotlin.psi.psiUtil.endOffset -import org.jetbrains.kotlin.psi.psiUtil.startOffset - -class ConvertClassToSealedClassIntention : SelfTargetingRangeIntention(KtClass::class.java, "Convert to sealed class") { - - override fun applicabilityRange(element: KtClass): TextRange? { - if (element.modifierList == null) return null - if (!element.hasModifier(OPEN_KEYWORD) && !element.hasModifier(ABSTRACT_KEYWORD)) return null - - val constructors = listOfNotNull(element.primaryConstructor) + element.secondaryConstructors - if (constructors.isEmpty()) return null - if (!constructors.all { it.hasModifier(PRIVATE_KEYWORD) && it.getAnnotationEntries().isEmpty() }) return null - - val nameIdentifier = element.nameIdentifier ?: return null - return TextRange(element.startOffset, nameIdentifier.endOffset) - } - - override fun applyTo(element: KtClass, editor: Editor?) { - element.modifierList?.run { - getModifier(OPEN_KEYWORD)?.delete() - getModifier(ABSTRACT_KEYWORD)?.delete() - } - element.addModifier(SEALED_KEYWORD) - - element.primaryConstructor?.run { - if (element.secondaryConstructors.isEmpty() && valueParameters.isEmpty()) { - this.delete() - } - else { - val newConstructor = this.copy() as KtPrimaryConstructor - newConstructor.modifierList?.getModifier(PRIVATE_KEYWORD)?.delete() - newConstructor.getConstructorKeyword()?.delete() - this.replace(newConstructor) - } - } - - element.secondaryConstructors.forEach { - it.modifierList?.getModifier(PRIVATE_KEYWORD)?.delete() - } - } - -} diff --git a/idea/testData/intentions/convertClassToSealedClass/.intention b/idea/testData/intentions/convertClassToSealedClass/.intention deleted file mode 100644 index 6ab3dc22478..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ConvertClassToSealedClassIntention diff --git a/idea/testData/intentions/convertClassToSealedClass/abstract.kt b/idea/testData/intentions/convertClassToSealedClass/abstract.kt deleted file mode 100644 index 2bc8ad9f32d..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/abstract.kt +++ /dev/null @@ -1 +0,0 @@ -abstract class Test private constructor() \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/abstract.kt.after b/idea/testData/intentions/convertClassToSealedClass/abstract.kt.after deleted file mode 100644 index a0246442fe6..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/abstract.kt.after +++ /dev/null @@ -1 +0,0 @@ -sealed class Test \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/noConstructor.kt b/idea/testData/intentions/convertClassToSealedClass/noConstructor.kt deleted file mode 100644 index 942d87066aa..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/noConstructor.kt +++ /dev/null @@ -1,2 +0,0 @@ -// IS_APPLICABLE: false -open class Test \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/notOpenAndAbstract.kt b/idea/testData/intentions/convertClassToSealedClass/notOpenAndAbstract.kt deleted file mode 100644 index f33be4867cf..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/notOpenAndAbstract.kt +++ /dev/null @@ -1,2 +0,0 @@ -// IS_APPLICABLE: false -class Test private constructor() \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/notPrivatePrimaryConstructor.kt b/idea/testData/intentions/convertClassToSealedClass/notPrivatePrimaryConstructor.kt deleted file mode 100644 index 858806e4ff7..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/notPrivatePrimaryConstructor.kt +++ /dev/null @@ -1,2 +0,0 @@ -// IS_APPLICABLE: false -open class Test constructor() \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/notPrivateSecondaryConstructor.kt b/idea/testData/intentions/convertClassToSealedClass/notPrivateSecondaryConstructor.kt deleted file mode 100644 index d72d7747407..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/notPrivateSecondaryConstructor.kt +++ /dev/null @@ -1,5 +0,0 @@ -// IS_APPLICABLE: false -open class Test private constructor() { - constructor(i: Int) : this() { - } -} \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt b/idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt deleted file mode 100644 index a71f040f221..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt +++ /dev/null @@ -1,4 +0,0 @@ -open class Test { - private constructor(i: Int) { - } -} diff --git a/idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt.after b/idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt.after deleted file mode 100644 index b26f1f5d0d7..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt.after +++ /dev/null @@ -1,4 +0,0 @@ -sealed class Test { - constructor(i: Int) { - } -} diff --git a/idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt b/idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt deleted file mode 100644 index 6cd92dbe528..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt +++ /dev/null @@ -1 +0,0 @@ -open class Test private constructor() diff --git a/idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt.after b/idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt.after deleted file mode 100644 index a0246442fe6..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt.after +++ /dev/null @@ -1 +0,0 @@ -sealed class Test \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithAnnotation.kt b/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithAnnotation.kt deleted file mode 100644 index 850a5c8dbc2..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithAnnotation.kt +++ /dev/null @@ -1,3 +0,0 @@ -// IS_APPLICABLE: false -annotation class Inject -open class Test @Inject private constructor() diff --git a/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt b/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt deleted file mode 100644 index 802ab01460c..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt +++ /dev/null @@ -1 +0,0 @@ -open class Test private constructor(s: String) \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt.after b/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt.after deleted file mode 100644 index 9a0279eebb1..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt.after +++ /dev/null @@ -1 +0,0 @@ -sealed class Test(s: String) \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt b/idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt deleted file mode 100644 index 22644d85d3d..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt +++ /dev/null @@ -1,4 +0,0 @@ -open class Test private constructor() { - private constructor(i: Int) : this() { - } -} \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt.after b/idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt.after deleted file mode 100644 index 5ea8e0e46f3..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt.after +++ /dev/null @@ -1,4 +0,0 @@ -sealed class Test() { - constructor(i: Int) : this() { - } -} \ No newline at end of file diff --git a/idea/testData/intentions/convertClassToSealedClass/secondaryConstructorWithAnnotation.kt b/idea/testData/intentions/convertClassToSealedClass/secondaryConstructorWithAnnotation.kt deleted file mode 100644 index e7c60ecdbaf..00000000000 --- a/idea/testData/intentions/convertClassToSealedClass/secondaryConstructorWithAnnotation.kt +++ /dev/null @@ -1,6 +0,0 @@ -// IS_APPLICABLE: false -annotation class Inject -open class Test private constructor() { - private @Inject constructor(i: Int) : this() { - } -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 4f5e3667ee6..871b41ba59a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -4850,74 +4850,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } - @TestMetadata("idea/testData/intentions/convertClassToSealedClass") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ConvertClassToSealedClass extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - @TestMetadata("abstract.kt") - public void testAbstract() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/abstract.kt"); - } - - public void testAllFilesPresentInConvertClassToSealedClass() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertClassToSealedClass"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("noConstructor.kt") - public void testNoConstructor() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/noConstructor.kt"); - } - - @TestMetadata("notOpenAndAbstract.kt") - public void testNotOpenAndAbstract() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/notOpenAndAbstract.kt"); - } - - @TestMetadata("notPrivatePrimaryConstructor.kt") - public void testNotPrivatePrimaryConstructor() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/notPrivatePrimaryConstructor.kt"); - } - - @TestMetadata("notPrivateSecondaryConstructor.kt") - public void testNotPrivateSecondaryConstructor() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/notPrivateSecondaryConstructor.kt"); - } - - @TestMetadata("onlySecondaryConstructor.kt") - public void testOnlySecondaryConstructor() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/onlySecondaryConstructor.kt"); - } - - @TestMetadata("primaryConstructor.kt") - public void testPrimaryConstructor() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/primaryConstructor.kt"); - } - - @TestMetadata("primaryConstructorWithAnnotation.kt") - public void testPrimaryConstructorWithAnnotation() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithAnnotation.kt"); - } - - @TestMetadata("primaryConstructorWithValueParameter.kt") - public void testPrimaryConstructorWithValueParameter() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/primaryConstructorWithValueParameter.kt"); - } - - @TestMetadata("secondaryConstructor.kt") - public void testSecondaryConstructor() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/secondaryConstructor.kt"); - } - - @TestMetadata("secondaryConstructorWithAnnotation.kt") - public void testSecondaryConstructorWithAnnotation() throws Exception { - runTest("idea/testData/intentions/convertClassToSealedClass/secondaryConstructorWithAnnotation.kt"); - } - } - @TestMetadata("idea/testData/intentions/convertCollectionConstructorToFunction") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)