Skip to content

Commit 4aa3083

Browse files
committed
Possible fix for issue spring-projects#4798 with @OnlyInputTypes annotation
1 parent a84b3c2 commit 4aa3083

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

Diff for: pom.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,18 @@
166166
<url>https://repo.spring.io/milestone</url>
167167
</repository>
168168
</repositories>
169-
169+
<build>
170+
<plugins>
171+
<plugin>
172+
<groupId>org.jetbrains.kotlin</groupId>
173+
<artifactId>kotlin-maven-plugin</artifactId>
174+
<configuration>
175+
<args>
176+
<!-- Free compiler argument that allows @OnlyInputTypes usage -->
177+
<arg>-Xallow-kotlin-package</arg>
178+
</args>
179+
</configuration>
180+
</plugin>
181+
</plugins>
182+
</build>
170183
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package kotlin.internal
2+
3+
@Target(AnnotationTarget.TYPE_PARAMETER)
4+
@Retention(AnnotationRetention.BINARY)
5+
internal annotation class OnlyInputTypes

Diff for: spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/CriteriaExtensions.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
1617
package org.springframework.data.mongodb.core.query
1718

1819
import org.springframework.data.mapping.toDotPath
20+
import kotlin.internal.OnlyInputTypes
1921
import kotlin.reflect.KProperty
2022

2123
/**
@@ -32,7 +34,7 @@ fun Criteria.isEqualTo(o: Any?): Criteria = `is`(o)
3234
* @author Sebastien Deleuze
3335
* @since 2.0
3436
*/
35-
fun <T : Any?> Criteria.inValues(c: Collection<T>): Criteria = `in`(c)
37+
fun <@OnlyInputTypes T : Any?> Criteria.inValues(c: Collection<T>): Criteria = `in`(c)
3638

3739
/**
3840
* Extension for [Criteria.in] providing an `inValues` alias since `in` is a reserved keyword in Kotlin.

Diff for: spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/TypedCriteriaExtensions.kt

+12-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import org.springframework.data.mapping.toDotPath
2323
import org.springframework.data.mongodb.core.geo.GeoJson
2424
import org.springframework.data.mongodb.core.schema.JsonSchemaObject
2525
import java.util.regex.Pattern
26+
import kotlin.internal.OnlyInputTypes
27+
import kotlin.reflect.KMutableProperty
2628
import kotlin.reflect.KProperty
2729

2830
/**
@@ -31,7 +33,7 @@ import kotlin.reflect.KProperty
3133
* @since 2.2
3234
* @see Criteria.isEqualTo
3335
*/
34-
infix fun <T> KProperty<T>.isEqualTo(value: T) =
36+
infix fun <T> KMutableProperty<T>.isEqualTo(value: T) =
3537
Criteria(this.toDotPath()).isEqualTo(value)
3638

3739
/**
@@ -42,7 +44,7 @@ infix fun <T> KProperty<T>.isEqualTo(value: T) =
4244
* @since 2.2
4345
* @see Criteria.ne
4446
*/
45-
infix fun <T> KProperty<T>.ne(value: T): Criteria =
47+
infix fun <@OnlyInputTypes T> KProperty<T>.ne(value: T): Criteria =
4648
Criteria(this.toDotPath()).ne(value)
4749

4850
/**
@@ -53,7 +55,7 @@ infix fun <T> KProperty<T>.ne(value: T): Criteria =
5355
* @since 2.2
5456
* @see Criteria.lt
5557
*/
56-
infix fun <T> KProperty<T>.lt(value: Any): Criteria =
58+
infix fun <@OnlyInputTypes T> KProperty<T>.lt(value: Any): Criteria =
5759
Criteria(this.toDotPath()).lt(value)
5860

