mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not keep strong reference to cached psi element
This commit is contained in:
@@ -32,6 +32,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public abstract class SourcePosition implements Navigatable{
|
||||
@NotNull private final PsiFile myFile;
|
||||
private long myModificationStamp = -1L;
|
||||
|
||||
private PsiElement myPsiElement;
|
||||
private WeakReference<PsiElement> myPsiElementRef;
|
||||
private Integer myLine;
|
||||
private Integer myOffset;
|
||||
|
||||
@@ -120,7 +121,7 @@ public abstract class SourcePosition implements Navigatable{
|
||||
myModificationStamp = myFile.getModificationStamp();
|
||||
myLine = null;
|
||||
myOffset = null;
|
||||
myPsiElement = null;
|
||||
myPsiElementRef = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ public abstract class SourcePosition implements Navigatable{
|
||||
if (myModificationStamp != myFile.getModificationStamp()) {
|
||||
return true;
|
||||
}
|
||||
final PsiElement psiElement = myPsiElement;
|
||||
final PsiElement psiElement = myPsiElementRef != null ? myPsiElementRef.get() : null;
|
||||
return psiElement != null && !ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
@@ -158,10 +159,13 @@ public abstract class SourcePosition implements Navigatable{
|
||||
@Override
|
||||
public PsiElement getElementAt() {
|
||||
updateData();
|
||||
if (myPsiElement == null) {
|
||||
myPsiElement = calcPsiElement();
|
||||
PsiElement element = myPsiElementRef != null ? myPsiElementRef.get() : null;
|
||||
if (element == null) {
|
||||
element = calcPsiElement();
|
||||
myPsiElementRef = new WeakReference<PsiElement>(element);
|
||||
return element;
|
||||
}
|
||||
return myPsiElement;
|
||||
return element;
|
||||
}
|
||||
|
||||
protected int calcLine() {
|
||||
|
||||
Reference in New Issue
Block a user