Fix secondary constructor deletion in "sealed class -> object"
This commit is contained in:
+3
-2
@@ -14,6 +14,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.idea.intentions.ConvertSecondaryConstructorToPrimaryIntention
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
@@ -47,9 +48,9 @@ class ConvertSealedSubClassToObjectFix : LocalQuickFix {
|
||||
}
|
||||
|
||||
private fun KtClass.changeToObject(factory: KtPsiFactory) {
|
||||
getClassOrInterfaceKeyword()?.replace(factory.createExpression(KtTokens.OBJECT_KEYWORD.value))
|
||||
secondaryConstructors.forEach { delete() }
|
||||
secondaryConstructors.forEach { ConvertSecondaryConstructorToPrimaryIntention().applyTo(it, null) }
|
||||
primaryConstructor?.delete()
|
||||
getClassOrInterfaceKeyword()?.replace(factory.createExpression(KtTokens.OBJECT_KEYWORD.value))
|
||||
}
|
||||
|
||||
private fun KtClass.transformToObject(factory: KtPsiFactory) {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FIX: Convert sealed sub-class to object
|
||||
// WITH_RUNTIME
|
||||
|
||||
sealed class Sealed
|
||||
|
||||
<caret>class SubSealed : Sealed() {
|
||||
constructor() {
|
||||
println("init")
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FIX: Convert sealed sub-class to object
|
||||
// WITH_RUNTIME
|
||||
|
||||
sealed class Sealed
|
||||
|
||||
object SubSealed : Sealed() {
|
||||
init {
|
||||
println("init")
|
||||
}
|
||||
}
|
||||
+5
@@ -1696,6 +1696,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/convertSealedSubClassToObject/convertSubClassWithParentheses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("convertSubClassWithSecondaryConstructor.kt")
|
||||
public void testConvertSubClassWithSecondaryConstructor() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/convertSealedSubClassToObject/convertSubClassWithSecondaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("convertSubClassWithoutParentheses.kt")
|
||||
public void testConvertSubClassWithoutParentheses() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/convertSealedSubClassToObject/convertSubClassWithoutParentheses.kt");
|
||||
|
||||
Reference in New Issue
Block a user