use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class BlockSupportImpl method makeFullParse.
@NotNull
private static DiffLog makeFullParse(@NotNull PsiFileImpl fileImpl, @NotNull FileASTNode oldFileNode, @NotNull CharSequence newFileText, @NotNull ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) {
if (fileImpl instanceof PsiCodeFragment) {
FileElement parent = fileImpl.getTreeElement();
final FileElement holderElement = new DummyHolder(fileImpl.getManager(), fileImpl.getContext()).getTreeElement();
holderElement.rawAddChildren(fileImpl.createContentLeafElement(holderElement.getCharTable().intern(newFileText, 0, newFileText.length())));
DiffLog diffLog = new DiffLog();
diffLog.appendReplaceFileElement(parent, (FileElement) holderElement.getFirstChildNode());
return diffLog;
} else {
FileViewProvider viewProvider = fileImpl.getViewProvider();
viewProvider.getLanguages();
FileType fileType = viewProvider.getVirtualFile().getFileType();
String fileName = fileImpl.getName();
final LightVirtualFile lightFile = new LightVirtualFile(fileName, fileType, newFileText, viewProvider.getVirtualFile().getCharset(), fileImpl.getViewProvider().getModificationStamp());
lightFile.setOriginalFile(viewProvider.getVirtualFile());
FileViewProvider copy = viewProvider.createCopy(lightFile);
if (copy.isEventSystemEnabled()) {
throw new AssertionError("Copied view provider must be non-physical for reparse to deliver correct events: " + viewProvider);
}
copy.getLanguages();
// optimization: do not convert file contents to bytes to determine if we should codeinsight it
SingleRootFileViewProvider.doNotCheckFileSizeLimit(lightFile);
PsiFileImpl newFile = getFileCopy(fileImpl, copy);
newFile.setOriginalFile(fileImpl);
final FileElement newFileElement = (FileElement) newFile.getNode();
final FileElement oldFileElement = (FileElement) oldFileNode;
if (!lastCommittedText.toString().equals(oldFileElement.getText())) {
throw new IncorrectOperationException(viewProvider.toString());
}
DiffLog diffLog = mergeTrees(fileImpl, oldFileElement, newFileElement, indicator, lastCommittedText);
((PsiManagerEx) fileImpl.getManager()).getFileManager().setViewProvider(lightFile, null);
return diffLog;
}
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class LightVirtualFileLeaksTest method createLightFile.
@NotNull
private LightVirtualFile createLightFile() {
LightVirtualFile vFile = new LightVirtualFile(getName() + ".java", JavaFileType.INSTANCE, "class Foo {}");
vFile.putUserData(myKey, Boolean.TRUE);
return vFile;
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class SingleRootFileViewProvider method clone.
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public FileViewProvider clone() {
final VirtualFile origFile = getVirtualFile();
LightVirtualFile copy = new LightVirtualFile(origFile.getName(), myFileType, getContents(), origFile.getCharset(), getModificationStamp());
copy.setOriginalFile(origFile);
copy.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
copy.setCharset(origFile.getCharset());
return createCopy(copy);
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class PsiDirectoryImpl method copyFileFrom.
@Override
@NotNull
public PsiFile copyFileFrom(@NotNull String newName, @NotNull PsiFile originalFile) throws IncorrectOperationException {
checkCreateFile(newName);
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(originalFile);
if (document != null) {
FileDocumentManager.getInstance().saveDocument(document);
}
final VirtualFile parent = getVirtualFile();
try {
final VirtualFile vFile = originalFile.getVirtualFile();
if (vFile == null)
throw new IncorrectOperationException("Cannot copy non-physical file: " + originalFile);
VirtualFile copyVFile;
if (parent.getFileSystem() == vFile.getFileSystem()) {
copyVFile = vFile.copy(this, parent, newName);
} else if (vFile instanceof LightVirtualFile) {
copyVFile = parent.createChildData(this, newName);
copyVFile.setBinaryContent(originalFile.getText().getBytes(copyVFile.getCharset()));
} else {
copyVFile = VfsUtilCore.copyFile(this, vFile, parent, newName);
}
if (copyVFile == null)
throw new IncorrectOperationException("File was not copied: " + vFile);
DumbService.getInstance(getProject()).completeJustSubmittedTasks();
final PsiFile copyPsi = myManager.findFile(copyVFile);
if (copyPsi == null)
throw new IncorrectOperationException("Could not find file " + copyVFile + " after copying " + vFile);
updateAddedFile(copyPsi);
return copyPsi;
} catch (IOException e) {
throw new IncorrectOperationException(e);
}
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class EditorChangeAction method refreshFileStatus.
private void refreshFileStatus() {
VirtualFile f = getAffectedDocuments()[0].getFile();
if (f == null || f instanceof LightVirtualFile)
return;
for (Project each : ProjectManager.getInstance().getOpenProjects()) {
FileStatusManagerImpl statusManager = (FileStatusManagerImpl) FileStatusManager.getInstance(each);
statusManager.refreshFileStatusFromDocument(f, getDocument());
}
}
Aggregations