Commit c088e423 authored by Him188's avatar Him188

(internal) _miraiContentToString: Ignore transient properties

parent a5f9504b
......@@ -11,6 +11,7 @@
package net.mamoe.mirai.qqandroid.utils
import kotlinx.serialization.Transient
import net.mamoe.mirai.utils.DefaultLogger
import net.mamoe.mirai.utils.debug
import kotlin.reflect.KClass
......@@ -210,5 +211,13 @@ private fun Any.allMembersFromSuperClassesMatching(classFilter: (KClass<out Any>
.map { it.members }
.flatMap { it.asSequence() }
.filterIsInstance<KProperty1<*, *>>()
.filterNot { it.hasAnnotation<Transient>() }
.filterNot { it.isTransient() }
.mapNotNull { it as KProperty1<Any, *> }
}
\ No newline at end of file
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
internal expect inline fun <reified T : Annotation> KProperty<*>.hasAnnotation(): Boolean
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
internal expect fun KProperty<*>.isTransient(): Boolean
\ No newline at end of file
package net.mamoe.mirai.qqandroid.utils
import java.lang.reflect.Modifier
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty1
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.jvm.javaField
internal actual fun KProperty1<*, *>.getValueAgainstPermission(receiver: Any): Any? {
return this.javaField?.apply { isAccessible = true }?.get(receiver)
}
\ No newline at end of file
}
// on JVM, it will be resolved to member function
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
actual internal inline fun <reified T : Annotation> KProperty<*>.hasAnnotation(): Boolean =
findAnnotation<T>() != null
// on JVM, it will be resolved to member function
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
actual internal fun KProperty<*>.isTransient(): Boolean =
javaField?.modifiers?.and(Modifier.TRANSIENT) != 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment