Pull Members Up: Use light field if property doesnt't have light methods

#KT-10552 Fixed
This commit is contained in:
Alexey Sedunov
2016-01-28 17:17:54 +03:00
parent e386a6b0e9
commit f9632c1ad6
4 changed files with 27 additions and 1 deletions
@@ -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
}
@@ -0,0 +1,8 @@
open class Temp1
open class <caret>Temp2 : Temp1() {
// INFO: {"checked": "true"}
private val used: Int = 1
// INFO: {"checked": "false"}
private val using: Int = used + 1
}
class Temp3 : Temp2()
@@ -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()
@@ -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");