From 20f2b59cf0ecd10ad5e77095bc160aee3b795b9c Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 25 Feb 2015 19:09:34 +0100 Subject: [PATCH] clear ClsParameter.name cache on roots change (IDEA-136727) --- .../psi/impl/compiled/ClsParameterImpl.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java index b4b338523947..4cec97001741 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java @@ -16,6 +16,7 @@ package com.intellij.psi.impl.compiled; import com.intellij.openapi.project.DumbService; +import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.util.AtomicNotNullLazyValue; import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.psi.*; @@ -30,10 +31,13 @@ import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.stubs.StubElement; +import com.intellij.psi.util.CachedValueProvider; +import com.intellij.psi.util.CachedValuesManager; import com.intellij.ui.RowIcon; import com.intellij.util.IncorrectOperationException; import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -63,34 +67,37 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement @Override public String getName() { - String name = myName; - - if (name == null) { - PsiParameterStubImpl parameterStub = (PsiParameterStubImpl)getStub(); - if (!parameterStub.isAutoGeneratedName()) { - name = parameterStub.getName(); - } - - if (name == null) { - if (DumbService.getInstance(getProject()).isDumb()) { - return null; - } - - ClsMethodImpl method = (ClsMethodImpl)getDeclarationScope(); - PsiMethod sourceMethod = method.getSourceMirrorMethod(); - if (sourceMethod != null) { - assert sourceMethod != method : method; - name = sourceMethod.getParameterList().getParameters()[getIndex()].getName(); - } - else { - name = getMirrorName(); - } + return CachedValuesManager.getCachedValue(this, new CachedValueProvider() { + @Nullable + @Override + public Result compute() { + return Result.create(calcName(), + getContainingFile(), + getContainingFile().getNavigationElement(), + FileIndexFacade.getInstance(getProject()).getRootModificationTracker()); } + }); + } - myName = name; + @Nullable + private String calcName() { + PsiParameterStubImpl parameterStub = (PsiParameterStubImpl)getStub(); + if (!parameterStub.isAutoGeneratedName()) { + return parameterStub.getName(); + } + + if (DumbService.getInstance(getProject()).isDumb()) { + return null; } - return name; + ClsMethodImpl method = (ClsMethodImpl)getDeclarationScope(); + PsiMethod sourceMethod = method.getSourceMirrorMethod(); + if (sourceMethod != null) { + assert sourceMethod != method : method; + return sourceMethod.getParameterList().getParameters()[getIndex()].getName(); + } + + return getMirrorName(); } public boolean isAutoGeneratedName() { -- 2.32.0