Extract Interface/Pull Up: Drop 'final' modifier when moving to an interface
#KT-15640 Fixed
This commit is contained in:
@@ -479,6 +479,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
||||
- [`KT-15353`](https://youtrack.jetbrains.com/issue/KT-15353) Extract Superclass/Interface: Allow extracting class with special name (and quotes)
|
||||
- [`KT-15643`](https://youtrack.jetbrains.com/issue/KT-15643) Extract Interface/Pull Up: Disable "Make abstract" and assume it to be true for primary constructor parameter when moving to an interface
|
||||
- [`KT-15607`](https://youtrack.jetbrains.com/issue/KT-15607) Extract Interface/Pull Up: Disable internal/protected members when moving to an interface
|
||||
- [`KT-15640`](https://youtrack.jetbrains.com/issue/KT-15640) Extract Interface/Pull Up: Drop 'final' modifier when moving to an interface
|
||||
|
||||
#### Intention actions, inspections and quickfixes
|
||||
|
||||
|
||||
@@ -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