5961
/**
@@ -64,7 +66,7 @@ infix fun <T> KProperty<T>.lt(value: Any): Criteria =
6466
* @since 2.2
6567
* @see Criteria.lte
6668
*/
67-
infix fun <T> KProperty<T>.lte(value: Any): Criteria =
69+
infix fun <@OnlyInputTypes T> KProperty<T>.lte(value: Any): Criteria =
6870
Criteria(this.toDotPath()).lte(value)
6971

7072
/**
@@ -75,7 +77,7 @@ infix fun <T> KProperty<T>.lte(value: Any): Criteria =
7577
* @since 2.2
7678
* @see Criteria.gt
7779
*/
78-
infix fun <T> KProperty<T>.gt(value: Any): Criteria =
80+
infix fun <@OnlyInputTypes T> KProperty<T>.gt(value: Any): Criteria =
7981
Criteria(this.toDotPath()).gt(value)
8082

8183
/**
@@ -86,7 +88,7 @@ infix fun <T> KProperty<T>.gt(value: Any): Criteria =
8688
* @since 2.2
8789
* @see Criteria.gte
8890
*/
89-
infix fun <T> KProperty<T>.gte(value: Any): Criteria =
91+
infix fun <@OnlyInputTypes T> KProperty<T>.gte(value: Any): Criteria =
9092
Criteria(this.toDotPath()).gte(value)
9193

9294
/**
@@ -97,7 +99,7 @@ infix fun <T> KProperty<T>.gte(value: Any): Criteria =
9799
* @since 2.2
98100
* @see Criteria.inValues
99101
*/
100-
fun <T> KProperty<T>.inValues(vararg o: Any): Criteria =
102+
fun <@OnlyInputTypes T> KProperty<T>.inValues(vararg o: Any): Criteria =
101103
Criteria(this.toDotPath()).`in`(*o)
102104

103105
/**
@@ -108,7 +110,7 @@ fun <T> KProperty<T>.inValues(vararg o: Any): Criteria =
108110
* @since 2.2
109111
* @see Criteria.inValues
110112
*/
111-
infix fun <T> KProperty<T>.inValues(value: Collection<T>): Criteria =
113+
infix fun <@OnlyInputTypes T> KProperty<T>.inValues(value: Collection<T>): Criteria =
112114
Criteria(this.toDotPath()).`in`(value)
113115

114116
/**
@@ -119,7 +121,7 @@ infix fun <T> KProperty<T>.inValues(value: Collection<T>): Criteria =
119121
* @since 2.2
120122
* @see Criteria.nin
121123
*/
122-
fun <T> KProperty<T>.nin(vararg o: Any): Criteria =
124+
fun <@OnlyInputTypes T> KProperty<T>.nin(vararg o: Any): Criteria =
123125
Criteria(this.toDotPath()).nin(*o)
124126

125127
/**
@@ -130,7 +132,7 @@ fun <T> KProperty<T>.nin(vararg o: Any): Criteria =
130132
* @since 2.2
131133
* @see Criteria.nin
132134
*/
133-
infix fun <T> KProperty<T>.nin(value: Collection<T>): Criteria =
135+
infix fun <@OnlyInputTypes T> KProperty<T>.nin(value: Collection<T>): Criteria =
134136
Criteria(this.toDotPath()).nin(value)
135137

136138
/**

Diff for: spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/TypedUpdateExtensions.kt

+21-19
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
1617
package org.springframework.data.mongodb.core.query
1718

1819
import org.springframework.data.mapping.toDotPath
1920
import org.springframework.data.mongodb.core.query.Update.Position
21+
import kotlin.internal.OnlyInputTypes
2022
import kotlin.reflect.KProperty
2123

2224
/**
@@ -26,7 +28,7 @@ import kotlin.reflect.KProperty
2628
* @since 4.4
2729
* @see Update.update
2830
*/
29-
fun <T> update(key: KProperty<T>, value: T?) =
31+
fun <@OnlyInputTypes T> update(key: KProperty<T>, value: T?) =
3032
Update.update(key.toDotPath(), value)
3133

