New J2K: fix assignment target in ConvertGettersAndSettersToPropertyProcessing

#KT-36190 fixed
This commit is contained in:
Ilya Kirillov
2020-03-27 17:34:43 +03:00
parent b3e728f4fb
commit d6d843aaed
4 changed files with 29 additions and 2 deletions
@@ -238,6 +238,7 @@ private class ConvertGettersAndSettersToPropertyStatefulProcessing(
modifiers
)
ktSetter.filterModifiers()
val propertyName = property.name
if (setter is RealSetter) {
setter.function.forAllUsages { usage ->
val callExpression = usage.getStrictParentOfType<KtCallExpression>() ?: return@forAllUsages
@@ -245,10 +246,10 @@ private class ConvertGettersAndSettersToPropertyStatefulProcessing(
val newValue = callExpression.valueArguments.single()
if (qualifier != null) {
qualifier.replace(
factory.createExpression("${qualifier.receiverExpression.text}.${setter.name} = ${newValue.text}")
factory.createExpression("${qualifier.receiverExpression.text}.$propertyName = ${newValue.text}")
)
} else {
callExpression.replace(factory.createExpression("${setter.name} = ${newValue.text}"))
callExpression.replace(factory.createExpression("$propertyName = ${newValue.text}"))
}
}
}
@@ -0,0 +1,10 @@
public class TestSetter {
private static void setThing(int thing) { }
private static int isThing() { return 42; }
public static void main(String[] args) {
setThing(42);
System.out.println(isThing());
}
}
@@ -0,0 +1,11 @@
object TestSetter {
private var isThing: Int
private get() = 42
private set(thing) {}
@JvmStatic
fun main(args: Array<String>) {
isThing = 42
println(isThing)
}
}
@@ -1585,6 +1585,11 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
runTest("nj2k/testData/newJ2k/detectProperties/IsPrefix.java");
}
@TestMetadata("IsPrefixSetterCall.java")
public void testIsPrefixSetterCall() throws Exception {
runTest("nj2k/testData/newJ2k/detectProperties/IsPrefixSetterCall.java");
}
@TestMetadata("JavaKeywordPropertyName.java")
public void testJavaKeywordPropertyName() throws Exception {
runTest("nj2k/testData/newJ2k/detectProperties/JavaKeywordPropertyName.java");