Proper way to obtain ResolveCache instance

Hi all,

how shall I obtain ResolveCache in my PsiReferenceResolver  ?

Via psi element - file - project - static method  or via ServiceManager.getService(ResolveCache.class) ?
Or is there some nice dependency injection mechanism?

3 comments

All three of those will work. If you have a project component, project service or an extension in a project-scoped extension point, and if you add a parameter of type ResolveCache to your constructor, the instance will be injected.

0

Tried it:


  20428]  ERROR - i.util.KeyedExtensionCollector - ****************.ApdlReferenceContributor has unsatisfied dependency: class com.intellij.psi.impl.source.resolve.ResolveCache among unsatisfiable dependencies: [[class com.intellij.psi.impl.source.resolve.ResolveCache]] where AreaPicoContainer[null] was the leaf container being asked for dependencies.
org.picocontainer.defaults.UnsatisfiableDependenciesException: com.kosmosbanking.apdl.idea.psi.ApdlReferenceContributor has unsatisfied dependency: class com.intellij.psi.impl.source.resolve.ResolveCache among unsatisfiable dependencies: [[class com.intellij.psi.impl.source.resolve.ResolveCache]] where AreaPicoContainer[null] was the leaf container being asked for dependencies.
     at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getGreediestSatisfiableConstructor(ConstructorInjectionComponentAdapter.java:191)
     at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:210)


registeres as;


  <psi.referenceContributor
                implementation="**************************.ApdlReferenceContributor"/>


Source:


   private  final ResolveCache resolveCache;

    public ApdlReferenceContributor(ResolveCache resolveCache) {
        this.resolveCache = resolveCache;

        System.err.println("********************** resolve cace instance provided>" + resolveCache);
    }


I thought reference constributor is project extension poing....

0

No, this is an application level extension. To check this, you can find the extension point declaration in the CE source code (LangExtensionPoints.xml in this case) and check whether its area is set to IDEA_PROJECT.

0

Please sign in to leave a comment.