Skip to content

Commit

Permalink
Possible fix for issue spring-projects#4798 with @OnlyInputTypes anno…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
pmatysek committed Sep 27, 2024
1 parent a84b3c2 commit 4aa3083
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,18 @@
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<!-- Free compiler argument that allows @OnlyInputTypes usage -->
<arg>-Xallow-kotlin-package</arg>
</args>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kotlin.internal

@Target(AnnotationTarget.TYPE_PARAMETER)
@Retention(AnnotationRetention.BINARY)
internal annotation class OnlyInputTypes
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package org.springframework.data.mongodb.core.query

import org.springframework.data.mapping.toDotPath
import kotlin.internal.OnlyInputTypes
import kotlin.reflect.KProperty

/**
Expand All @@ -32,7 +34,7 @@ fun Criteria.isEqualTo(o: Any?): Criteria = `is`(o)
* @author Sebastien Deleuze
* @since 2.0
*/
fun <T : Any?> Criteria.inValues(c: Collection<T>): Criteria = `in`(c)
fun <@OnlyInputTypes T : Any?> Criteria.inValues(c: Collection<T>): Criteria = `in`(c)

/**
* Extension for [Criteria.in] providing an `inValues` alias since `in` is a reserved keyword in Kotlin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.springframework.data.mapping.toDotPath
import org.springframework.data.mongodb.core.geo.GeoJson
import org.springframework.data.mongodb.core.schema.JsonSchemaObject
import java.util.regex.Pattern
import kotlin.internal.OnlyInputTypes
import kotlin.reflect.KMutableProperty
import kotlin.reflect.KProperty

/**
Expand All @@ -31,7 +33,7 @@ import kotlin.reflect.KProperty
* @since 2.2
* @see Criteria.isEqualTo
*/
infix fun <T> KProperty<T>.isEqualTo(value: T) =
infix fun <T> KMutableProperty<T>.isEqualTo(value: T) =
Criteria(this.toDotPath()).isEqualTo(value)

/**
Expand All @@ -42,7 +44,7 @@ infix fun <T> KProperty<T>.isEqualTo(value: T) =
* @since 2.2
* @see Criteria.ne
*/
infix fun <T> KProperty<T>.ne(value: T): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.ne(value: T): Criteria =
Criteria(this.toDotPath()).ne(value)

/**
Expand All @@ -53,7 +55,7 @@ infix fun <T> KProperty<T>.ne(value: T): Criteria =
* @since 2.2
* @see Criteria.lt
*/
infix fun <T> KProperty<T>.lt(value: Any): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.lt(value: Any): Criteria =
Criteria(this.toDotPath()).lt(value)

/**
Expand All @@ -64,7 +66,7 @@ infix fun <T> KProperty<T>.lt(value: Any): Criteria =
* @since 2.2
* @see Criteria.lte
*/
infix fun <T> KProperty<T>.lte(value: Any): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.lte(value: Any): Criteria =
Criteria(this.toDotPath()).lte(value)

/**
Expand All @@ -75,7 +77,7 @@ infix fun <T> KProperty<T>.lte(value: Any): Criteria =
* @since 2.2
* @see Criteria.gt
*/
infix fun <T> KProperty<T>.gt(value: Any): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.gt(value: Any): Criteria =
Criteria(this.toDotPath()).gt(value)

/**
Expand All @@ -86,7 +88,7 @@ infix fun <T> KProperty<T>.gt(value: Any): Criteria =
* @since 2.2
* @see Criteria.gte
*/
infix fun <T> KProperty<T>.gte(value: Any): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.gte(value: Any): Criteria =
Criteria(this.toDotPath()).gte(value)

/**
Expand All @@ -97,7 +99,7 @@ infix fun <T> KProperty<T>.gte(value: Any): Criteria =
* @since 2.2
* @see Criteria.inValues
*/
fun <T> KProperty<T>.inValues(vararg o: Any): Criteria =
fun <@OnlyInputTypes T> KProperty<T>.inValues(vararg o: Any): Criteria =
Criteria(this.toDotPath()).`in`(*o)

