Support setters for Java-method-based properties in reflection

Also heuristically support the corner case of multiple properties with the same
name and signature in a Java class, see the comment in
KDeclarationContainerImpl

 #KT-11258 Fixed
This commit is contained in:
Alexander Udalov
2016-03-03 12:33:35 +03:00
parent 14b1a3a048
commit ae14d185eb
5 changed files with 77 additions and 5 deletions
@@ -0,0 +1,39 @@
// WITH_REFLECT
// FILE: J.java
public class J implements K {
private String foo;
@Override
public String getFoo() {
return foo;
}
@Override
public void setFoo(String s) {
foo = s;
}
}
// FILE: K.kt
import kotlin.test.assertEquals
import kotlin.reflect.KParameter
interface K {
var foo: String
}
fun box(): String {
val p = J::foo
assertEquals("foo", p.name)
if (p.parameters.size != 1) return "Should have only 1 parameter"
if (p.parameters.single().kind != KParameter.Kind.INSTANCE) return "Should have an instance parameter"
if (J::class.members.none { it == p }) return "No foo in members"
val j = J()
p.setter.call(j, "OK")
return p.getter.call(j)
}