Merge pull request #515 from dmekhanikov/master
Introduce propertyDelegated method in delegates
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata, s: String = "is OK") { name = "${p.name} $s" }
|
||||
}
|
||||
|
||||
val prop by Delegate()
|
||||
|
||||
fun box(): String {
|
||||
return if (prop == "prop is OK") "OK" else "fail";
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
val prop: String by Delegate()
|
||||
|
||||
inner class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
class A {
|
||||
val p = Delegate()
|
||||
val prop by p
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
fun foo() = Delegate()
|
||||
|
||||
class A {
|
||||
val prop by foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
val p = Delegate()
|
||||
|
||||
class A {
|
||||
val prop by p
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: A, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
val A.prop by Delegate()
|
||||
|
||||
class A {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: F.A, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
class F {
|
||||
val A.prop by Delegate()
|
||||
|
||||
class A {
|
||||
}
|
||||
|
||||
fun foo(): String {
|
||||
return A().prop
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (F().foo() == "prop") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
trait A {
|
||||
val prop: String
|
||||
}
|
||||
|
||||
class AImpl: A {
|
||||
override val prop by Delegate()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if(AImpl().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class Delegate {
|
||||
var inner = "OK"
|
||||
fun get(t: Any?, p: PropertyMetadata): String = inner
|
||||
|
||||
private fun propertyDelegated(p: PropertyMetadata) { inner = "fail" }
|
||||
fun propertyDelegated() { inner = "fail" }
|
||||
fun propertyDelegated(a: Int) { inner = "fail" }
|
||||
fun propertyDelegated(a: String) { inner = "fail" }
|
||||
fun propertyDelegated(p: PropertyMetadata, a: Int) { inner = "fail" }
|
||||
fun propertyDelegated<T>(p: PropertyMetadata, s: String = "") { inner = "fail" }
|
||||
}
|
||||
|
||||
val prop by Delegate()
|
||||
|
||||
fun box(): String {
|
||||
return prop
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
}
|
||||
|
||||
fun Delegate.propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
|
||||
class A {
|
||||
val prop by Delegate()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
class A {
|
||||
private val prop by Delegate()
|
||||
|
||||
fun test(): String {
|
||||
return if (prop == "prop") "OK" else "fail"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A().test()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
val prop by Delegate()
|
||||
|
||||
fun box(): String {
|
||||
return if (prop == "prop") "OK" else "fail"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Delegate {
|
||||
var count = 0
|
||||
fun get(t: Any?, p: PropertyMetadata) {}
|
||||
fun propertyDelegated(vararg p: PropertyMetadata) { count++ }
|
||||
}
|
||||
|
||||
val delegate = Delegate()
|
||||
|
||||
val prop1 by delegate
|
||||
val prop2 by delegate
|
||||
|
||||
fun box(): String {
|
||||
return if(delegate.count == 2) "OK" else "fail"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(p: PropertyMetadata) { name = p.name }
|
||||
}
|
||||
|
||||
class A {
|
||||
inner class B {
|
||||
val prop by Delegate()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = A().B().prop
|
||||
return if(p == "prop") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Delegate {
|
||||
var name = ""
|
||||
fun get(t: Any?, p: PropertyMetadata): String = name
|
||||
fun propertyDelegated(vararg p: PropertyMetadata) { name = p[0].name }
|
||||
}
|
||||
|
||||
val prop by Delegate()
|
||||
|
||||
fun box(): String {
|
||||
return if (prop == "prop") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
val a: Int by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY!>Delegate()<!>
|
||||
|
||||
class Delegate {
|
||||
fun get(t: Any?, p: PropertyMetadata): Int {
|
||||
t.equals(p) // to avoid UNUSED_PARAMETER warning
|
||||
return 1
|
||||
}
|
||||
|
||||
fun propertyDelegated(p: PropertyMetadata) {
|
||||
p.equals(p)
|
||||
}
|
||||
|
||||
fun propertyDelegated(p: PropertyMetadata, s: String = "") {
|
||||
p.equals(s)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
internal val a: kotlin.Int
|
||||
|
||||
internal final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun propertyDelegated(/*0*/ p: kotlin.PropertyMetadata): kotlin.Unit
|
||||
internal final fun propertyDelegated(/*0*/ p: kotlin.PropertyMetadata, /*1*/ s: kotlin.String = ...): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
val a: Int by <!DELEGATE_PD_METHOD_NONE_APPLICABLE!>Delegate()<!>
|
||||
|
||||
class Delegate {
|
||||
fun get(t: Any?, p: PropertyMetadata): Int {
|
||||
t.equals(p) // to avoid UNUSED_PARAMETER warning
|
||||
return 1
|
||||
}
|
||||
|
||||
fun propertyDelegated<T>(p: PropertyMetadata) {
|
||||
p.equals(p)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
internal val a: kotlin.Int
|
||||
|
||||
internal final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun </*0*/ T> propertyDelegated(/*0*/ p: kotlin.PropertyMetadata): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
val a: Int by Delegate()
|
||||
|
||||
class Delegate {
|
||||
fun get(t: Any?, p: PropertyMetadata): Int {
|
||||
t.equals(p) // to avoid UNUSED_PARAMETER warning
|
||||
return 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
internal val a: kotlin.Int
|
||||
|
||||
internal final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
val a: Int by <!DELEGATE_PD_METHOD_NONE_APPLICABLE!>Delegate()<!>
|
||||
|
||||
class Delegate {
|
||||
fun get(t: Any?, p: PropertyMetadata): Int {
|
||||
t.equals(p) // to avoid UNUSED_PARAMETER warning
|
||||
return 1
|
||||
}
|
||||
|
||||
private fun propertyDelegated(p: PropertyMetadata) {
|
||||
p.equals(p)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
internal val a: kotlin.Int
|
||||
|
||||
internal final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
private final fun propertyDelegated(/*0*/ p: kotlin.PropertyMetadata): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
val a: Int by <!DELEGATE_PD_METHOD_NONE_APPLICABLE!>Delegate()<!>
|
||||
|
||||
class Delegate {
|
||||
fun get(t: Any?, p: PropertyMetadata): Int {
|
||||
t.equals(p) // to avoid UNUSED_PARAMETER warning
|
||||
return 1
|
||||
}
|
||||
|
||||
fun propertyDelegated() {}
|
||||
|
||||
fun propertyDelegated(a: Int) {
|
||||
a.equals(a)
|
||||
}
|
||||
|
||||
fun propertyDelegated(a: String) {
|
||||
a.equals(a)
|
||||
}
|
||||
|
||||
fun propertyDelegated(p: PropertyMetadata, a: Int) {
|
||||
p.equals(a)
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
internal val a: kotlin.Int
|
||||
|
||||
internal final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun propertyDelegated(): kotlin.Unit
|
||||
internal final fun propertyDelegated(/*0*/ a: kotlin.Int): kotlin.Unit
|
||||
internal final fun propertyDelegated(/*0*/ p: kotlin.PropertyMetadata, /*1*/ a: kotlin.Int): kotlin.Unit
|
||||
internal final fun propertyDelegated(/*0*/ a: kotlin.String): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user