Best way to associate data with a PsiElement?

I want to associate some information with the PsiElement subclass instances in my plugin, and I'm not sure of the best way to do this. I'd like to cache information such as inferred types and values calculated from symbol resolution, as well as tag elements during the symbol resolution process with information that will later be useful during annotation. I can see two obvious ways to do this, either cache the data with a weak hash map (like ResolveCache) or store the values in the userdata. I'm not 100% clear on the lifecycle of PsiElements - any recommendations as to which of these would be more appropriate?

Comment actions Permalink

The recommended approach is to put CachedValues (created using CachedValueManager) into the userdata of PsiElements.

Comment actions Permalink

Great, thanks Dmitry.


Please sign in to leave a comment.