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
hfhbd
07/13/2025, 7:46 AM
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
Alex Styl
07/13/2025, 10:09 AM
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
hfhbd
07/13/2025, 10:23 AM
It’s very new so I would just look at detekt sources directly.