Does kotlinpoet-metadata have functionality simila...
# squarelibraries
s
Does kotlinpoet-metadata have functionality similar to the
Types
and
Elements
classes? There’s some reusable functionality that would be nice, such as an
isSubtypeOf(t1: KmType, t2: KmType
.
z
Are you often running into a case where you don't have the original Class or TypeElement first?
s
Yes. I am trying to check the supertype of primary constructor value parameters. I thought I could use the inspector to then extract the corresponding
KmClass
for the parameter type but the inspector is crashing when trying to resolve Kotlin primitives, such as
kotlin.String
, which makes sense because the Kotlin data types are mirrors of Java types.
The reason I don’t have the original TypeElement for these parameters is because I’m using the inspector to extract the primary constructor. As far as I know there’s no way to get the original ExecutableElement from a ImmutableKmConstructor
z
my memory is fuzzy, but ElementsInspector also will put the
ExecutableElement
in tags iirc
ehhh nvm, doesn’t look like we do. Seems a valid case though. Worst case though, you can look up the original element from its km signature
I don’t know if we want to add APIs vs just giving the original source elements and use the existing ones
s
Worst case though, you can look up the original element from its km signature
How do I do this? Would I be manually inspecting each constructor, then checking if the parameters are the same?
The separate issue is that just looking up an Element from the Kotlin class name doesn’t work reliably. There is no way to get a TypeMirror for Kotlin types such as
kotlin.String
.