kotlinpoet icon indicating copy to clipboard operation
kotlinpoet copied to clipboard

KType can be more than just parameterized types or typevariable

Open ZacSweers opened this issue 6 years ago • 2 comments

This is kotlin's equivalent of a Type and can also just be a regular class. The current KType.asTypeName() is in ParameterizedTypeName.kt though, and should probably be generified and moved to TypeName.kt

ZacSweers avatar Jun 21 '19 23:06 ZacSweers

looking further, it looks like this eventually routes through TypeName, maybe it should just be moved to there?

ZacSweers avatar Jun 25 '19 03:06 ZacSweers

technically possible with typeOf() but that's marked as experimental. It would be pretty straightforward though, and could be used as basically just a proxy to KType.asTypeName()

@ExperimentalStdlibApi
inline fun <reified T> typeName(): TypeName {
  val type = typeOf<T>()
  return type.asTypeName()
}

ZacSweers avatar Jun 28 '19 00:06 ZacSweers