Extract Interface/Pull Up: Drop 'final' modifier when moving to an interface
#KT-15640 Fixed
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.refactoring.pullUp
|
||||
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
@@ -59,6 +58,10 @@ fun KtNamedDeclaration.canMoveMemberToJavaClass(targetClass: PsiClass): Boolean
|
||||
}
|
||||
|
||||
fun addMemberToTarget(targetMember: KtNamedDeclaration, targetClass: KtClassOrObject): KtNamedDeclaration {
|
||||
if (targetClass is KtClass && targetClass.isInterface()) {
|
||||
targetMember.removeModifier(KtTokens.FINAL_KEYWORD)
|
||||
}
|
||||
|
||||
if (targetMember is KtParameter) {
|
||||
val parameterList = (targetClass as KtClass).createPrimaryConstructorIfAbsent().valueParameterList!!
|
||||
val anchor = parameterList.parameters.firstOrNull { it.isVarArg || it.hasDefaultValue() }
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// NAME: I
|
||||
// SIBLING:
|
||||
class <caret>A {
|
||||
// INFO: {checked: "true"}
|
||||
final val one = 1
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
interface I {
|
||||
// INFO: {checked: "true"}
|
||||
val one: Int
|
||||
}
|
||||
|
||||
// NAME: I
|
||||
// SIBLING:
|
||||
class A : I {
|
||||
// INFO: {checked: "true"}
|
||||
final override val one = 1
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
interface I
|
||||
|
||||
class <caret>A : I {
|
||||
// INFO: {checked: "true"}
|
||||
final val one = 1
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
interface I {
|
||||
// INFO: {checked: "true"}
|
||||
val one: Int
|
||||
}
|
||||
|
||||
class A : I {
|
||||
// INFO: {checked: "true"}
|
||||
final override val one = 1
|
||||
}
|
||||
+6
@@ -4358,6 +4358,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
doExtractInterfaceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dropFinal.kt")
|
||||
public void testDropFinal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractInterface/dropFinal.kt");
|
||||
doExtractInterfaceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("specialName.kt")
|
||||
public void testSpecialName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractInterface/specialName.kt");
|
||||
|
||||
@@ -110,6 +110,12 @@ public class PullUpTestGenerated extends AbstractPullUpTest {
|
||||
doKotlinTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dropFinal.kt")
|
||||
public void testDropFinal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/dropFinal.kt");
|
||||
doKotlinTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dropModifierWhenMovingSideOverride.kt")
|
||||
public void testDropModifierWhenMovingSideOverride() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/dropModifierWhenMovingSideOverride.kt");
|
||||
|
||||
Reference in New Issue
Block a user