Introduce "Remove fun modifier" quick fix for FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS error

#KT-37539 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-03-17 20:30:41 +09:00
committed by Ilya Kirillov
parent bfd6eeda60
commit 3263e85bee
6 changed files with 50 additions and 0 deletions
@@ -642,5 +642,7 @@ class QuickFixRegistrar : QuickFixContributor {
MUST_BE_INITIALIZED.registerFactory(ChangeVariableMutabilityFix.MUST_BE_INITIALIZED_FACTORY)
TOO_MANY_ARGUMENTS.registerFactory(RemoveArgumentFix)
FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS.registerFactory(RemoveModifierFix.createRemoveFunFromInterfaceFactory())
}
}
@@ -120,5 +120,18 @@ class RemoveModifierFix(
}
}
}
fun createRemoveFunFromInterfaceFactory(): KotlinSingleIntentionActionFactory {
return object : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): RemoveModifierFix? {
val keyword = diagnostic.psiElement
val modifierList = keyword.parent as? KtDeclarationModifierList ?: return null
val funInterface = (modifierList.parent as? KtClass)?.takeIf {
it.isInterface() && it.hasModifier(KtTokens.FUN_KEYWORD)
} ?: return null
return RemoveModifierFix(funInterface, KtTokens.FUN_KEYWORD, isRedundant = false)
}
}
}
}
}
+2
View File
@@ -0,0 +1,2 @@
// "Remove 'fun' modifier" "true"
<caret>fun interface WrongFunFace
+2
View File
@@ -0,0 +1,2 @@
// "Remove 'fun' modifier" "true"
interface WrongFunFace
@@ -3619,6 +3619,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
}
}
@TestMetadata("idea/testData/quickfix/redundantFun")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class RedundantFun extends AbstractQuickFixMultiFileTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTestWithExtraFile, this, testDataFilePath);
}
public void testAllFilesPresentInRedundantFun() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/redundantFun"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), null, true);
}
}
@TestMetadata("idea/testData/quickfix/redundantIf")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -10199,6 +10199,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/redundantFun")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class RedundantFun extends AbstractQuickFixTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInRedundantFun() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/redundantFun"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("idea/testData/quickfix/redundantFun/simple.kt");
}
}
@TestMetadata("idea/testData/quickfix/redundantIf")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)