From f9632c1ad6191f7baa236782ac36c8ca55c274ad Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 28 Jan 2016 17:17:54 +0300 Subject: [PATCH] Pull Members Up: Use light field if property doesnt't have light methods #KT-10552 Fixed --- .../idea/refactoring/memberInfo/KotlinMemberInfo.kt | 4 +++- .../pullUp/k2k/propertyWithoutLightMethod.kt | 8 ++++++++ .../pullUp/k2k/propertyWithoutLightMethod.kt.after | 10 ++++++++++ .../idea/refactoring/pullUp/PullUpTestGenerated.java | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt create mode 100644 idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt index 7866bf1be39..f64c90c182c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt @@ -20,6 +20,7 @@ import com.intellij.psi.PsiMember import com.intellij.refactoring.RefactoringBundle import com.intellij.refactoring.classMembers.MemberInfoBase import com.intellij.refactoring.util.classMembers.MemberInfo +import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor @@ -69,7 +70,8 @@ class KotlinMemberInfo(member: KtNamedDeclaration, val isSuperClass: Boolean = f fun KotlinMemberInfo.toJavaMemberInfo(): MemberInfo? { val declaration = member val psiMember: PsiMember? = when (declaration) { - is KtNamedFunction, is KtProperty -> declaration.getRepresentativeLightMethod() + is KtNamedFunction -> declaration.getRepresentativeLightMethod() + is KtProperty -> declaration.getRepresentativeLightMethod() ?: LightClassUtil.getLightClassPropertyMethods(declaration).backingField is KtClassOrObject -> declaration.toLightClass() else -> null } diff --git a/idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt b/idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt new file mode 100644 index 00000000000..863793accba --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt @@ -0,0 +1,8 @@ +open class Temp1 +open class Temp2 : Temp1() { + // INFO: {"checked": "true"} + private val used: Int = 1 + // INFO: {"checked": "false"} + private val using: Int = used + 1 +} +class Temp3 : Temp2() \ No newline at end of file diff --git a/idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt.after b/idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt.after new file mode 100644 index 00000000000..a5422f193e3 --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt.after @@ -0,0 +1,10 @@ +open class Temp1 { + // INFO: {"checked": "true"} + protected val used: Int = 1 +} + +open class Temp2 : Temp1() { + // INFO: {"checked": "false"} + private val using: Int = used + 1 +} +class Temp3 : Temp2() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java index 6a1eaf6cf7b..d24d82e1562 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java @@ -205,6 +205,12 @@ public class PullUpTestGenerated extends AbstractPullUpTest { doKotlinTest(fileName); } + @TestMetadata("propertyWithoutLightMethod.kt") + public void testPropertyWithoutLightMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/propertyWithoutLightMethod.kt"); + doKotlinTest(fileName); + } + @TestMetadata("publicToInterface.kt") public void testPublicToInterface() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/publicToInterface.kt");