Standalone UAST parser


I'm using the following code to create a standalone UAST parser:

I'm able to get UFile & UClass objects from Java files but only UFile objects from Kotlin files. After solving several NPEs looking for various services during the initialization of JavaCoreApplicationEnvironment & JavaCoreProjectEnvironment, I've gotten stuck on the following error:

Could not find installation home path. Please make sure bin/ is present in the installation directory.


I would appreciate help getting past this error but I would also appreciate it if someone can take a look through my code to tell me what I'm doing wrong in setting up the environment for Kotlin UAST support.

For example, to get past one of the NPEs I had to use the following reflection hack:

val instance = {
it.getDeclaredConstructor().let {
it.isAccessible = true
registerApplicationService(, instance)

I doubt this is how DefaultIdeTargetPlatformKindProvider is supposed to be setup so I would really appreciate some help on how I'm supposed to be setting up the environment.

评论操作 固定链接

This is a somewhat complicated task. Please see also my answer in

See also org.jetbrains.uast.kotlin.internal.CliKotlinUastResolveProviderService

评论操作 固定链接

I was able to get further using CliKotlinUastResolveProviderService as a reference but ultimately got stuck somewhere around FileBasedIndexImpl.waitUntilIndicesAreInitialized().

If I can get the standalone PSI references working I think I'll just abandon this approach.