diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 92cfca9d224..7181f84e036 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -418,6 +418,7 @@ class QuickFixRegistrar : QuickFixContributor { UNRESOLVED_REFERENCE.registerFactory(CreateTypeParameterByRefActionFactory) FINAL_UPPER_BOUND.registerFactory(InlineTypeParameterFix) + FINAL_UPPER_BOUND.registerFactory(RemoveFinalUpperBoundFix) TYPE_PARAMETER_AS_REIFIED.registerFactory(AddReifiedToTypeParameterOfFunctionFix) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFinalUpperBoundFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFinalUpperBoundFix.kt new file mode 100644 index 00000000000..83e5c0f4cac --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFinalUpperBoundFix.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2016 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.kotlin.idea.quickfix + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtTypeParameter +import org.jetbrains.kotlin.psi.KtTypeReference +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType + +class RemoveFinalUpperBoundFix(val typeReference: KtTypeReference) : KotlinQuickFixAction(typeReference) { + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + typeReference.getStrictParentOfType()?.extendsBound = null + } + + override fun getText() = "Remove final upper bound" + + override fun getFamilyName() = text + + companion object Factory : KotlinSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic) = RemoveFinalUpperBoundFix(Errors.FINAL_UPPER_BOUND.cast(diagnostic).psiElement) + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/removeFinalUpperBound/basic.kt b/idea/testData/quickfix/removeFinalUpperBound/basic.kt new file mode 100644 index 00000000000..03366b7d6e9 --- /dev/null +++ b/idea/testData/quickfix/removeFinalUpperBound/basic.kt @@ -0,0 +1,3 @@ +// "Remove final upper bound" "true" + +data class DC>(val x: T, val y: String) \ No newline at end of file diff --git a/idea/testData/quickfix/removeFinalUpperBound/basic.kt.after b/idea/testData/quickfix/removeFinalUpperBound/basic.kt.after new file mode 100644 index 00000000000..ea83bcfdacc --- /dev/null +++ b/idea/testData/quickfix/removeFinalUpperBound/basic.kt.after @@ -0,0 +1,3 @@ +// "Remove final upper bound" "true" + +data class DC(val x: T, val y: String) \ No newline at end of file diff --git a/idea/testData/quickfix/removeFinalUpperBound/function.kt b/idea/testData/quickfix/removeFinalUpperBound/function.kt new file mode 100644 index 00000000000..eec8715e973 --- /dev/null +++ b/idea/testData/quickfix/removeFinalUpperBound/function.kt @@ -0,0 +1,7 @@ +// "Remove final upper bound" "true" + +data class DC(val x: Int, val y: String) { + fun > foo(b: S) { + val a: S = b + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/removeFinalUpperBound/function.kt.after b/idea/testData/quickfix/removeFinalUpperBound/function.kt.after new file mode 100644 index 00000000000..16ca2752f61 --- /dev/null +++ b/idea/testData/quickfix/removeFinalUpperBound/function.kt.after @@ -0,0 +1,7 @@ +// "Remove final upper bound" "true" + +data class DC(val x: Int, val y: String) { + fun foo(b: S) { + val a: S = b + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 1ad93c32500..58aa7b9aa44 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -7100,6 +7100,27 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/removeFinalUpperBound") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveFinalUpperBound extends AbstractQuickFixTest { + public void testAllFilesPresentInRemoveFinalUpperBound() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/removeFinalUpperBound"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/removeFinalUpperBound/basic.kt"); + doTest(fileName); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/removeFinalUpperBound/function.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/quickfix/removeToStringInStringTemplate") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)