Implement quickfix for MANY_CLASSES_IN_SUPERTYPE_LIST

This commit is contained in:
Peter Tseng
2013-02-20 01:13:35 -05:00
committed by Nikolay Krasko
parent 9000f6971c
commit 1025ab4397
12 changed files with 132 additions and 0 deletions
@@ -29,6 +29,8 @@ remove.right.part.of.binary.expression=Remove right part of a binary expression
remove.cast=Remove cast
remove.elvis.operator=Remove elvis operator
remove.redundant.nullable=Remove redundant '?'
remove.supertype=Remove supertype ''{0}''
remove.supertype.family=Remove supertype
remove.supertype.nullable=Remove '?'
remove.type.arguments=Remove type arguments
remove.useless.nullable=Remove useless '?'
@@ -219,5 +219,7 @@ public class QuickFixes {
factories.put(COMPARE_TO_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForCompareToTypeMismatch());
factories.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, MapPlatformClassToKotlinFix.createFactory());
factories.put(MANY_CLASSES_IN_SUPERTYPE_LIST, RemoveSupertypeFix.createFactory());
}
}
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2013 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.jet.plugin.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.PsiFile;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.JetBundle;
public class RemoveSupertypeFix extends JetIntentionAction<JetDelegationSpecifier> {
private final JetDelegationSpecifier superClass;
public RemoveSupertypeFix(@NotNull JetDelegationSpecifier superClass) {
super(superClass);
this.superClass = superClass;
}
@NotNull
@Override
public String getText() {
return JetBundle.message("remove.supertype", superClass.getText());
}
@NotNull
@Override
public String getFamilyName() {
return JetBundle.message("remove.supertype.family");
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile 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() == JetTokens.COMMA) {
prev.getPsi().delete();
}
superClass.delete();
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetDelegationSpecifier> createAction(Diagnostic diagnostic) {
JetDelegationSpecifier superClass = QuickFixUtil.getParentElementOfType(diagnostic, JetDelegationSpecifier.class);
if (superClass == null) return null;
return new RemoveSupertypeFix(superClass);
}
};
}
}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2()'" "true"
open class C1 {}
open class C2 {}
class C3: C1() {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2()'" "true"
open class C1 {}
open class C2 {}
class C3: C1() {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2'" "true"
open class C1 {}
open class C2 {}
class C3: C1() {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2()'" "true"
open class C1 {}
open class C2 {}
class C3: C1() /* Hello, world! */ {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2()'" "true"
open class C1 {}
open class C2 {}
class C3: C1(), C2<caret>() {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2()'" "true"
open class C1 {}
open class C2 {}
class C3: C1(),C2<caret>() {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2'" "true"
open class C1 {}
open class C2 {}
class C3: C1(), C2<caret> {}
@@ -0,0 +1,4 @@
// "Remove supertype 'C2()'" "true"
open class C1 {}
open class C2 {}
class C3: C1(), /* Hello, world! */ C2<caret>() {}
@@ -534,6 +534,26 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/modifiers/beforeRemoveRedundantModifier3.kt");
}
@TestMetadata("beforeRemoveSupertype1.kt")
public void testRemoveSupertype1() throws Exception {
doTest("idea/testData/quickfix/modifiers/beforeRemoveSupertype1.kt");
}
@TestMetadata("beforeRemoveSupertype2.kt")
public void testRemoveSupertype2() throws Exception {
doTest("idea/testData/quickfix/modifiers/beforeRemoveSupertype2.kt");
}
@TestMetadata("beforeRemoveSupertype3.kt")
public void testRemoveSupertype3() throws Exception {
doTest("idea/testData/quickfix/modifiers/beforeRemoveSupertype3.kt");
}
@TestMetadata("beforeRemoveSupertype4.kt")
public void testRemoveSupertype4() throws Exception {
doTest("idea/testData/quickfix/modifiers/beforeRemoveSupertype4.kt");
}
@TestMetadata("beforeVisibilityModifer1.kt")
public void testVisibilityModifer1() throws Exception {
doTest("idea/testData/quickfix/modifiers/beforeVisibilityModifer1.kt");