nullify stub->psi reference when stub-based file is changed, simpler isValid check for stub elements

This commit is contained in:
peter
2012-04-02 20:54:08 +02:00
parent 18391c509f
commit d85a101ade
2 changed files with 13 additions and 19 deletions
@@ -154,11 +154,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
public boolean isValid() {
T stub = myStub;
if (stub != null) {
PsiElement parentPsi = stub.getParentStub().getPsi();
if (parentPsi instanceof PsiFileImpl) {
return ((PsiFileImpl) parentPsi).isStubBasedChildValid(this);
}
return parentPsi.isValid();
PsiElement psi = stub.getParentStub().getPsi();
return psi != null && psi.isValid();
}
return super.isValid();
@@ -220,7 +220,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
stubs.next(); // Skip file stub;
switchFromStubToAST(treeElement, stubs);
myStub = null;
clearStub();
}
setTreeElement(treeElement);
@@ -249,17 +249,6 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
return findTreeForStub(ast, stubs, stub);
}
public boolean isStubBasedChildValid(@NotNull StubBasedPsiElementBase child) {
synchronized (myStubLock) {
StubTree fileStub = derefStub();
StubElement childStub = child.getStub();
if (childStub != null && (fileStub == null || fileStub.getRoot() != childStub.getParentStub())) {
return false;
}
}
return isValid();
}
@Nullable
private static ASTNode findTreeForStub(ASTNode tree, final Iterator<StubElement<?>> stubs, final StubElement stub) {
final IElementType type = tree.getElementType();
@@ -352,10 +341,18 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
myViewProvider.beforeContentsSynchronized();
setTreeElement(null);
synchronized (myStubLock) {
myStub = null;
clearStub();
}
}
private void clearStub() {
StubTree stubHolder = myStub == null ? null : myStub.get();
if (stubHolder != null) {
((StubBase<?>)stubHolder.getRoot()).setPsi(null);
}
myStub = null;
}
public void clearCaches() {}
@Override
@@ -404,7 +401,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
}
synchronized (myStubLock) {
myStub = null;
clearStub();
if (tree != null) {
tree.putUserData(STUB_TREE_IN_PARSED_TREE, null);
}