How can i get the type of a property that does not...
# compiler
a
How can i get the type of a property that does not have its type explicitly specified? ie
val property = "value"
Current code:
Copy code
val environment = KotlinCoreEnvironment.createForProduction(
        projectDisposable = Disposer.newDisposable(),
        configuration = CompilerConfiguration(),
        configFiles = EnvironmentConfigFiles.JS_CONFIG_FILES
    )

    val fileWithProperty = PsiManager.getInstance(environment.project)
        .findFile(LightVirtualFile("FileWithProperty.kt", INSTANCE, "val property = \"value\"")) as KtFile

    val myVal = fileWithProperty.declarations.first() as KtProperty
when i inspect
myVal
there is nothing that hints towards the type (string) of the property. Reading this channel I think I need a binding context, but I don't understand how to create one. For context, I am building a CLI app (not a plugin)
h
Well, you basically need to setup the whole compiler and run it until type resolution stage to get type interference. I would take a look at the new Analytics api instead, that does all the setup and FIR analysis. Detect (and ksp) uses the standalone api with a cli entrypoint.
2
a
I would take a look at the new Analytics api instead
where can i find that? so far I have been searching in this slack and via chatgpt. unless you mean to have a look at detect and ksp sources
h
It’s very new so I would just look at detekt sources directly.
a
alright. thanks for the pointer