diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 356eb8b4300..2169d487803 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -1106,6 +1106,7 @@ fun main(args: Array) { testClass { val pattern = "^([\\w\\-_]+)\\.kt$" model("quickfix/modifiers", pattern = pattern, filenameStartsLowerCase = true, recursive = false) + model("quickfix/override/typeMismatchOnOverride", pattern = pattern, filenameStartsLowerCase = true, recursive = false) } } diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/KtQuickFixesList.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/KtQuickFixesList.kt index d216b510e4e..51d40922c8d 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/KtQuickFixesList.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/KtQuickFixesList.kt @@ -18,8 +18,16 @@ annotation class ForKtQuickFixesListBuilder() class KtQuickFixesListBuilder private constructor() { val quickFixes = mutableMapOf>, MutableList>() - inline fun > register(quickFixFactory: QuickFixFactory) { - quickFixes.getOrPut(D::class) { mutableListOf() }.add(quickFixFactory) + inline fun > register( + quickFixFactory: QuickFixesPsiBasedFactory + ) { + quickFixes.getOrPut(DIAGNOSTIC::class) { mutableListOf() }.add(quickFixFactory) + } + + inline fun > register( + quickFixFactory: QuickFixesHLApiBasedFactory + ) { + quickFixes.getOrPut(DIAGNOSTIC::class) { mutableListOf() }.add(quickFixFactory) } @OptIn(ForKtQuickFixesListBuilder::class) diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/MainKtQuickFixRegistrar.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/MainKtQuickFixRegistrar.kt index 9c65bf68da5..615c2dc9126 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/MainKtQuickFixRegistrar.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/MainKtQuickFixRegistrar.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.lexer.KtToken import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtCallableDeclaration import org.jetbrains.kotlin.psi.KtModifierListOwner +import org.jetbrains.kotlin.psi.KtNamedDeclaration class MainKtQuickFixRegistrar : KtQuickFixRegistrar() { private val modifiers = KtQuickFixesListBuilder.register { @@ -28,7 +29,15 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() { ) } + private val overrides = KtQuickFixesListBuilder.register { + register(ChangeTypeQuickFix.changeFunctionReturnTypeOnOverride) + register(ChangeTypeQuickFix.changePropertyReturnTypeOnOverride) + register(ChangeTypeQuickFix.changeVariableReturnTypeOnOverride) + + } + override val list: KtQuickFixesList = KtQuickFixesList.createCombined( modifiers, + overrides, ) } \ No newline at end of file diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/QuickFixesHLApiBasedFactory.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/QuickFixesHLApiBasedFactory.kt new file mode 100644 index 00000000000..51f462df737 --- /dev/null +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/QuickFixesHLApiBasedFactory.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.quickfix + +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession +import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi + +abstract class QuickFixesHLApiBasedFactory> : QuickFixFactory { + final override fun asKotlinIntentionActionsFactory(): KotlinIntentionActionsFactory { + error("Should not be called. This function is not considered to bue used in FE10 plugin, from FIR plugin consider using createQuickFix") + } + + abstract fun KtAnalysisSession.createQuickFix(diagnostic: DIAGNOSTIC): List +} + + +inline fun > quickFixesHLApiBasedFactory( + crossinline createQuickFix: KtAnalysisSession.(DIAGNOSTIC) -> List +) = object : QuickFixesHLApiBasedFactory() { + override fun KtAnalysisSession.createQuickFix(diagnostic: DIAGNOSTIC): List = + createQuickFix(diagnostic) +} \ No newline at end of file diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt new file mode 100644 index 00000000000..ecb512cd7c9 --- /dev/null +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt @@ -0,0 +1,149 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.quickfix.fixes + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.util.parentOfType +import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession +import org.jetbrains.kotlin.idea.frontend.api.components.KtTypeRendererOptions +import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi +import org.jetbrains.kotlin.idea.frontend.api.fir.diagnostics.KtFirDiagnostic +import org.jetbrains.kotlin.idea.frontend.api.symbols.* +import org.jetbrains.kotlin.idea.frontend.api.types.KtType +import org.jetbrains.kotlin.idea.frontend.api.types.isUnit +import org.jetbrains.kotlin.idea.quickfix.ChangeCallableReturnTypeFix +import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction +import org.jetbrains.kotlin.idea.quickfix.quickFixesHLApiBasedFactory +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.types.checker.KotlinTypeChecker + + +class ChangeTypeQuickFix internal constructor( + declaration: KtCallableDeclaration, + private val typeInfo: TypeInfo, + private val updateBaseFunction: Boolean +) : KotlinQuickFixAction(declaration) { + override fun getText(): String { + val element = element ?: return "" + val functionPresentation = when { + updateBaseFunction -> { + val containerName = element.parentOfType()?.nameAsName?.takeUnless { it.isSpecial } + ChangeCallableReturnTypeFix.StringPresentation.baseFunctionOrConstructorParameterPresentation(element, containerName) + } + else -> null + } + return ChangeCallableReturnTypeFix.StringPresentation.getTextForQuickFix( + element, + functionPresentation, + typeInfo.isUnit, + typeInfo.short + ) + } + + override fun getFamilyName(): String = ChangeCallableReturnTypeFix.StringPresentation.familyName() + + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + val element = element ?: return + if (!element.isProcedure()) { + val newTypeRef = KtPsiFactory(project).createType(typeInfo.short) + element.typeReference = newTypeRef + } else { + element.typeReference = null + } + } + + private fun KtCallableDeclaration.isProcedure() = + typeInfo.isUnit && this is KtFunction && hasBlockBody() + + internal data class TypeInfo( + val qualified: String, + val short: String, + val isUnit: Boolean, + ) + + companion object { + val changeFunctionReturnTypeOnOverride = + ChangeTypeQuickFixFactory.changeReturnTypeOnOverride { + it.function as? KtFunctionSymbol + } + + val changePropertyReturnTypeOnOverride = + ChangeTypeQuickFixFactory.changeReturnTypeOnOverride { + it.property as? KtPropertySymbol + } + + val changeVariableReturnTypeOnOverride = + ChangeTypeQuickFixFactory.changeReturnTypeOnOverride { + it.variable as? KtPropertySymbol + } + } +} + +private object ChangeTypeQuickFixFactory { + inline fun > changeReturnTypeOnOverride( + crossinline getCallableSymbol: (DIAGNOSTIC) -> KtCallableSymbol? + ) = quickFixesHLApiBasedFactory { diagnostic -> + val declaration = diagnostic.psi as? KtCallableDeclaration ?: return@quickFixesHLApiBasedFactory emptyList() + val callable = getCallableSymbol(diagnostic) ?: return@quickFixesHLApiBasedFactory emptyList() + listOfNotNull( + createChangeCurrentDeclarationQuickFix(callable, declaration), + createChangeOverriddenFunctionQuickFix(callable), + ) + } + + fun KtAnalysisSession.createChangeCurrentDeclarationQuickFix( + callable: KtCallableSymbol, + declaration: PSI + ): ChangeTypeQuickFix? { + val lowerSuperType = findLowerBoundOfOverriddenCallablesReturnTypes(callable) ?: return null + val changeToTypeInfo = createTypeInfo(lowerSuperType) + return ChangeTypeQuickFix(declaration, changeToTypeInfo, updateBaseFunction = false) + } + + fun KtAnalysisSession.createChangeOverriddenFunctionQuickFix( + callable: KtCallableSymbol + ): ChangeTypeQuickFix? { + val type = callable.annotatedType.type + val singleNonMatchingOverriddenFunction = findSingleNonMatchingOverriddenFunction(callable, type) ?: return null + val singleMatchingOverriddenFunctionPsi = singleNonMatchingOverriddenFunction.psiSafe() ?: return null + val changeToTypeInfo = createTypeInfo(type) + return ChangeTypeQuickFix(singleMatchingOverriddenFunctionPsi, changeToTypeInfo, updateBaseFunction = true) + } + + private fun KtAnalysisSession.findSingleNonMatchingOverriddenFunction( + callable: KtCallableSymbol, + type: KtType + ): KtCallableSymbol? { + val overriddenSymbols = callable.getOverriddenSymbols() + return overriddenSymbols + .singleOrNull { overridden -> + overridden.origin != KtSymbolOrigin.INTERSECTION_OVERRIDE && !type.isSubTypeOf(overridden.annotatedType.type) + } + } + + fun KtAnalysisSession.createTypeInfo(ktType: KtType) = ChangeTypeQuickFix.TypeInfo( + qualified = ktType.render(), + short = ktType.render(KtTypeRendererOptions.SHORT_NAMES), + isUnit = ktType.isUnit + ) + + private fun KtAnalysisSession.findLowerBoundOfOverriddenCallablesReturnTypes(symbol: KtCallableSymbol): KtType? { + var lowestType: KtType? = null + for (overridden in symbol.getOverriddenSymbols()) { + val overriddenType = overridden.annotatedType.type + when { + lowestType == null || overriddenType isSubTypeOf lowestType -> { + lowestType = overriddenType + } + lowestType isNotSubTypeOf overriddenType -> { + return null + } + } + } + return lowestType + } +} diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/quickfix/HighLevelQuickFixTestGenerated.java b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/quickfix/HighLevelQuickFixTestGenerated.java index 183e35c986a..7a8e975175d 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/quickfix/HighLevelQuickFixTestGenerated.java +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/quickfix/HighLevelQuickFixTestGenerated.java @@ -17,320 +17,436 @@ import java.util.regex.Pattern; /** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@TestMetadata("idea/testData/quickfix/modifiers") -@TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + @TestMetadata("idea/testData/quickfix/modifiers") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Modifiers extends AbstractHighLevelQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("abstractModifierInEnum.kt") + public void testAbstractModifierInEnum() throws Exception { + runTest("idea/testData/quickfix/modifiers/abstractModifierInEnum.kt"); + } + + @TestMetadata("addLateinit.kt") + public void testAddLateinit() throws Exception { + runTest("idea/testData/quickfix/modifiers/addLateinit.kt"); + } + + public void testAllFilesPresentInModifiers() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/modifiers"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, false); + } + + @TestMetadata("cannotMakeClassAnnotation.kt") + public void testCannotMakeClassAnnotation() throws Exception { + runTest("idea/testData/quickfix/modifiers/cannotMakeClassAnnotation.kt"); + } + + @TestMetadata("finalTrait.kt") + public void testFinalTrait() throws Exception { + runTest("idea/testData/quickfix/modifiers/finalTrait.kt"); + } + + @TestMetadata("illegalEnumAnnotation1.kt") + public void testIllegalEnumAnnotation1() throws Exception { + runTest("idea/testData/quickfix/modifiers/illegalEnumAnnotation1.kt"); + } + + @TestMetadata("illegalEnumAnnotation2.kt") + public void testIllegalEnumAnnotation2() throws Exception { + runTest("idea/testData/quickfix/modifiers/illegalEnumAnnotation2.kt"); + } + + @TestMetadata("infixModifier.kt") + public void testInfixModifier() throws Exception { + runTest("idea/testData/quickfix/modifiers/infixModifier.kt"); + } + + @TestMetadata("kt10409.kt") + public void testKt10409() throws Exception { + runTest("idea/testData/quickfix/modifiers/kt10409.kt"); + } + + @TestMetadata("nestedAbstractClass.kt") + public void testNestedAbstractClass() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedAbstractClass.kt"); + } + + @TestMetadata("nestedAnnotationClass.kt") + public void testNestedAnnotationClass() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedAnnotationClass.kt"); + } + + @TestMetadata("nestedClassNotAllowed.kt") + public void testNestedClassNotAllowed() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedClassNotAllowed.kt"); + } + + @TestMetadata("nestedDataClass.kt") + public void testNestedDataClass() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedDataClass.kt"); + } + + @TestMetadata("nestedEnumClass.kt") + public void testNestedEnumClass() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedEnumClass.kt"); + } + + @TestMetadata("nestedInterface.kt") + public void testNestedInterface() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedInterface.kt"); + } + + @TestMetadata("nestedObject.kt") + public void testNestedObject() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedObject.kt"); + } + + @TestMetadata("nestedSealedClass.kt") + public void testNestedSealedClass() throws Exception { + runTest("idea/testData/quickfix/modifiers/nestedSealedClass.kt"); + } + + @TestMetadata("noAbstractForAnonymousObject.kt") + public void testNoAbstractForAnonymousObject() throws Exception { + runTest("idea/testData/quickfix/modifiers/noAbstractForAnonymousObject.kt"); + } + + @TestMetadata("noAbstractForObject.kt") + public void testNoAbstractForObject() throws Exception { + runTest("idea/testData/quickfix/modifiers/noAbstractForObject.kt"); + } + + @TestMetadata("noLateinitOnNullable.kt") + public void testNoLateinitOnNullable() throws Exception { + runTest("idea/testData/quickfix/modifiers/noLateinitOnNullable.kt"); + } + + @TestMetadata("noLateinitOnPrimitive.kt") + public void testNoLateinitOnPrimitive() throws Exception { + runTest("idea/testData/quickfix/modifiers/noLateinitOnPrimitive.kt"); + } + + @TestMetadata("notAnAnnotationClass.kt") + public void testNotAnAnnotationClass() throws Exception { + runTest("idea/testData/quickfix/modifiers/notAnAnnotationClass.kt"); + } + + @TestMetadata("openCompanionObject.kt") + public void testOpenCompanionObject() throws Exception { + runTest("idea/testData/quickfix/modifiers/openCompanionObject.kt"); + } + + @TestMetadata("openCompanionObject2.kt") + public void testOpenCompanionObject2() throws Exception { + runTest("idea/testData/quickfix/modifiers/openCompanionObject2.kt"); + } + + @TestMetadata("openMemberInFinalClass1.kt") + public void testOpenMemberInFinalClass1() throws Exception { + runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass1.kt"); + } + + @TestMetadata("openMemberInFinalClass2.kt") + public void testOpenMemberInFinalClass2() throws Exception { + runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass2.kt"); + } + + @TestMetadata("openMemberInFinalClass3.kt") + public void testOpenMemberInFinalClass3() throws Exception { + runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass3.kt"); + } + + @TestMetadata("openMemberInFinalClass4.kt") + public void testOpenMemberInFinalClass4() throws Exception { + runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass4.kt"); + } + + @TestMetadata("openModifierInEnum.kt") + public void testOpenModifierInEnum() throws Exception { + runTest("idea/testData/quickfix/modifiers/openModifierInEnum.kt"); + } + + @TestMetadata("openObject.kt") + public void testOpenObject() throws Exception { + runTest("idea/testData/quickfix/modifiers/openObject.kt"); + } + + @TestMetadata("openVarWithPrivateSetter.kt") + public void testOpenVarWithPrivateSetter() throws Exception { + runTest("idea/testData/quickfix/modifiers/openVarWithPrivateSetter.kt"); + } + + @TestMetadata("operatorModifier.kt") + public void testOperatorModifier() throws Exception { + runTest("idea/testData/quickfix/modifiers/operatorModifier.kt"); + } + + @TestMetadata("operatorModifierCollection.kt") + public void testOperatorModifierCollection() throws Exception { + runTest("idea/testData/quickfix/modifiers/operatorModifierCollection.kt"); + } + + @TestMetadata("operatorModifierComponent.kt") + public void testOperatorModifierComponent() throws Exception { + runTest("idea/testData/quickfix/modifiers/operatorModifierComponent.kt"); + } + + @TestMetadata("operatorModifierGet.kt") + public void testOperatorModifierGet() throws Exception { + runTest("idea/testData/quickfix/modifiers/operatorModifierGet.kt"); + } + + @TestMetadata("operatorModifierInherited.kt") + public void testOperatorModifierInherited() throws Exception { + runTest("idea/testData/quickfix/modifiers/operatorModifierInherited.kt"); + } + + @TestMetadata("overrideWithPrivateSetter.kt") + public void testOverrideWithPrivateSetter() throws Exception { + runTest("idea/testData/quickfix/modifiers/overrideWithPrivateSetter.kt"); + } + + @TestMetadata("packageMemberCannotBeProtected.kt") + public void testPackageMemberCannotBeProtected() throws Exception { + runTest("idea/testData/quickfix/modifiers/packageMemberCannotBeProtected.kt"); + } + + @TestMetadata("redundantOpenInInterface.kt") + public void testRedundantOpenInInterface() throws Exception { + runTest("idea/testData/quickfix/modifiers/redundantOpenInInterface.kt"); + } + + @TestMetadata("removeAbstractModifier.kt") + public void testRemoveAbstractModifier() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeAbstractModifier.kt"); + } + + @TestMetadata("removeConst.kt") + public void testRemoveConst() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeConst.kt"); + } + + @TestMetadata("removeIncompatibleModifier.kt") + public void testRemoveIncompatibleModifier() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeIncompatibleModifier.kt"); + } + + @TestMetadata("removeInnerForClassInTrait.kt") + public void testRemoveInnerForClassInTrait() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeInnerForClassInTrait.kt"); + } + + @TestMetadata("removeModifierFromForbiddenOperatorMod.kt") + public void testRemoveModifierFromForbiddenOperatorMod() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeModifierFromForbiddenOperatorMod.kt"); + } + + @TestMetadata("removeModifierFromOperatorMod.kt") + public void testRemoveModifierFromOperatorMod() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeModifierFromOperatorMod.kt"); + } + + @TestMetadata("removeModifierFromOperatorModAssign.kt") + public void testRemoveModifierFromOperatorModAssign() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeModifierFromOperatorModAssign.kt"); + } + + @TestMetadata("removeProtectedModifier.kt") + public void testRemoveProtectedModifier() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeProtectedModifier.kt"); + } + + @TestMetadata("removeRedundantModifier1.kt") + public void testRemoveRedundantModifier1() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeRedundantModifier1.kt"); + } + + @TestMetadata("removeRedundantModifier2.kt") + public void testRemoveRedundantModifier2() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeRedundantModifier2.kt"); + } + + @TestMetadata("removeRedundantModifier3.kt") + public void testRemoveRedundantModifier3() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeRedundantModifier3.kt"); + } + + @TestMetadata("removeSupertype1.kt") + public void testRemoveSupertype1() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeSupertype1.kt"); + } + + @TestMetadata("removeSupertype2.kt") + public void testRemoveSupertype2() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeSupertype2.kt"); + } + + @TestMetadata("removeSupertype3.kt") + public void testRemoveSupertype3() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeSupertype3.kt"); + } + + @TestMetadata("removeSupertype4.kt") + public void testRemoveSupertype4() throws Exception { + runTest("idea/testData/quickfix/modifiers/removeSupertype4.kt"); + } + + @TestMetadata("visibilityModifer1.kt") + public void testVisibilityModifer1() throws Exception { + runTest("idea/testData/quickfix/modifiers/visibilityModifer1.kt"); + } + + @TestMetadata("visibilityModifer2.kt") + public void testVisibilityModifer2() throws Exception { + runTest("idea/testData/quickfix/modifiers/visibilityModifer2.kt"); + } + + @TestMetadata("visibilityModiferOverrideJavaRuntime.kt") + public void testVisibilityModiferOverrideJavaRuntime() throws Exception { + runTest("idea/testData/quickfix/modifiers/visibilityModiferOverrideJavaRuntime.kt"); + } + + @TestMetadata("visibilityModiferParameter.kt") + public void testVisibilityModiferParameter() throws Exception { + runTest("idea/testData/quickfix/modifiers/visibilityModiferParameter.kt"); + } + + @TestMetadata("withAnnotationAndBlockComment.kt") + public void testWithAnnotationAndBlockComment() throws Exception { + runTest("idea/testData/quickfix/modifiers/withAnnotationAndBlockComment.kt"); + } + + @TestMetadata("withAnnotationAndEolComment.kt") + public void testWithAnnotationAndEolComment() throws Exception { + runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment.kt"); + } + + @TestMetadata("withAnnotationAndEolComment2.kt") + public void testWithAnnotationAndEolComment2() throws Exception { + runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment2.kt"); + } + + @TestMetadata("withAnnotationAndEolComment3.kt") + public void testWithAnnotationAndEolComment3() throws Exception { + runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment3.kt"); + } } - @TestMetadata("abstractModifierInEnum.kt") - public void testAbstractModifierInEnum() throws Exception { - runTest("idea/testData/quickfix/modifiers/abstractModifierInEnum.kt"); - } + @TestMetadata("idea/testData/quickfix/override/typeMismatchOnOverride") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeMismatchOnOverride extends AbstractHighLevelQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } - @TestMetadata("addLateinit.kt") - public void testAddLateinit() throws Exception { - runTest("idea/testData/quickfix/modifiers/addLateinit.kt"); - } + public void testAllFilesPresentInTypeMismatchOnOverride() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/override/typeMismatchOnOverride"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, false); + } - public void testAllFilesPresentInModifiers() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/modifiers"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, false); - } + @TestMetadata("cantChangeMultipleOverriddenPropertiesTypes.kt") + public void testCantChangeMultipleOverriddenPropertiesTypes() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeMultipleOverriddenPropertiesTypes.kt"); + } - @TestMetadata("cannotMakeClassAnnotation.kt") - public void testCannotMakeClassAnnotation() throws Exception { - runTest("idea/testData/quickfix/modifiers/cannotMakeClassAnnotation.kt"); - } + @TestMetadata("cantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt") + public void testCantChangeOverriddenPropertyTypeToMatchOverridingProperty() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt"); + } - @TestMetadata("finalTrait.kt") - public void testFinalTrait() throws Exception { - runTest("idea/testData/quickfix/modifiers/finalTrait.kt"); - } + @TestMetadata("cantChangePropertyTypeToMatchOverridenProperties.kt") + public void testCantChangePropertyTypeToMatchOverridenProperties() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/cantChangePropertyTypeToMatchOverridenProperties.kt"); + } - @TestMetadata("illegalEnumAnnotation1.kt") - public void testIllegalEnumAnnotation1() throws Exception { - runTest("idea/testData/quickfix/modifiers/illegalEnumAnnotation1.kt"); - } + @TestMetadata("cantChangeReturnTypeOfOverriddenFunction.kt") + public void testCantChangeReturnTypeOfOverriddenFunction() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeReturnTypeOfOverriddenFunction.kt"); + } - @TestMetadata("illegalEnumAnnotation2.kt") - public void testIllegalEnumAnnotation2() throws Exception { - runTest("idea/testData/quickfix/modifiers/illegalEnumAnnotation2.kt"); - } + @TestMetadata("changeOverriddenPropertyType1.kt") + public void testChangeOverriddenPropertyType1() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/changeOverriddenPropertyType1.kt"); + } - @TestMetadata("infixModifier.kt") - public void testInfixModifier() throws Exception { - runTest("idea/testData/quickfix/modifiers/infixModifier.kt"); - } + @TestMetadata("changeOverriddenPropertyType2.kt") + public void testChangeOverriddenPropertyType2() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/changeOverriddenPropertyType2.kt"); + } - @TestMetadata("kt10409.kt") - public void testKt10409() throws Exception { - runTest("idea/testData/quickfix/modifiers/kt10409.kt"); - } + @TestMetadata("changeOverriddenPropertyTypeFromCtorParameter.kt") + public void testChangeOverriddenPropertyTypeFromCtorParameter() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/changeOverriddenPropertyTypeFromCtorParameter.kt"); + } - @TestMetadata("nestedAbstractClass.kt") - public void testNestedAbstractClass() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedAbstractClass.kt"); - } + @TestMetadata("changeOverridingCtorParameterType.kt") + public void testChangeOverridingCtorParameterType() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/changeOverridingCtorParameterType.kt"); + } - @TestMetadata("nestedAnnotationClass.kt") - public void testNestedAnnotationClass() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedAnnotationClass.kt"); - } + @TestMetadata("changeOverridingPropertyTypeToFunctionType.kt") + public void testChangeOverridingPropertyTypeToFunctionType() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/changeOverridingPropertyTypeToFunctionType.kt"); + } - @TestMetadata("nestedClassNotAllowed.kt") - public void testNestedClassNotAllowed() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedClassNotAllowed.kt"); - } + @TestMetadata("changeReturnTypeOfOverriddenFunction.kt") + public void testChangeReturnTypeOfOverriddenFunction() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/changeReturnTypeOfOverriddenFunction.kt"); + } - @TestMetadata("nestedDataClass.kt") - public void testNestedDataClass() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedDataClass.kt"); - } + @TestMetadata("namedFunctionReturnOverrideInsideVariableInitializer.kt") + public void testNamedFunctionReturnOverrideInsideVariableInitializer() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/namedFunctionReturnOverrideInsideVariableInitializer.kt"); + } - @TestMetadata("nestedEnumClass.kt") - public void testNestedEnumClass() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedEnumClass.kt"); - } + @TestMetadata("objectInsideBody.kt") + public void testObjectInsideBody() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/objectInsideBody.kt"); + } - @TestMetadata("nestedInterface.kt") - public void testNestedInterface() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedInterface.kt"); - } + @TestMetadata("propertyReturnTypeMismatchOnOverride.kt") + public void testPropertyReturnTypeMismatchOnOverride() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/propertyReturnTypeMismatchOnOverride.kt"); + } - @TestMetadata("nestedObject.kt") - public void testNestedObject() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedObject.kt"); - } + @TestMetadata("propertyTypeMismatchOnOverrideIntLong.kt") + public void testPropertyTypeMismatchOnOverrideIntLong() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/propertyTypeMismatchOnOverrideIntLong.kt"); + } - @TestMetadata("nestedSealedClass.kt") - public void testNestedSealedClass() throws Exception { - runTest("idea/testData/quickfix/modifiers/nestedSealedClass.kt"); - } + @TestMetadata("propertyTypeMismatchOnOverrideIntUnit.kt") + public void testPropertyTypeMismatchOnOverrideIntUnit() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/propertyTypeMismatchOnOverrideIntUnit.kt"); + } - @TestMetadata("noAbstractForAnonymousObject.kt") - public void testNoAbstractForAnonymousObject() throws Exception { - runTest("idea/testData/quickfix/modifiers/noAbstractForAnonymousObject.kt"); - } + @TestMetadata("returnTypeMismatchOnMultipleOverride.kt") + public void testReturnTypeMismatchOnMultipleOverride() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/returnTypeMismatchOnMultipleOverride.kt"); + } - @TestMetadata("noAbstractForObject.kt") - public void testNoAbstractForObject() throws Exception { - runTest("idea/testData/quickfix/modifiers/noAbstractForObject.kt"); - } + @TestMetadata("returnTypeMismatchOnMultipleOverrideAmbiguity.kt") + public void testReturnTypeMismatchOnMultipleOverrideAmbiguity() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/returnTypeMismatchOnMultipleOverrideAmbiguity.kt"); + } - @TestMetadata("noLateinitOnNullable.kt") - public void testNoLateinitOnNullable() throws Exception { - runTest("idea/testData/quickfix/modifiers/noLateinitOnNullable.kt"); - } + @TestMetadata("returnTypeMismatchOnOverrideIntLong.kt") + public void testReturnTypeMismatchOnOverrideIntLong() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/returnTypeMismatchOnOverrideIntLong.kt"); + } - @TestMetadata("noLateinitOnPrimitive.kt") - public void testNoLateinitOnPrimitive() throws Exception { - runTest("idea/testData/quickfix/modifiers/noLateinitOnPrimitive.kt"); - } + @TestMetadata("returnTypeMismatchOnOverrideIntUnit.kt") + public void testReturnTypeMismatchOnOverrideIntUnit() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/returnTypeMismatchOnOverrideIntUnit.kt"); + } - @TestMetadata("notAnAnnotationClass.kt") - public void testNotAnAnnotationClass() throws Exception { - runTest("idea/testData/quickfix/modifiers/notAnAnnotationClass.kt"); - } - - @TestMetadata("openCompanionObject.kt") - public void testOpenCompanionObject() throws Exception { - runTest("idea/testData/quickfix/modifiers/openCompanionObject.kt"); - } - - @TestMetadata("openCompanionObject2.kt") - public void testOpenCompanionObject2() throws Exception { - runTest("idea/testData/quickfix/modifiers/openCompanionObject2.kt"); - } - - @TestMetadata("openMemberInFinalClass1.kt") - public void testOpenMemberInFinalClass1() throws Exception { - runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass1.kt"); - } - - @TestMetadata("openMemberInFinalClass2.kt") - public void testOpenMemberInFinalClass2() throws Exception { - runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass2.kt"); - } - - @TestMetadata("openMemberInFinalClass3.kt") - public void testOpenMemberInFinalClass3() throws Exception { - runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass3.kt"); - } - - @TestMetadata("openMemberInFinalClass4.kt") - public void testOpenMemberInFinalClass4() throws Exception { - runTest("idea/testData/quickfix/modifiers/openMemberInFinalClass4.kt"); - } - - @TestMetadata("openModifierInEnum.kt") - public void testOpenModifierInEnum() throws Exception { - runTest("idea/testData/quickfix/modifiers/openModifierInEnum.kt"); - } - - @TestMetadata("openObject.kt") - public void testOpenObject() throws Exception { - runTest("idea/testData/quickfix/modifiers/openObject.kt"); - } - - @TestMetadata("openVarWithPrivateSetter.kt") - public void testOpenVarWithPrivateSetter() throws Exception { - runTest("idea/testData/quickfix/modifiers/openVarWithPrivateSetter.kt"); - } - - @TestMetadata("operatorModifier.kt") - public void testOperatorModifier() throws Exception { - runTest("idea/testData/quickfix/modifiers/operatorModifier.kt"); - } - - @TestMetadata("operatorModifierCollection.kt") - public void testOperatorModifierCollection() throws Exception { - runTest("idea/testData/quickfix/modifiers/operatorModifierCollection.kt"); - } - - @TestMetadata("operatorModifierComponent.kt") - public void testOperatorModifierComponent() throws Exception { - runTest("idea/testData/quickfix/modifiers/operatorModifierComponent.kt"); - } - - @TestMetadata("operatorModifierGet.kt") - public void testOperatorModifierGet() throws Exception { - runTest("idea/testData/quickfix/modifiers/operatorModifierGet.kt"); - } - - @TestMetadata("operatorModifierInherited.kt") - public void testOperatorModifierInherited() throws Exception { - runTest("idea/testData/quickfix/modifiers/operatorModifierInherited.kt"); - } - - @TestMetadata("overrideWithPrivateSetter.kt") - public void testOverrideWithPrivateSetter() throws Exception { - runTest("idea/testData/quickfix/modifiers/overrideWithPrivateSetter.kt"); - } - - @TestMetadata("packageMemberCannotBeProtected.kt") - public void testPackageMemberCannotBeProtected() throws Exception { - runTest("idea/testData/quickfix/modifiers/packageMemberCannotBeProtected.kt"); - } - - @TestMetadata("redundantOpenInInterface.kt") - public void testRedundantOpenInInterface() throws Exception { - runTest("idea/testData/quickfix/modifiers/redundantOpenInInterface.kt"); - } - - @TestMetadata("removeAbstractModifier.kt") - public void testRemoveAbstractModifier() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeAbstractModifier.kt"); - } - - @TestMetadata("removeConst.kt") - public void testRemoveConst() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeConst.kt"); - } - - @TestMetadata("removeIncompatibleModifier.kt") - public void testRemoveIncompatibleModifier() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeIncompatibleModifier.kt"); - } - - @TestMetadata("removeInnerForClassInTrait.kt") - public void testRemoveInnerForClassInTrait() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeInnerForClassInTrait.kt"); - } - - @TestMetadata("removeModifierFromForbiddenOperatorMod.kt") - public void testRemoveModifierFromForbiddenOperatorMod() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeModifierFromForbiddenOperatorMod.kt"); - } - - @TestMetadata("removeModifierFromOperatorMod.kt") - public void testRemoveModifierFromOperatorMod() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeModifierFromOperatorMod.kt"); - } - - @TestMetadata("removeModifierFromOperatorModAssign.kt") - public void testRemoveModifierFromOperatorModAssign() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeModifierFromOperatorModAssign.kt"); - } - - @TestMetadata("removeProtectedModifier.kt") - public void testRemoveProtectedModifier() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeProtectedModifier.kt"); - } - - @TestMetadata("removeRedundantModifier1.kt") - public void testRemoveRedundantModifier1() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeRedundantModifier1.kt"); - } - - @TestMetadata("removeRedundantModifier2.kt") - public void testRemoveRedundantModifier2() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeRedundantModifier2.kt"); - } - - @TestMetadata("removeRedundantModifier3.kt") - public void testRemoveRedundantModifier3() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeRedundantModifier3.kt"); - } - - @TestMetadata("removeSupertype1.kt") - public void testRemoveSupertype1() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeSupertype1.kt"); - } - - @TestMetadata("removeSupertype2.kt") - public void testRemoveSupertype2() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeSupertype2.kt"); - } - - @TestMetadata("removeSupertype3.kt") - public void testRemoveSupertype3() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeSupertype3.kt"); - } - - @TestMetadata("removeSupertype4.kt") - public void testRemoveSupertype4() throws Exception { - runTest("idea/testData/quickfix/modifiers/removeSupertype4.kt"); - } - - @TestMetadata("visibilityModifer1.kt") - public void testVisibilityModifer1() throws Exception { - runTest("idea/testData/quickfix/modifiers/visibilityModifer1.kt"); - } - - @TestMetadata("visibilityModifer2.kt") - public void testVisibilityModifer2() throws Exception { - runTest("idea/testData/quickfix/modifiers/visibilityModifer2.kt"); - } - - @TestMetadata("visibilityModiferOverrideJavaRuntime.kt") - public void testVisibilityModiferOverrideJavaRuntime() throws Exception { - runTest("idea/testData/quickfix/modifiers/visibilityModiferOverrideJavaRuntime.kt"); - } - - @TestMetadata("visibilityModiferParameter.kt") - public void testVisibilityModiferParameter() throws Exception { - runTest("idea/testData/quickfix/modifiers/visibilityModiferParameter.kt"); - } - - @TestMetadata("withAnnotationAndBlockComment.kt") - public void testWithAnnotationAndBlockComment() throws Exception { - runTest("idea/testData/quickfix/modifiers/withAnnotationAndBlockComment.kt"); - } - - @TestMetadata("withAnnotationAndEolComment.kt") - public void testWithAnnotationAndEolComment() throws Exception { - runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment.kt"); - } - - @TestMetadata("withAnnotationAndEolComment2.kt") - public void testWithAnnotationAndEolComment2() throws Exception { - runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment2.kt"); - } - - @TestMetadata("withAnnotationAndEolComment3.kt") - public void testWithAnnotationAndEolComment3() throws Exception { - runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment3.kt"); + @TestMetadata("returnTypeMismatchOnOverrideUnitInt.kt") + public void testReturnTypeMismatchOnOverrideUnitInt() throws Exception { + runTest("idea/testData/quickfix/override/typeMismatchOnOverride/returnTypeMismatchOnOverrideUnitInt.kt"); + } } }