3234
/**
@@ -36,7 +38,7 @@ fun <T> update(key: KProperty<T>, value: T?) =
3638
* @since 4.4
3739
* @see Update.set
3840
*/
39-
fun <T> Update.set(key: KProperty<T>, value: T?) =
41+
fun <@OnlyInputTypes T> Update.set(key: KProperty<T>, value: T?) =
4042
set(key.toDotPath(), value)
4143

4244
/**
@@ -46,7 +48,7 @@ fun <T> Update.set(key: KProperty<T>, value: T?) =
4648
* @since 4.4
4749
* @see Update.setOnInsert
4850
*/
49-
fun <T> Update.setOnInsert(key: KProperty<T>, value: T?) =
51+
fun <@OnlyInputTypes T> Update.setOnInsert(key: KProperty<T>, value: T?) =
5052
setOnInsert(key.toDotPath(), value)
5153

5254
/**
@@ -56,7 +58,7 @@ fun <T> Update.setOnInsert(key: KProperty<T>, value: T?) =
5658
* @since 4.4
5759
* @see Update.unset
5860
*/
59-
fun <T> Update.unset(key: KProperty<T>) =
61+
fun <@OnlyInputTypes T> Update.unset(key: KProperty<T>) =
6062
unset(key.toDotPath())
6163

6264
/**
@@ -66,10 +68,10 @@ fun <T> Update.unset(key: KProperty<T>) =
6668
* @since 4.4
6769
* @see Update.inc
6870
*/
69-
fun <T> Update.inc(key: KProperty<T>, inc: Number) =
71+
fun <@OnlyInputTypes T> Update.inc(key: KProperty<T>, inc: Number) =
7072
inc(key.toDotPath(), inc)
7173

72-
fun <T> Update.inc(key: KProperty<T>) =
74+
fun <@OnlyInputTypes T> Update.inc(key: KProperty<T>) =
7375
inc(key.toDotPath())
7476

7577
/**
@@ -79,7 +81,7 @@ fun <T> Update.inc(key: KProperty<T>) =
7981
* @since 4.4
8082
* @see Update.push
8183
*/
82-
fun <T> Update.push(key: KProperty<Collection<T>>, value: T?) =
84+
fun <@OnlyInputTypes T> Update.push(key: KProperty<Collection<T>>, value: T?) =
8385
push(key.toDotPath(), value)
8486

8587
/**
@@ -91,7 +93,7 @@ fun <T> Update.push(key: KProperty<Collection<T>>, value: T?) =
9193
* @since 4.4
9294
* @see Update.push
9395
*/
94-
fun <T> Update.push(key: KProperty<T>) =
96+
fun <@OnlyInputTypes T> Update.push(key: KProperty<T>) =
9597
push(key.toDotPath())
9698

9799
/**
@@ -102,7 +104,7 @@ fun <T> Update.push(key: KProperty<T>) =
102104
* @since 4.4
103105
* @see Update.addToSet
104106
*/
105-
fun <T> Update.addToSet(key: KProperty<T>) =
107+
fun <@OnlyInputTypes T> Update.addToSet(key: KProperty<T>) =
106108
addToSet(key.toDotPath())
107109

108110
/**
@@ -112,7 +114,7 @@ fun <T> Update.addToSet(key: KProperty<T>) =
112114
* @since 4.4
113115
* @see Update.addToSet
114116
*/
115-
fun <T> Update.addToSet(key: KProperty<Collection<T>>, value: T?) =
117+
fun <@OnlyInputTypes T> Update.addToSet(key: KProperty<Collection<T>>, value: T?) =
116118
addToSet(key.toDotPath(), value)
117119

