anchor-based smart pointers: restore correctly when anchor is the element itself

This commit is contained in:
peter
2015-09-15 18:45:05 +02:00
parent 2e3cd6809e
commit de752703c6
2 changed files with 21 additions and 1 deletions
@@ -814,4 +814,24 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
assertNotNull(pointer.getElement());
}
public void testNonAnchoredStubbedElement() {
PsiFile file = configureByText(JavaFileType.INSTANCE, "class Foo { { @NotNull String foo; } }");
StubTree stubTree = ((PsiFileImpl)file).getStubTree();
assertNotNull(stubTree);
PsiElement anno = stubTree.getPlainList().stream().map(element -> element.getPsi()).filter(psiElement -> psiElement instanceof PsiAnnotation).findFirst().get();
SmartPsiElementPointer<PsiElement> pointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(anno);
assertNotNull(((PsiFileImpl)file).getStubTree());
stubTree = null;
anno = null;
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertNull(((SmartPointerEx) pointer).getCachedElement());
file.getViewProvider().getDocument().insertString(0, " ");
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
assertNotNull(pointer.getElement());
}
}