aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt
blob: 898f21cce87b72cd8b1cb39010ae9ab4cb92c35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package at.hannibal2.skyhanni.utils

import java.lang.reflect.*

val <T> Class<T>.allFields: List<Field>
    get() = this.declaredFields.toList() + (this.superclass?.allFields ?: listOf())
val <T> Class<T>.allAccessibleFields: List<Field>
    get() = allFields.also { it.forEach { it.isAccessible = true } }

val Type.nonGeneric: Class<*>?
    get() = when (this) {
        is ParameterizedType -> this.rawType.nonGeneric
        is Class<*> -> this
        is WildcardType -> this.upperBounds[0].nonGeneric
        is TypeVariable<*> -> this.bounds[0].nonGeneric
        else -> null
    }