@@ -18,51 +18,28 @@ package org.springframework.data.core
1818import kotlin.reflect.KProperty
1919import kotlin.reflect.KProperty1
2020
21+
2122/* *
22- * Abstraction of a property path consisting of [KProperty].
23+ * Extension for [KProperty] providing an `toPath` function to render a [KProperty] in dot notation .
2324 *
24- * @author Tjeu Kayim
2525 * @author Mark Paluch
26- * @author Yoann de Martino
2726 * @since 2.5
27+ * @see org.springframework.data.core.PropertyPath.toDotPath
2828 */
29- internal class KPropertyPath <T , U >(
30- val parent : KProperty <U ?>,
31- val child : KProperty1 <U , T >
32- ) : KProperty<T> by child
29+ fun KProperty <* >.toDotPath (): String = asString(this )
3330
3431/* *
35- * Abstraction of a property path that consists of parent [KProperty],
36- * and child property [KProperty], where parent [parent] has an [Iterable]
37- * of children, so it represents 1-M mapping.
32+ * Extension for [KProperty1] providing an `toPath` function to create a [TypedPropertyPath].
3833 *
39- * @author Mikhail Polivakha
40- * @since 3.5
41- */
42- internal class KIterablePropertyPath <T , U >(
43- val parent : KProperty <Iterable <U ?>? >,
44- val child : KProperty1 <U , T >
45- ) : KProperty<T> by child
46-
47- /* *
48- * Recursively construct field name for a nested property.
49- * @author Tjeu Kayim
50- * @author Mikhail Polivakha
34+ * @author Mark Paluch
35+ * @since 4.1
36+ * @see org.springframework.data.core.PropertyPath.toDotPath
5137 */
52- fun asString (property : KProperty <* >): String {
53- return when (property) {
54- is KPropertyPath <* , * > ->
55- " ${asString(property.parent)} .${property.child.name} "
56-
57- is KIterablePropertyPath <* , * > ->
58- " ${asString(property.parent)} .${property.child.name} "
59-
60- else -> property.name
61- }
62- }
38+ fun <T : Any , P > KProperty1 <T , P >.toPath (): TypedPropertyPath <T , P > =
39+ KTypedPropertyPath .of(this )
6340
6441/* *
65- * Builds [KPropertyPath ] from Property References.
42+ * Builds [KPropertyReference ] from Property References.
6643 * Refer to a nested property in an embeddable or association.
6744 *
6845 * For example, referring to the field "author.name":
@@ -71,14 +48,14 @@ fun asString(property: KProperty<*>): String {
7148 * ```
7249 * @author Tjeu Kayim
7350 * @author Yoann de Martino
74- * @since 2.5
51+ * @since 4.1
7552 */
7653@JvmName(" div" )
77- operator fun <T , U > KProperty<T ?>.div (other : KProperty1 <T , U >): KProperty < U > =
78- KPropertyPath (this , other)
54+ operator fun <T , M , P > KProperty1 < T , M ?>.div (other : KProperty1 <M , P ? >): KProperty1 < T , P > =
55+ KSinglePropertyReference (this , other) as KProperty1 < T , P >
7956
8057/* *
81- * Builds [KPropertyPath ] from Property References.
58+ * Builds [KPropertyReference ] from Property References.
8259 * Refer to a nested property in an embeddable or association.
8360 *
8461 * Note, that this function is different from [div] above in the
@@ -91,8 +68,8 @@ operator fun <T, U> KProperty<T?>.div(other: KProperty1<T, U>): KProperty<U> =
9168 * Author::books / Book::title contains "Bartleby"
9269 * ```
9370 * @author Mikhail Polivakha
94- * @since 3.5
71+ * @since 4.1
9572 */
9673@JvmName(" divIterable" )
97- operator fun <T , U > KProperty< Collection<T ?>?>.div (other : KProperty1 <T , U >): KProperty < U > =
98- KIterablePropertyPath (this , other)
74+ operator fun <T , M , P > KProperty1 < T , Collection <M ?>?>.div (other : KProperty1 <M , P ? >): KProperty1 < T , P > =
75+ KIterablePropertyReference (this , other) as KProperty1 < T , P >
0 commit comments