Java to Kotlin converter: converting usages of Kotlin object members

#KT-5172 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-06-05 20:53:29 +04:00
parent e789026291
commit 0631e4fdbe
5 changed files with 40 additions and 6 deletions
@@ -294,7 +294,7 @@ open class ExpressionVisitor(protected val converter: Converter,
identifier = Identifier("size", isNullable)
}
else if (qualifier != null) {
if (referencedName == "object$") {
if (referencedName == "object$" || referencedName == "instance$") {
val target = expression.getReference()?.resolve()
if (target is LightField) { //TODO: should be KotlinLightField with check of origin here, see KT-5188
result = converter.convertExpression(qualifier)
@@ -1596,6 +1596,11 @@ public class JavaToKotlinConverterTestGenerated extends AbstractJavaToKotlinConv
doTest("j2k/tests/testData/ast/kotlinApiAccess/InheritedProperty.java");
}
@TestMetadata("ObjectMembers.java")
public void testObjectMembers() throws Exception {
doTest("j2k/tests/testData/ast/kotlinApiAccess/ObjectMembers.java");
}
@TestMetadata("Property.java")
public void testProperty() throws Exception {
doTest("j2k/tests/testData/ast/kotlinApiAccess/Property.java");
+13 -5
View File
@@ -7,8 +7,8 @@ public open class KotlinClass {
public fun statucFun(p: Int): Int = p
public var staticVar: Int = 1
public var staticProperty: Int
get() = 1
set(value) {}
get() = 1
set(value) {}
}
}
@@ -19,9 +19,17 @@ public fun Int.extensionFunction(): String = toString()
public var globalValue1: Int = 1
public var globalValue2: Int
get() = 0
set(value) {}
get() = 0
set(value) {}
public var String.extensionProperty: Int
get() = 1
set(value) {}
set(value) {}
public object KotlinObject {
public fun foo(): Int = 1
public var property1: Int = 1
public var property2: Int
get() = 1
set(value) {}
}
@@ -0,0 +1,12 @@
//file
import kotlinApi.KotlinObject;
class C {
int foo() {
KotlinObject.instance$.setProperty1(1);
KotlinObject.instance$.setProperty2(2);
return KotlinObject.instance$.foo() +
KotlinObject.instance$.getProperty1() +
KotlinObject.instance$.getProperty2();
}
}
@@ -0,0 +1,9 @@
import kotlinApi.KotlinObject
class C() {
fun foo(): Int {
KotlinObject.property1 = 1
KotlinObject.property2 = 2
return KotlinObject.foo() + KotlinObject.property1 + KotlinObject.property2
}
}