mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
nullify stub->psi reference when stub-based file is changed, simpler isValid check for stub elements
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user