Psi resolving outside intelliJ

Hello all,

I'm trying to use the Open APIs and Psi structures to parse Java sources programmatically, i.e. outside of the context of IntelliJ. Looking at the unit test integration hooks of intellij, I got this to work perfectly ... up to point I try to resolve declaration to definitions. From that point, the Psi classes need more information they pull from an intellij project definition (sources, modules, etc) and its services (directory index, etc).

I tried two approaches to this. First one is to setup my own application and project and bootstrap the plugins in that context. Due to the nature of the intellij internals, it is very difficult to cherry pick the right plugins/services. The other approach is to programmatically bootstrap the full IDE, but in command line mode. This shows cumbersome in the way the applications are asynchronously bootstrapped. Moreover a number of unitialized fields or forced class cast break this setup, obviously proven untreaded paths.

Maybe it is just better to cherry pick and initalize a number of necessary services to be able to use resolving in the Psi structures. That would be a third approach.

Could you guys advice at what would be the best way to go about it?

Thanks beforehand!
-wim

6 comments

Take a look at the JavaCoreApplicationEnvironment and JavaCoreProjectEnvironment classes. These should do what you need.

0

Wow ... indeed! Will try that out ASAP. These classes exists as of release 12.0.x?

0

Hello,

I got an follow-up question on this. First of all, I got the parsing to work use the core application and project environments. That works swimmingly.

The thing now is, that variables and types resolve when referencing structures in the same source file apparently; however, when the resolving needs to cross the boundaries of two files (e.g. class B extends A both in the same package), the PsiReference.resolve() methods return null.

What am I missing? Or is this as designed and should I pass via another service for this?

Thanks already for any additional information!
-wim

0

Most likely you need to set up the classpath by calling JavaCoreProjectEnvironment.addJarToClasspath() and .addSourcesToClasspath().

0

Thanks for you reply! I was already doing that, but I made another stupid mistake by not aligning the folder structure with the package structure. Obviously this breaks resolving. My excuses for this!
-wim

0

Please sign in to leave a comment.