let stub reference stub tree by default to prevent it being collected (e.g. ClsFileImpl)

This commit is contained in:
peter
2012-03-30 20:27:28 +02:00
parent e4a1bb0b1c
commit 0ea7826d3c
3 changed files with 10 additions and 2 deletions
@@ -684,7 +684,6 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
myStub = new SoftReference<StubTree>(stubHolder);
StubBase<PsiFile> base = (StubBase)stubHolder.getRoot();
base.setPsi(this);
base.putUserData(STUB_TREE_IN_PARSED_TREE, stubHolder); // This will prevent soft reference myStub to be collected before all of the stubs are collected.
return stubHolder;
}
}
@@ -19,6 +19,7 @@
*/
package com.intellij.psi.stubs;
import com.intellij.openapi.util.Key;
import gnu.trove.THashMap;
import gnu.trove.TIntArrayList;
import org.jetbrains.annotations.NotNull;
@@ -29,12 +30,20 @@ import java.util.List;
import java.util.Map;
public class StubTree {
private static final Key<StubTree> STUB_TO_TREE_REFERENCE = Key.create("stub to tree reference");
private final PsiFileStub myRoot;
private final List<StubElement<?>> myPlainList = new ArrayList<StubElement<?>>();
public StubTree(@NotNull final PsiFileStub root) {
this(root, true);
}
public StubTree(@NotNull final PsiFileStub root, final boolean withBackReference) {
myRoot = root;
enumerateStubs(root, myPlainList);
if (withBackReference) {
myRoot.putUserData(STUB_TO_TREE_REFERENCE, this); // This will prevent soft references to stub tree to be collected before all of the stubs are collected.
}
}
private static void enumerateStubs(final StubElement<?> root, final List<StubElement<?>> result) {
@@ -306,7 +306,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi
final Map<StubIndexKey, Map<Object, TIntArrayList>> stubTree;
if (!data.isEmpty()) {
final SerializedStubTree stub = data.values().iterator().next();
stubTree = new StubTree((PsiFileStub)stub.getStub()).indexStubTree();
stubTree = new StubTree((PsiFileStub)stub.getStub(), false).indexStubTree();
}
else {
stubTree = Collections.emptyMap();