/**
Expand All @@ -108,7 +110,7 @@ fun <T> KProperty<T>.inValues(vararg o: Any): Criteria =
* @since 2.2
* @see Criteria.inValues
*/
infix fun <T> KProperty<T>.inValues(value: Collection<T>): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.inValues(value: Collection<T>): Criteria =
Criteria(this.toDotPath()).`in`(value)

/**
Expand All @@ -119,7 +121,7 @@ infix fun <T> KProperty<T>.inValues(value: Collection<T>): Criteria =
* @since 2.2
* @see Criteria.nin
*/
fun <T> KProperty<T>.nin(vararg o: Any): Criteria =
fun <@OnlyInputTypes T> KProperty<T>.nin(vararg o: Any): Criteria =
Criteria(this.toDotPath()).nin(*o)

/**
Expand All @@ -130,7 +132,7 @@ fun <T> KProperty<T>.nin(vararg o: Any): Criteria =
* @since 2.2
* @see Criteria.nin
*/
infix fun <T> KProperty<T>.nin(value: Collection<T>): Criteria =
infix fun <@OnlyInputTypes T> KProperty<T>.nin(value: Collection<T>): Criteria =
Criteria(this.toDotPath()).nin(value)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package org.springframework.data.mongodb.core.query

import org.springframework.data.mapping.toDotPath
import org.springframework.data.mongodb.core.query.Update.Position
import kotlin.internal.OnlyInputTypes
import kotlin.reflect.KProperty

/**
Expand All @@ -26,7 +28,7 @@ import kotlin.reflect.KProperty
* @since 4.4
* @see Update.update
*/
fun <T> update(key: KProperty<T>, value: T?) =
fun <@OnlyInputTypes T> update(key: KProperty<T>, value: T?) =
Update.update(key.toDotPath(), value)

/**
Expand All @@ -36,7 +38,7 @@ fun <T> update(key: KProperty<T>, value: T?) =
* @since 4.4
* @see Update.set
*/
fun <T> Update.set(key: KProperty<T>, value: T?) =
fun <@OnlyInputTypes T> Update.set(key: KProperty<T>, value: T?) =
set(key.toDotPath(), value)

/**
Expand All @@ -46,7 +48,7 @@ fun <T> Update.set(key: KProperty<T>, value: T?) =
* @since 4.4
* @see Update.setOnInsert
*/
fun <T> Update.setOnInsert(key: KProperty<T>, value: T?) =
fun <@OnlyInputTypes T> Update.setOnInsert(key: KProperty<T>, value: T?) =
setOnInsert(key.toDotPath(), value)

