Skip to content

Possible fix for issue #4798 with @OnlyInputTypes annotation #4799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -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
@@ -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

/**
@@ -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.
Original file line number Diff line number Diff line change
@@ -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

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
Original file line number Diff line number Diff line change
@@ -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

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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())

/**
@@ -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())

/**
@@ -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)

/**
@@ -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())

/**
@@ -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())

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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)

/**
@@ -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())

/**
@@ -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())

/**
@@ -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)

/**
@@ -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())

/**
@@ -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)

/**
@@ -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())