Merge pull request #948 from shiraji/quick_fix_for_final_upper_bound_2
KT-13674 Add quickfix to remove the final upper bound
This commit is contained in:
@@ -418,6 +418,7 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
UNRESOLVED_REFERENCE.registerFactory(CreateTypeParameterByRefActionFactory)
|
UNRESOLVED_REFERENCE.registerFactory(CreateTypeParameterByRefActionFactory)
|
||||||
|
|
||||||
FINAL_UPPER_BOUND.registerFactory(InlineTypeParameterFix)
|
FINAL_UPPER_BOUND.registerFactory(InlineTypeParameterFix)
|
||||||
|
FINAL_UPPER_BOUND.registerFactory(RemoveFinalUpperBoundFix)
|
||||||
|
|
||||||
TYPE_PARAMETER_AS_REIFIED.registerFactory(AddReifiedToTypeParameterOfFunctionFix)
|
TYPE_PARAMETER_AS_REIFIED.registerFactory(AddReifiedToTypeParameterOfFunctionFix)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<KtTypeReference>(typeReference) {
|
||||||
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
|
typeReference.getStrictParentOfType<KtTypeParameter>()?.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove final upper bound" "true"
|
||||||
|
|
||||||
|
data class DC<T : Int<caret>>(val x: T, val y: String)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// "Remove final upper bound" "true"
|
||||||
|
|
||||||
|
data class DC<T>(val x: T, val y: String)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Remove final upper bound" "true"
|
||||||
|
|
||||||
|
data class DC(val x: Int, val y: String) {
|
||||||
|
fun <S : Int<caret>> foo(b: S) {
|
||||||
|
val a: S = b
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Remove final upper bound" "true"
|
||||||
|
|
||||||
|
data class DC(val x: Int, val y: String) {
|
||||||
|
fun <S> foo(b: S) {
|
||||||
|
val a: S = b
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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")
|
@TestMetadata("idea/testData/quickfix/removeToStringInStringTemplate")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user