/**
Expand All @@ -56,7 +58,7 @@ fun <T> Update.setOnInsert(key: KProperty<T>, value: T?) =
* @since 4.4
* @see Update.unset
*/
fun <T> Update.unset(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.unset(key: KProperty<T>) =
unset(key.toDotPath())

/**
Expand All @@ -66,10 +68,10 @@ fun <T> Update.unset(key: KProperty<T>) =
* @since 4.4
* @see Update.inc
*/
fun <T> Update.inc(key: KProperty<T>, inc: Number) =
fun <@OnlyInputTypes T> Update.inc(key: KProperty<T>, inc: Number) =
inc(key.toDotPath(), inc)

fun <T> Update.inc(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.inc(key: KProperty<T>) =
inc(key.toDotPath())

/**
Expand All @@ -79,7 +81,7 @@ fun <T> Update.inc(key: KProperty<T>) =
* @since 4.4
* @see Update.push
*/
fun <T> Update.push(key: KProperty<Collection<T>>, value: T?) =
fun <@OnlyInputTypes T> Update.push(key: KProperty<Collection<T>>, value: T?) =
push(key.toDotPath(), value)

/**
Expand All @@ -91,7 +93,7 @@ fun <T> Update.push(key: KProperty<Collection<T>>, value: T?) =
* @since 4.4
* @see Update.push
*/
fun <T> Update.push(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.push(key: KProperty<T>) =
push(key.toDotPath())

/**
Expand All @@ -102,7 +104,7 @@ fun <T> Update.push(key: KProperty<T>) =
* @since 4.4
* @see Update.addToSet
*/
fun <T> Update.addToSet(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.addToSet(key: KProperty<T>) =
addToSet(key.toDotPath())

/**
Expand All @@ -112,7 +114,7 @@ fun <T> Update.addToSet(key: KProperty<T>) =
* @since 4.4
* @see Update.addToSet
*/
fun <T> Update.addToSet(key: KProperty<Collection<T>>, value: T?) =
fun <@OnlyInputTypes T> Update.addToSet(key: KProperty<Collection<T>>, value: T?) =
addToSet(key.toDotPath(), value)

/**
Expand All @@ -122,7 +124,7 @@ fun <T> Update.addToSet(key: KProperty<Collection<T>>, value: T?) =
* @since 4.4
* @see Update.pop
*/
fun <T> Update.pop(key: KProperty<T>, pos: Position) =
fun <@OnlyInputTypes T> Update.pop(key: KProperty<T>, pos: Position) =
pop(key.toDotPath(), pos)

/**
Expand All @@ -132,7 +134,7 @@ fun <T> Update.pop(key: KProperty<T>, pos: Position) =
* @since 4.4
* @see Update.pull
*/
fun <T> Update.pull(key: KProperty<T>, value: Any) =
fun <@OnlyInputTypes T> Update.pull(key: KProperty<T>, value: Any) =
pull(key.toDotPath(), value)

/**
Expand All @@ -142,7 +144,7 @@ fun <T> Update.pull(key: KProperty<T>, value: Any) =
* @since 4.4
* @see Update.pullAll
*/
fun <T> Update.pullAll(key: KProperty<Collection<T>>, values: Array<T>) =
fun <@OnlyInputTypes T> Update.pullAll(key: KProperty<Collection<T>>, values: Array<T>) =
pullAll(key.toDotPath(), values)

/**
Expand All @@ -152,7 +154,7 @@ fun <T> Update.pullAll(key: KProperty<Collection<T>>, values: Array<T>) =
* @since 4.4
* @see Update.currentDate
*/
fun <T> Update.currentDate(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.currentDate(key: KProperty<T>) =
currentDate(key.toDotPath())

/**
Expand All @@ -162,7 +164,7 @@ fun <T> Update.currentDate(key: KProperty<T>) =
* @since 4.4
* @see Update.currentTimestamp
*/
fun <T> Update.currentTimestamp(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.currentTimestamp(key: KProperty<T>) =
currentTimestamp(key.toDotPath())

/**
Expand All @@ -172,7 +174,7 @@ fun <T> Update.currentTimestamp(key: KProperty<T>) =
* @since 4.4
* @see Update.multiply
*/
fun <T> Update.multiply(key: KProperty<T>, multiplier: Number) =
fun <@OnlyInputTypes T> Update.multiply(key: KProperty<T>, multiplier: Number) =
multiply(key.toDotPath(), multiplier)

/**
Expand Down Expand Up @@ -202,7 +204,7 @@ fun <T : Any> Update.min(key: KProperty<T>, value: T) =
* @since 4.4
* @see Update.bitwise
*/
fun <T> Update.bitwise(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.bitwise(key: KProperty<T>) =
bitwise(key.toDotPath())

/**
Expand All @@ -213,7 +215,7 @@ fun <T> Update.bitwise(key: KProperty<T>) =
* @since 4.4
* @see Update.filterArray
*/
fun <T> Update.filterArray(identifier: KProperty<T>, expression: Any) =
fun <@OnlyInputTypes T> Update.filterArray(identifier: KProperty<T>, expression: Any) =
filterArray(identifier.toDotPath(), expression)

/**
Expand All @@ -223,6 +225,6 @@ fun <T> Update.filterArray(identifier: KProperty<T>, expression: Any) =
* @since 4.4
* @see Update.modifies
*/
fun <T> Update.modifies(key: KProperty<T>) =
fun <@OnlyInputTypes T> Update.modifies(key: KProperty<T>) =
modifies(key.toDotPath())

0 comments on commit 4aa3083

Please sign in to comment.