don't create new AstPath-s during switching to strong refs (EA-91128 - assert: PsiFileImpl.associateAstPathWithPsi)

This commit is contained in:
peter
2016-11-04 09:15:27 +01:00
parent 138e49f8ed
commit d992b4b1a8
@@ -74,7 +74,6 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
private boolean myInvalidated;
private volatile boolean myAstLoaded;
private volatile boolean myUseStrongRefs;
private volatile boolean mySwitchingToStrongRefs;
private AstPathPsiMap myRefToPsi;
private final ThreadLocal<FileElement> myFileElementBeingLoaded = new ThreadLocal<FileElement>();
protected final PsiManagerEx myManager;
@@ -277,7 +276,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
StubBasedPsiElementBase psi = pair.first;
AstPath path = pair.second;
path.getNode().setPsi(psi);
associateAstPathWithPsi(path, psi);
myRefToPsi.cachePsi(path, psi);
psi.setStubIndex(i + 1);
}
}
@@ -1132,8 +1131,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
public final void beforeAstChange() {
if (!useStrongRefs()) {
LOG.assertTrue(!mySwitchingToStrongRefs);
mySwitchingToStrongRefs = true;
myUseStrongRefs = true;
myRefToPsi.switchToStrongRefs();
FileElement element = getTreeElement();
@@ -1142,9 +1140,6 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
} else {
LOG.error("No AST; " + derefStub() + "; " + this + " of " + getClass() + "; " + getViewProvider() + " of " + getViewProvider().getClass());
}
myUseStrongRefs = true;
mySwitchingToStrongRefs = false;
}
}
@@ -1159,16 +1154,10 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
synchronized (PsiLock.LOCK) {
psi = myRefToPsi.getCachedPsi(path);
return psi != null ? psi : associateAstPathWithPsi(path, creator.create());
return psi != null ? psi : myRefToPsi.cachePsi(path, creator.create());
}
}
@NotNull
private StubBasedPsiElementBase<?> associateAstPathWithPsi(@NotNull AstPath path, @NotNull StubBasedPsiElementBase<?> psi) {
LOG.assertTrue(!mySwitchingToStrongRefs);
return myRefToPsi.cachePsi(path, psi);
}
final AstPathPsiMap getRefToPsi() {
return myRefToPsi;
}