KT-12417: add support of RTTI against K(Mutable)Property* types

This commit is contained in:
Alexey Andreev
2016-06-14 16:38:17 +03:00
parent 048b6b60e9
commit 2e6a48576d
13 changed files with 256 additions and 36 deletions
@@ -120,6 +120,15 @@ class ReflectionTypes(module: ModuleDescriptor) {
fun isCallableType(type: KotlinType): Boolean =
type.isFunctionTypeOrSubtype || isKCallableType(type)
@JvmStatic fun isFunctionalKPropertyType(type: KotlinType): Boolean {
val descriptor = type.constructor.declarationDescriptor ?: return false
val segments = DescriptorUtils.getFqName(descriptor).pathSegments()
return segments.size == 3 && segments.subList(0, 2) == KOTLIN_REFLECT_FQ_NAME.pathSegments() &&
segments.last().let { it.isProperty("KProperty") || it.isProperty("KMutableProperty") }
}
private fun Name.isProperty(baseName: String) = asString().startsWith(baseName) && asString() != baseName
private fun isKCallableType(type: KotlinType): Boolean =
hasFqName(type.constructor, KotlinBuiltIns.FQ_NAMES.kCallable) ||
type.constructor.supertypes.any { isKCallableType(it) }