Search in sources :

Example 21 with LightVirtualFile

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;
    }
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) FileType(com.intellij.openapi.fileTypes.FileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with LightVirtualFile

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;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with LightVirtualFile

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 24 with LightVirtualFile

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);
    }
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with LightVirtualFile

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) FileStatusManagerImpl(com.intellij.openapi.vcs.impl.FileStatusManagerImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Aggregations

LightVirtualFile (com.intellij.testFramework.LightVirtualFile)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 NotNull (org.jetbrains.annotations.NotNull)10 Nullable (org.jetbrains.annotations.Nullable)10 IpnbFile (org.jetbrains.plugins.ipnb.format.IpnbFile)7 Document (com.intellij.openapi.editor.Document)6 FileElement (com.intellij.psi.impl.source.tree.FileElement)6 FileType (com.intellij.openapi.fileTypes.FileType)5 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)5 FileManager (com.intellij.psi.impl.file.impl.FileManager)5 Project (com.intellij.openapi.project.Project)4 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)4 Language (com.intellij.lang.Language)3 FileViewProvider (com.intellij.psi.FileViewProvider)3 PsiFile (com.intellij.psi.PsiFile)3 PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)3 File (java.io.File)3 IpnbCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCell)3 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)2 MockDocument (com.intellij.mock.MockDocument)2