/
KProperty.kt
269 lines (237 loc) · 10.2 KB
/
KProperty.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("IMPLEMENTING_FUNCTION_INTERFACE")
package kotlin.reflect
/**
* Represents a property, such as a named `val` or `var` declaration.
* Instances of this class are obtainable by the `::` operator.
*
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/reflection.html)
* for more information.
*
* @param R the type of the property.
*/
public interface KProperty<out R> : KCallable<R> {
/**
* `true` if this property is `lateinit`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#late-initialized-properties)
* for more information.
*/
@SinceKotlin("1.1")
public val isLateinit: Boolean
/**
* `true` if this property is `const`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#compile-time-constants)
* for more information.
*/
@SinceKotlin("1.1")
public val isConst: Boolean
/** The getter of this property, used to obtain the value of the property. */
public val getter: Getter<R>
/**
* Represents a property accessor, which is a `get` or `set` method declared alongside the property.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/properties.html#getters-and-setters)
* for more information.
*
* @param R the type of the property, which it is an accessor of.
*/
public interface Accessor<out R> {
/** The property which this accessor is originated from. */
public val property: KProperty<R>
}
/**
* Getter of the property is a `get` method declared alongside the property.
*/
public interface Getter<out R> : Accessor<R>, KFunction<R>
}
/**
* Represents a property declared as a `var`.
*/
public interface KMutableProperty<R> : KProperty<R> {
/** The setter of this mutable property, used to change the value of the property. */
public val setter: Setter<R>
/**
* Setter of the property is a `set` method declared alongside the property.
*/
public interface Setter<R> : KProperty.Accessor<R>, KFunction<Unit>
}
/**
* Represents a property without any kind of receiver.
* Such property is either originally declared in a receiverless context such as a package,
* or has the receiver bound to it.
*/
public interface KProperty0<out R> : KProperty<R>, () -> R {
/**
* Returns the current value of the property.
*/
public fun get(): R
/**
* Returns the value of the delegate if this is a delegated property, or `null` if this property is not delegated.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/delegated-properties.html)
* for more information.
*/
@SinceKotlin("1.1")
public fun getDelegate(): Any?
override val getter: Getter<R>
/**
* Getter of the property is a `get` method declared alongside the property.
*
* Can be used as a function that takes 0 arguments and returns the value of the property type [R].
*/
public interface Getter<out R> : KProperty.Getter<R>, () -> R
}
/**
* Represents a `var`-property without any kind of receiver.
*/
public interface KMutableProperty0<R> : KProperty0<R>, KMutableProperty<R> {
/**
* Modifies the value of the property.
*
* @param value the new value to be assigned to this property.
*/
public fun set(value: R)
override val setter: Setter<R>
/**
* Setter of the property is a `set` method declared alongside the property.
*
* Can be used as a function that takes new property value as an argument and returns [Unit].
*/
public interface Setter<R> : KMutableProperty.Setter<R>, (R) -> Unit
}
/**
* Represents a property, operations on which take one receiver as a parameter.
*
* @param T the type of the receiver which should be used to obtain the value of the property.
* @param R the type of the property.
*/
public interface KProperty1<T, out R> : KProperty<R>, (T) -> R {
/**
* Returns the current value of the property.
*
* @param receiver the receiver which is used to obtain the value of the property.
* For example, it should be a class instance if this is a member property of that class,
* or an extension receiver if this is a top level extension property.
*/
public fun get(receiver: T): R
/**
* Returns the value of the delegate if this is a delegated property, or `null` if this property is not delegated.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/delegated-properties.html)
* for more information.
*
* Note that for a top level **extension** property, the delegate is the same for all extension receivers,
* so the actual [receiver] instance passed in is not going to make any difference, it must only be a value of [T].
*
* @param receiver the receiver which is used to obtain the value of the property delegate.
* For example, it should be a class instance if this is a member property of that class,
* or an extension receiver if this is a top level extension property.
*
* @see [kotlin.reflect.full.getExtensionDelegate] // [KProperty1.getExtensionDelegate]
*/
@SinceKotlin("1.1")
public fun getDelegate(receiver: T): Any?
override val getter: Getter<T, R>
/**
* Getter of the property is a `get` method declared alongside the property.
*
* Can be used as a function that takes an argument of type [T] (the receiver) and returns the value of the property type [R].
*/
public interface Getter<T, out R> : KProperty.Getter<R>, (T) -> R
}
/**
* Represents a `var`-property, operations on which take one receiver as a parameter.
*/
public interface KMutableProperty1<T, R> : KProperty1<T, R>, KMutableProperty<R> {
/**
* Modifies the value of the property.
*
* @param receiver the receiver which is used to modify the value of the property.
* For example, it should be a class instance if this is a member property of that class,
* or an extension receiver if this is a top level extension property.
* @param value the new value to be assigned to this property.
*/
public fun set(receiver: T, value: R)
override val setter: Setter<T, R>
/**
* Setter of the property is a `set` method declared alongside the property.
*
* Can be used as a function that takes the receiver and the new property value as arguments and returns [Unit].
*/
public interface Setter<T, R> : KMutableProperty.Setter<R>, (T, R) -> Unit
}
/**
* Represents a property, operations on which take two receivers as parameters,
* such as an extension property declared in a class.
*
* @param D the type of the first receiver. In case of the extension property in a class this is
* the type of the declaring class of the property, or any subclass of that class.
* @param E the type of the second receiver. In case of the extension property in a class this is
* the type of the extension receiver.
* @param R the type of the property.
*/
public interface KProperty2<D, E, out R> : KProperty<R>, (D, E) -> R {
/**
* Returns the current value of the property. In case of the extension property in a class,
* the instance of the class should be passed first and the instance of the extension receiver second.
*
* @param receiver1 the instance of the first receiver.
* @param receiver2 the instance of the second receiver.
*/
public fun get(receiver1: D, receiver2: E): R
/**
* Returns the value of the delegate if this is a delegated property, or `null` if this property is not delegated.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/delegated-properties.html)
* for more information.
*
* In case of the extension property in a class, the instance of the class should be passed first
* and the instance of the extension receiver second.
*
* @param receiver1 the instance of the first receiver.
* @param receiver2 the instance of the second receiver.
*
* @see [kotlin.reflect.full.getExtensionDelegate] // [KProperty2.getExtensionDelegate]
*/
@SinceKotlin("1.1")
public fun getDelegate(receiver1: D, receiver2: E): Any?
override val getter: Getter<D, E, R>
/**
* Getter of the property is a `get` method declared alongside the property.
*
* Can be used as a function that takes an argument of type [D] (the first receiver), an argument of type [E] (the second receiver)
* and returns the value of the property type [R].
*/
public interface Getter<D, E, out R> : KProperty.Getter<R>, (D, E) -> R
}
/**
* Represents a `var`-property, operations on which take two receivers as parameters.
*/
public interface KMutableProperty2<D, E, R> : KProperty2<D, E, R>, KMutableProperty<R> {
/**
* Modifies the value of the property.
*
* @param receiver1 the instance of the first receiver.
* @param receiver2 the instance of the second receiver.
* @param value the new value to be assigned to this property.
*/
public fun set(receiver1: D, receiver2: E, value: R)
override val setter: Setter<D, E, R>
/**
* Setter of the property is a `set` method declared alongside the property.
*
* Can be used as a function that takes an argument of type [D] (the first receiver), an argument of type [E] (the second receiver),
* and the new property value and returns [Unit].
*/
public interface Setter<D, E, R> : KMutableProperty.Setter<R>, (D, E, R) -> Unit
}