Skip to content

Commit

Permalink
cache AbstractHaxeNamedComponent getName
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Oct 30, 2023
1 parent eb8cb0b commit bb53015
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import com.intellij.plugins.haxe.HaxeComponentType;
import com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypes;
import com.intellij.plugins.haxe.lang.psi.*;
import com.intellij.plugins.haxe.model.HaxeBaseMemberModel;
import com.intellij.plugins.haxe.model.HaxeClassModel;
import com.intellij.plugins.haxe.model.HaxeEnumValueModel;
import com.intellij.plugins.haxe.model.HaxeMethodModel;
import com.intellij.plugins.haxe.model.*;
import com.intellij.plugins.haxe.model.type.ResultHolder;
import com.intellij.plugins.haxe.util.HaxeDebugUtil;
import com.intellij.plugins.haxe.util.HaxePresentableUtil;
Expand All @@ -42,6 +39,8 @@
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
Expand All @@ -57,9 +56,6 @@
abstract public class AbstractHaxeNamedComponent extends HaxePsiCompositeElementImpl
implements HaxeNamedComponent, PsiNamedElement {

private String myName;
public ResultHolder _cachedType;
public long _cachedTypeStamp;

public AbstractHaxeNamedComponent(@NotNull ASTNode node) {
super(node);
Expand All @@ -69,16 +65,21 @@ public AbstractHaxeNamedComponent(@NotNull ASTNode node) {
@Nullable
@NonNls
public String getName() {
if (ApplicationManager.getApplication().isReadAccessAllowed()) {
final HaxeComponentName name = getComponentName();
return CachedValuesManager.getProjectPsiDependentCache(this, AbstractHaxeNamedComponent::_getName).getValue();
}

private static CachedValueProvider.Result<String> _getName(AbstractHaxeNamedComponent namedComponent) {
final HaxeComponentName name = namedComponent.getComponentName();
if (name != null) {
myName = name.getText();
return new CachedValueProvider.Result<>(name.getText(), name, namedComponent);
} else {
myName = super.getName();
return new CachedValueProvider.Result<>(namedComponent._getNameFromSuper(), namedComponent);
}
}
return myName;
}
private String _getNameFromSuper() {
return super.getName();
}


@Override
public String getText() {
Expand All @@ -90,7 +91,6 @@ public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperatio
final HaxeComponentName componentName = getComponentName();
if (componentName != null) {
componentName.setName(name);
myName = name;
}
return this;
}
Expand Down

0 comments on commit bb53015

Please sign in to comment.