diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties index 879ab434951..c2ced4cda32 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties @@ -12,8 +12,6 @@ remove.parts.from.property.family=Remove parts from property remove.psi.element.family=Remove element remove.right.part.of.binary.expression=Remove right part of a binary expression remove.elvis.operator=Remove elvis operator -remove.supertype=Remove supertype ''{0}'' -remove.supertype.family=Remove supertype remove.type.arguments=Remove type arguments remove.useless.nullable=Remove useless '?' remove.spread.sign=Remove '*' diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index c6d5c2a32be..1dfcdfe0edb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -289,7 +289,7 @@ class QuickFixRegistrar : QuickFixContributor { PLATFORM_CLASS_MAPPED_TO_KOTLIN.registerFactory(MapPlatformClassToKotlinFix) - MANY_CLASSES_IN_SUPERTYPE_LIST.registerFactory(RemoveSupertypeFix.createFactory()) + MANY_CLASSES_IN_SUPERTYPE_LIST.registerFactory(RemoveSupertypeFix) NO_GET_METHOD.registerFactory(CreateGetFunctionActionFactory) NO_SET_METHOD.registerFactory(CreateSetFunctionActionFactory) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.kt index f2219b44b88..c06eacd9b6f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.kt @@ -14,64 +14,30 @@ * limitations under the License. */ -package org.jetbrains.kotlin.idea.quickfix; +package org.jetbrains.kotlin.idea.quickfix -import com.intellij.lang.ASTNode; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.impl.PsiImplUtil; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.diagnostics.Diagnostic; -import org.jetbrains.kotlin.idea.KotlinBundle; -import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil; -import org.jetbrains.kotlin.lexer.KtTokens; -import org.jetbrains.kotlin.psi.KtSuperTypeListEntry; -import org.jetbrains.kotlin.psi.KtFile; +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtSuperTypeListEntry +import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -public class RemoveSupertypeFix extends KotlinQuickFixAction { - private final KtSuperTypeListEntry superClass; +class RemoveSupertypeFix(superClass: KtSuperTypeListEntry) : KotlinQuickFixAction(superClass) { + override fun getFamilyName() = "Remove supertype" - public RemoveSupertypeFix(@NotNull KtSuperTypeListEntry superClass) { - super(superClass); - this.superClass = superClass; + override fun getText() = familyName + + public override fun invoke(project: Project, editor: Editor?, file: KtFile) { + element.getStrictParentOfType()?.removeSuperTypeListEntry(element) } - @NotNull - @Override - public String getText() { - return KotlinBundle.message("remove.supertype", superClass.getText()); - } - - @NotNull - @Override - public String getFamilyName() { - return KotlinBundle.message("remove.supertype.family"); - } - - @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { - // Find the preceding comma and delete it as well. - // We must ignore whitespaces and comments when looking for the comma. - PsiElement prevSibling = superClass.getPrevSibling(); - assert prevSibling != null: "A PSI element should exist before supertype declaration"; - ASTNode prev = PsiImplUtil.skipWhitespaceAndCommentsBack(prevSibling.getNode()); - assert prev != null: "A non-whitespace element should exist before supertype declaration"; - if (prev.getElementType() == KtTokens.COMMA) { - prev.getPsi().delete(); + companion object : KotlinSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction? { + val superClass = diagnostic.psiElement.getNonStrictParentOfType() ?: return null + return RemoveSupertypeFix(superClass) } - superClass.delete(); - } - - public static KotlinSingleIntentionActionFactory createFactory() { - return new KotlinSingleIntentionActionFactory() { - @Override - public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { - KtSuperTypeListEntry superClass = QuickFixUtil.getParentElementOfType(diagnostic, KtSuperTypeListEntry.class); - if (superClass == null) return null; - return new RemoveSupertypeFix(superClass); - } - }; } } diff --git a/idea/testData/quickfix/modifiers/removeSupertype1.kt b/idea/testData/quickfix/modifiers/removeSupertype1.kt index 3cc206805b7..e58abb36861 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype1.kt +++ b/idea/testData/quickfix/modifiers/removeSupertype1.kt @@ -1,4 +1,4 @@ -// "Remove supertype 'C2()'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1(), C2() {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype1.kt.after b/idea/testData/quickfix/modifiers/removeSupertype1.kt.after index 03a240e4187..9cbe42b8e17 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype1.kt.after +++ b/idea/testData/quickfix/modifiers/removeSupertype1.kt.after @@ -1,4 +1,4 @@ -// "Remove supertype 'C2()'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1() {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype2.kt b/idea/testData/quickfix/modifiers/removeSupertype2.kt index fbe4a8cee99..ce761405c83 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype2.kt +++ b/idea/testData/quickfix/modifiers/removeSupertype2.kt @@ -1,4 +1,4 @@ -// "Remove supertype 'C2()'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1(),C2() {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype2.kt.after b/idea/testData/quickfix/modifiers/removeSupertype2.kt.after index 03a240e4187..9cbe42b8e17 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype2.kt.after +++ b/idea/testData/quickfix/modifiers/removeSupertype2.kt.after @@ -1,4 +1,4 @@ -// "Remove supertype 'C2()'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1() {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype3.kt b/idea/testData/quickfix/modifiers/removeSupertype3.kt index 3090283f8c2..50b3f8bf5df 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype3.kt +++ b/idea/testData/quickfix/modifiers/removeSupertype3.kt @@ -1,4 +1,4 @@ -// "Remove supertype 'C2'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1(), C2 {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype3.kt.after b/idea/testData/quickfix/modifiers/removeSupertype3.kt.after index 71fdbd3e13c..9cbe42b8e17 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype3.kt.after +++ b/idea/testData/quickfix/modifiers/removeSupertype3.kt.after @@ -1,4 +1,4 @@ -// "Remove supertype 'C2'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1() {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype4.kt b/idea/testData/quickfix/modifiers/removeSupertype4.kt index a05843d7dc0..fc82fe021df 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype4.kt +++ b/idea/testData/quickfix/modifiers/removeSupertype4.kt @@ -1,4 +1,4 @@ -// "Remove supertype 'C2()'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1(), /* Hello, world! */ C2() {} diff --git a/idea/testData/quickfix/modifiers/removeSupertype4.kt.after b/idea/testData/quickfix/modifiers/removeSupertype4.kt.after index b53974f5811..5f8c8de880e 100644 --- a/idea/testData/quickfix/modifiers/removeSupertype4.kt.after +++ b/idea/testData/quickfix/modifiers/removeSupertype4.kt.after @@ -1,4 +1,4 @@ -// "Remove supertype 'C2()'" "true" +// "Remove supertype" "true" open class C1 {} open class C2 {} class C3: C1() /* Hello, world! */ {}