Skip to content

Commit

Permalink
1.1.7 小修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Oct 27, 2024
1 parent a627c84 commit d011be8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=org.tabooproject.reflex
version=1.1.6
version=1.1.7
kotlin.incremental=true
kotlin.incremental.java=true
kotlin.caching.enabled=true
Expand Down
14 changes: 14 additions & 0 deletions reflex/src/main/kotlin/org/tabooproject/reflex/ReflexClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ class ReflexClass(val structure: ClassStructure, val mode: AnalyseMode) {
}
}

/**
* 获取当前类的 [Class] 对象
*/
fun toClass(): Class<out Any> {
return structure.owner.instance ?: error("Class not found: $name")
}

/**
* 获取当前类的 [Class] 对象,可为空
*/
fun toClassOrNull(): Class<out Any>? {
return structure.owner.instance
}

override fun toString(): String {
return "ReflexClass $mode($name)"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.tabooproject.reflex

import org.junit.jupiter.api.Test
import kotlin.reflect.KProperty1

class ReflexPropertyGetter {

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD)
annotation class Key(val id: String)

class Data(
@Key("sb")
val name: String,
)

inline fun <reified T> query(process: Processor.() -> Unit) {
Processor(T::class.java).also(process)
}

class Processor(val owner: Class<*>) {

infix fun KProperty1<*, *>.eq(any: Any) {
println("正在进行 ${owner.name} 下的判定: $name eq $any")
val id = ReflexClass.of(owner).getField(name).getAnnotation(Key::class.java).property<String>("id")
println("@Key = $id")
}
}

@Test
fun test() {
query<Data> {
Data::name eq "SB"
}
}
}

0 comments on commit d011be8

Please sign in to comment.