use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method testNoAstLoadingWithoutDocumentChanges.
public void testNoAstLoadingWithoutDocumentChanges() {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
assertNotNull(aClass);
PsiFileImpl file = (PsiFileImpl) aClass.getContainingFile();
createEditor(file.getVirtualFile());
assertFalse(file.isContentsLoaded());
SmartPointerEx pointer = (SmartPointerEx) createPointer(aClass);
assertFalse(file.isContentsLoaded());
//noinspection UnusedAssignment
aClass = null;
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertNull(pointer.getCachedElement());
assertNotNull(pointer.getElement());
assertFalse(file.isContentsLoaded());
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method testNonAnchoredStubbedElement.
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(StubElement::getPsi).filter(psiElement -> psiElement instanceof PsiAnnotation).findFirst().get();
SmartPsiElementPointer<PsiElement> pointer = createPointer(anno);
assertNotNull(((PsiFileImpl) file).getStubTree());
stubTree = null;
anno = null;
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertNull(((SmartPointerEx) pointer).getCachedElement());
insertString(file.getViewProvider().getDocument(), 0, " ");
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
assertNotNull(pointer.getElement());
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class ClsFileImpl method getMirror.
@Override
public PsiElement getMirror() {
TreeElement mirrorTreeElement = SoftReference.dereference(myMirrorFileElement);
if (mirrorTreeElement == null) {
synchronized (myMirrorLock) {
mirrorTreeElement = SoftReference.dereference(myMirrorFileElement);
if (mirrorTreeElement == null) {
VirtualFile file = getVirtualFile();
PsiClass[] classes = getClasses();
String fileName = (classes.length > 0 ? classes[0].getName() : file.getNameWithoutExtension()) + JavaFileType.DOT_DEFAULT_EXTENSION;
final Document document = FileDocumentManager.getInstance().getDocument(file);
assert document != null : file.getUrl();
CharSequence mirrorText = document.getImmutableCharSequence();
boolean internalDecompiler = StringUtil.startsWith(mirrorText, BANNER);
PsiFileFactory factory = PsiFileFactory.getInstance(getManager().getProject());
PsiFile mirror = factory.createFileFromText(fileName, JavaLanguage.INSTANCE, mirrorText, false, false);
mirror.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, getLanguageLevel());
mirrorTreeElement = SourceTreeToPsiMap.psiToTreeNotNull(mirror);
try {
final TreeElement finalMirrorTreeElement = mirrorTreeElement;
ProgressManager.getInstance().executeNonCancelableSection(() -> {
setMirror(finalMirrorTreeElement);
putUserData(CLS_DOCUMENT_LINK_KEY, document);
});
} catch (InvalidMirrorException e) {
//noinspection ThrowableResultOfMethodCallIgnored
LOG.error(file.getUrl(), internalDecompiler ? e : wrapException(e, file));
}
((PsiFileImpl) mirror).setOriginalFile(this);
myMirrorFileElement = new SoftReference<>(mirrorTreeElement);
}
}
}
return mirrorTreeElement.getPsi();
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class MultiplePsiFilesPerDocumentFileViewProvider method checkAllTreesEqual.
@TestOnly
public void checkAllTreesEqual() {
Collection<PsiFileImpl> roots = myRoots.values();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getManager().getProject());
documentManager.commitAllDocuments();
for (PsiFile root : roots) {
Document document = documentManager.getDocument(root);
PsiDocumentManagerBase.checkConsistency(root, document);
assert root.getText().equals(document.getText());
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PsiAnchor method calcStubIndex.
public static int calcStubIndex(@NotNull StubBasedPsiElement psi) {
if (psi instanceof PsiFile) {
return 0;
}
final StubElement liveStub = psi.getStub();
if (liveStub != null) {
return ((StubBase) liveStub).id;
}
PsiFileImpl file = (PsiFileImpl) psi.getContainingFile();
final StubTree stubTree = file.calcStubTree();
for (StubElement<?> stb : stubTree.getPlainList()) {
if (stb.getPsi() == psi) {
return ((StubBase) stb).id;
}
}
// it is possible via custom stub builder intentionally not producing stubs for stubbed elements
return -1;
}
Aggregations