Conflicting CachedValue documentation?


This doc suggests using CachedValue for heavy comptations like PsiReference.resolve():

But the Javadoc for CachedValue says not to depend on "PSI elements around X, when X is a PsiElement".

In my plugin, the references often depend on nearby PSI elements.

  1. Am I supposed to use CachedValue for these resolve() calls? If not, what should I use? All of my heavy PsiElement-related computations depend on nearby PSI elements...
  2. Is this a valid use-case for CachedValuesManager.getProjectPsiDependentCache ? When I try to use this method, I get an error from the CachedValueLeakChecker:

"Incorrect CachedValue use. Provider references PSI, causing memory leaks and possible invalid element access."

This particular error comes from a custom PsiElement method:

fun term() : Term? {
val expression = this.expression() ?: return null
return CachedValuesManager.getProjectPsiDependentCache(this) {
computeTermWithArguments(expression, this.arguments())
1 comment
Comment actions Permalink

Sorry this got lost. is computeTermWithArguments() an instance method? For use in resolving, there's also com.intellij.psi.impl.source.resolve.ResolveCache


Please sign in to leave a comment.