118120
/**
@@ -122,7 +124,7 @@ fun <T> Update.addToSet(key: KProperty<Collection<T>>, value: T?) =
122124
* @since 4.4
123125
* @see Update.pop
124126
*/
125-
fun <T> Update.pop(key: KProperty<T>, pos: Position) =
127+
fun <@OnlyInputTypes T> Update.pop(key: KProperty<T>, pos: Position) =
126128
pop(key.toDotPath(), pos)
127129

128130
/**
@@ -132,7 +134,7 @@ fun <T> Update.pop(key: KProperty<T>, pos: Position) =
132134
* @since 4.4
133135
* @see Update.pull
134136
*/
135-
fun <T> Update.pull(key: KProperty<T>, value: Any) =
137+
fun <@OnlyInputTypes T> Update.pull(key: KProperty<T>, value: Any) =
136138
pull(key.toDotPath(), value)
137139

138140
/**
@@ -142,7 +144,7 @@ fun <T> Update.pull(key: KProperty<T>, value: Any) =
142144
* @since 4.4
143145
* @see Update.pullAll
144146
*/
145-
fun <T> Update.pullAll(key: KProperty<Collection<T>>, values: Array<T>) =
147+
fun <@OnlyInputTypes T> Update.pullAll(key: KProperty<Collection<T>>, values: Array<T>) =
146148
pullAll(key.toDotPath(), values)
147149

148150
/**
@@ -152,7 +154,7 @@ fun <T> Update.pullAll(key: KProperty<Collection<T>>, values: Array<T>) =
152154
* @since 4.4
153155
* @see Update.currentDate
154156
*/
155-
fun <T> Update.currentDate(key: KProperty<T>) =
157+
fun <@OnlyInputTypes T> Update.currentDate(key: KProperty<T>) =
156158
currentDate(key.toDotPath())
157159

158160
/**
@@ -162,7 +164,7 @@ fun <T> Update.currentDate(key: KProperty<T>) =
162164
* @since 4.4
163165
* @see Update.currentTimestamp
164166
*/
165-
fun <T> Update.currentTimestamp(key: KProperty<T>) =
167+
fun <@OnlyInputTypes T> Update.currentTimestamp(key: KProperty<T>) =
166168
currentTimestamp(key.toDotPath())
167169

168170
/**
@@ -172,7 +174,7 @@ fun <T> Update.currentTimestamp(key: KProperty<T>) =
172174
* @since 4.4
173175
* @see Update.multiply
174176
*/
175-
fun <T> Update.multiply(key: KProperty<T>, multiplier: Number) =
177+
fun <@OnlyInputTypes T> Update.multiply(key: KProperty<T>, multiplier: Number) =
176178
multiply(key.toDotPath(), multiplier)
177179

178180
/**
@@ -202,7 +204,7 @@ fun <T : Any> Update.min(key: KProperty<T>, value: T) =
202204
* @since 4.4
203205
* @see Update.bitwise
204206
*/
205-
fun <T> Update.bitwise(key: KProperty<T>) =
207+
fun <@OnlyInputTypes T> Update.bitwise(key: KProperty<T>) =
206208
bitwise(key.toDotPath())
207209

208210
/**
@@ -213,7 +215,7 @@ fun <T> Update.bitwise(key: KProperty<T>) =
213215
* @since 4.4
214216
* @see Update.filterArray
215217
*/
216-
fun <T> Update.filterArray(identifier: KProperty<T>, expression: Any) =
218+
fun <@OnlyInputTypes T> Update.filterArray(identifier: KProperty<T>, expression: Any) =
217219
filterArray(identifier.toDotPath(), expression)
218220

219221
/**
@@ -223,6 +225,6 @@ fun <T> Update.filterArray(identifier: KProperty<T>, expression: Any) =
223225
* @since 4.4
224226
* @see Update.modifies
225227
*/
226-
fun <T> Update.modifies(key: KProperty<T>) =
228+
fun <@OnlyInputTypes T> Update.modifies(key: KProperty<T>) =
227229
modifies(key.toDotPath())
228230

0 commit comments

Comments
 (0)