fix: nested class name support
This commit is contained in:
@ -9,21 +9,26 @@ object Helpers {
|
||||
|
||||
fun KType.getSimpleSlug(): String = when {
|
||||
this.arguments.isNotEmpty() -> genericNameAdapter(this, classifier as KClass<*>)
|
||||
else -> (classifier as KClass<*>).simpleName ?: error("Could not determine simple name for $this")
|
||||
else -> (classifier as KClass<*>).kompendiumSlug() ?: error("Could not determine simple name for $this")
|
||||
}
|
||||
|
||||
fun KType.getReferenceSlug(): String = when {
|
||||
arguments.isNotEmpty() -> "$COMPONENT_SLUG/${genericNameAdapter(this, classifier as KClass<*>)}"
|
||||
else -> "$COMPONENT_SLUG/${(classifier as KClass<*>).simpleName}"
|
||||
else -> "$COMPONENT_SLUG/${(classifier as KClass<*>).kompendiumSlug()}"
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
private fun KClass<*>.kompendiumSlug(): String? {
|
||||
if (java.packageName == "java.lang") return simpleName
|
||||
if (java.packageName == "java.util") return simpleName
|
||||
val pkg = java.packageName
|
||||
return qualifiedName?.replace(pkg, "")?.replace(".", "")
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts a class with type parameters into a reference friendly string
|
||||
*/
|
||||
private fun genericNameAdapter(type: KType, clazz: KClass<*>): String {
|
||||
val classNames = type.arguments
|
||||
.map { it.type?.classifier as KClass<*> }
|
||||
.map { it.simpleName }
|
||||
return classNames.joinToString(separator = "-", prefix = "${clazz.simpleName}-")
|
||||
.map { it.kompendiumSlug() }
|
||||
return classNames.joinToString(separator = "-", prefix = "${clazz.kompendiumSlug()}-")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user