mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-23 22:00:10 +08:00
Ignore empty string and arrays and 0s in _miraiContentToString
This commit is contained in:
parent
28f48e5c78
commit
40dd786f99
@ -142,9 +142,19 @@ private val KProperty1<*, *>.isConst: Boolean
|
||||
private val KClass<*>.isData: Boolean
|
||||
get() = false // on JVM, it will be resolved to member function
|
||||
|
||||
private fun Any.canBeIgnored(): Boolean {
|
||||
return when (this) {
|
||||
is String -> this.isEmpty()
|
||||
is ByteArray -> this.isEmpty()
|
||||
is Array<*> -> this.isEmpty()
|
||||
is Number -> this == 0
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun Any.contentToStringReflectively(
|
||||
prefix: String,
|
||||
filter: ((name: String, value: Any?) -> Boolean)? = null
|
||||
filter: ((name: String, value: Any?) -> Boolean)? = null,
|
||||
): String {
|
||||
val newPrefix = "$prefix "
|
||||
return (this::class.simpleName ?: "<UnnamedClass>") + "#" + this::class.hashCode() + " {\n" +
|
||||
@ -165,10 +175,13 @@ private fun Any.contentToStringReflectively(
|
||||
.joinToStringPrefixed(
|
||||
prefix = newPrefix
|
||||
) { (name: String, value: Any?) ->
|
||||
"$name=" + kotlin.runCatching {
|
||||
if (value == this) "<this>"
|
||||
else value._miraiContentToString(newPrefix)
|
||||
}.getOrElse { "<!>" }
|
||||
if (value.canBeIgnored()) ""
|
||||
else {
|
||||
"$name=" + kotlin.runCatching {
|
||||
if (value == this) "<this>"
|
||||
else value._miraiContentToString(newPrefix)
|
||||
}.getOrElse { "<!>" }
|
||||
}
|
||||
} + "\n$prefix}"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user