https://kotlinlang.org logo
#reflect
Title
# reflect
d

dstarcev

04/17/2018, 6:56 PM
basically I need some details on how such names are encoded in d1 and d2 properties of
@Metadata
g

gildor

04/18/2018, 2:04 AM
There is an introduction to
@Metadata
structure from @Eugenio

https://www.youtube.com/watch?v=dAQaZFyZ_hQ

🎉 2
u

udalov

04/19/2018, 7:13 AM
We're working on a library to give access to that data, it's coming shortly, see https://youtrack.jetbrains.com/issue/KT-23198
👏 2
👍 1
d

dstarcev

04/19/2018, 7:57 AM
@udalov will kotlin reflection be broken if names of the properties defined in the primary constructor are different from the according backing fields? e.g. as the result of obfuscation
e

Eugenio

04/19/2018, 8:06 AM
@dstarcev yep!
@udalov will it also work at compile time (like with kapt), or only runtime?
u

udalov

04/19/2018, 8:23 AM
@dstarcev can’t say for sure, but yeah, probably
@Eugenio both. It takes kotlin.Metadata’s content (ints, arrays of strings, etc) as an input
d

dstarcev

04/19/2018, 8:29 AM
@Eugenio can I use https://github.com/Takhion/kotlin-metadata to parse kotlin.Metadata contents?
g

gildor

04/19/2018, 8:31 AM
Yes
e

Eugenio

04/19/2018, 8:40 AM
@dstarcev yes, in a few days I'll release v2 which will make it a lot easier (and documented 😅)
This not only does the parsing of the metadata, but uses the Java Annotation Processing APIs to derive type information, kinda like Kotlin reflection, but at compile time
It's still lower level though
Because you don't necesaarily have access to full types, the rules are slightly different
d

dstarcev

04/19/2018, 8:56 AM
@Eugenio how do I do it with the current version? I have values of
kotlin.Metadata
properties as an input
If I am not mistaken, I need to get an instance of
me.eugeniomarletti.kotlin.metadata.KotlinClassMetadata
2 Views