use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class MultiplePsiFilesPerDocumentFileViewProvider method getPsiInner.
@Override
protected PsiFile getPsiInner(@NotNull final Language target) {
PsiFileImpl file = myRoots.get(target);
if (file == null) {
if (isPhysical()) {
VirtualFile virtualFile = getVirtualFile();
if (isIgnored())
return null;
VirtualFile parent = virtualFile.getParent();
if (parent != null) {
getManager().findDirectory(parent);
}
}
if (target != getBaseLanguage() && !getLanguages().contains(target)) {
return null;
}
file = (PsiFileImpl) createFile(target);
if (file == null)
return null;
if (myOriginal != null) {
final PsiFile originalFile = myOriginal.getPsi(target);
if (originalFile != null) {
file.setOriginalFile(originalFile);
}
}
file = ConcurrencyUtil.cacheOrGet(myRoots, target, file);
}
return file;
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class MultiplePsiFilesPerDocumentFileViewProvider method contentsSynchronized.
@Override
public void contentsSynchronized() {
Set<Language> languages = getLanguages();
for (Iterator<Map.Entry<Language, PsiFileImpl>> iterator = myRoots.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<Language, PsiFileImpl> entry = iterator.next();
if (!languages.contains(entry.getKey())) {
PsiFileImpl file = entry.getValue();
iterator.remove();
file.markInvalidated();
}
}
super.contentsSynchronized();
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PsiDirectoryImpl method add.
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
checkAdd(element);
if (element instanceof PsiFile) {
PsiFile originalFile = (PsiFile) element;
try {
VirtualFile newVFile;
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myManager.getProject());
if (originalFile instanceof PsiFileImpl) {
newVFile = myFile.createChildData(myManager, originalFile.getName());
String text = originalFile.getText();
final PsiFile psiFile = getManager().findFile(newVFile);
final Document document = psiFile == null ? null : psiDocumentManager.getDocument(psiFile);
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
if (document != null) {
document.setText(text);
fileDocumentManager.saveDocument(document);
} else {
String lineSeparator = fileDocumentManager.getLineSeparator(newVFile, getProject());
if (!lineSeparator.equals("\n")) {
text = StringUtil.convertLineSeparators(text, lineSeparator);
}
LoadTextUtil.write(getProject(), newVFile, myManager, text, -1);
}
} else {
byte[] storedContents = ((PsiBinaryFileImpl) originalFile).getStoredContents();
if (storedContents != null) {
newVFile = myFile.createChildData(myManager, originalFile.getName());
newVFile.setBinaryContent(storedContents);
} else {
newVFile = VfsUtilCore.copyFile(null, originalFile.getVirtualFile(), myFile);
}
}
psiDocumentManager.commitAllDocuments();
PsiFile newFile = myManager.findFile(newVFile);
if (newFile == null)
throw new IncorrectOperationException("Could not find file " + newVFile);
updateAddedFile(newFile);
return newFile;
} catch (IOException e) {
throw new IncorrectOperationException(e);
}
}
throw new IncorrectOperationException(element + " (" + element.getClass() + ")");
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class SingleRootFileViewProvider method getKnownTreeRoots.
@NotNull
public List<FileElement> getKnownTreeRoots() {
PsiFile psiFile = getCachedPsi(myBaseLanguage);
if (!(psiFile instanceof PsiFileImpl))
return Collections.emptyList();
FileElement element = ((PsiFileImpl) psiFile).getTreeElement();
return ContainerUtil.createMaybeSingletonList(element);
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class UsageViewTest method testUsageViewDoesNotHoldPsiFilesOrDocuments.
public void testUsageViewDoesNotHoldPsiFilesOrDocuments() throws Exception {
boolean[] foundLeaksBeforeTest = new boolean[1];
LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class, file -> {
if (!file.isPhysical())
return false;
System.err.println("Can't start the test: leaking PsiFiles found:");
foundLeaksBeforeTest[0] = true;
return true;
});
if (foundLeaksBeforeTest[0]) {
fail("Can't start the test: leaking PsiFiles found");
}
PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{} //iuggjhfg");
Usage[] usages = new Usage[100];
for (int i = 0; i < usages.length; i++) {
usages[i] = createUsage(psiFile, i);
}
UsageView usageView = UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, usages, new UsageViewPresentation(), null);
Disposer.register(myFixture.getTestRootDisposable(), usageView);
((EncodingManagerImpl) EncodingManager.getInstance()).clearDocumentQueue();
FileDocumentManager.getInstance().saveAllDocuments();
UIUtil.dispatchAllInvocationEvents();
LeakHunter.checkLeak(usageView, PsiFileImpl.class, PsiFileImpl::isPhysical);
LeakHunter.checkLeak(usageView, Document.class);
}
Aggregations