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.*;
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.*;
@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<String>() {
+ @Nullable
+ @Override
+ public Result<String> 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() {