Search in sources :

Example 41 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class PsiViewerDialog method updateEditor.

private void updateEditor() {
    final Object source = getSource();
    final String fileName = "Dummy." + (source instanceof FileType ? ((FileType) source).getDefaultExtension() : "txt");
    final LightVirtualFile lightFile;
    if (source instanceof PsiViewerExtension) {
        lightFile = new LightVirtualFile(fileName, ((PsiViewerExtension) source).getDefaultFileType(), "");
    } else if (source instanceof LanguageFileType) {
        lightFile = new LightVirtualFile(fileName, ObjectUtils.chooseNotNull((Language) myDialectComboBox.getSelectedItem(), ((LanguageFileType) source).getLanguage()), "");
    } else if (source instanceof FileType) {
        lightFile = new LightVirtualFile(fileName, (FileType) source, "");
    } else {
        return;
    }
    EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, lightFile);
    try {
        myEditor.setHighlighter(highlighter);
    } catch (Throwable e) {
        LOG.warn(e);
    }
}
Also used : Language(com.intellij.lang.Language) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 42 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class BinaryContent method getFile.

@Override
@Nullable
public VirtualFile getFile() {
    if (myFileType instanceof UIBasedFileType) {
        final VirtualFile file = findVirtualFile();
        if (file != null) {
            final LightVirtualFile lightFile = new LightVirtualFile(file, new String(myBytes), 1);
            lightFile.setOriginalFile(file);
            return lightFile;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class TemplateDataElementType method createPsiFileFromSource.

protected PsiFile createPsiFileFromSource(final Language language, CharSequence sourceCode, PsiManager manager) {
    @NonNls final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), sourceCode, LocalTimeCounter.currentTime());
    FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {

        @Override
        @NotNull
        public Language getBaseLanguage() {
            return language;
        }
    };
    // Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason), 
    // there should also be no file size checks for template data files.
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
    return viewProvider.getPsi(language);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) FileViewProvider(com.intellij.psi.FileViewProvider) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider)

Example 44 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class LoadTextUtilTest method doTest.

private static void doTest(String source, String expected, String expectedSeparator) {
    final LightVirtualFile vFile = new LightVirtualFile("test.txt");
    final CharSequence real = LoadTextUtil.getTextByBinaryPresentation(source.getBytes(), vFile);
    assertTrue("content", Comparing.equal(expected, real));
    if (expectedSeparator != null) {
        assertEquals("detected line separator", expectedSeparator, FileDocumentManager.getInstance().getLineSeparator(vFile, null));
    }
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 45 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class ReadonlyStatusHandlerImpl method ensureFilesWritable.

@Override
public OperationStatus ensureFilesWritable(@NotNull VirtualFile... files) {
    if (files.length == 0) {
        return new OperationStatusImpl(VirtualFile.EMPTY_ARRAY);
    }
    checkThreading();
    Set<VirtualFile> realFiles = new THashSet<>(files.length);
    for (VirtualFile file : files) {
        if (file instanceof LightVirtualFile) {
            VirtualFile originalFile = ((LightVirtualFile) file).getOriginalFile();
            if (originalFile != null) {
                file = originalFile;
            }
        }
        if (file instanceof VirtualFileWindow)
            file = ((VirtualFileWindow) file).getDelegate();
        if (file != null) {
            realFiles.add(file);
        }
    }
    files = VfsUtilCore.toVirtualFileArray(realFiles);
    for (final WritingAccessProvider accessProvider : myAccessProviders) {
        Collection<VirtualFile> denied = ContainerUtil.filter(files, virtualFile -> !accessProvider.isPotentiallyWritable(virtualFile));
        if (denied.isEmpty()) {
            denied = accessProvider.requestWriting(files);
        }
        if (!denied.isEmpty()) {
            return new OperationStatusImpl(VfsUtilCore.toVirtualFileArray(denied));
        }
    }
    final FileInfo[] fileInfos = createFileInfos(files);
    if (fileInfos.length == 0) {
        // if all files are already writable
        return createResultStatus(files);
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        if (myClearReadOnlyInTests) {
            processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
        }
        return createResultStatus(files);
    }
    // This event count hack is necessary to allow actions that called this stuff could still get data from their data contexts.
    // Otherwise data manager stuff will fire up an assertion saying that event count has been changed (due to modal dialog show-up)
    // The hack itself is safe since we guarantee that focus will return to the same component had it before modal dialog have been shown.
    final int savedEventCount = IdeEventQueue.getInstance().getEventCount();
    if (myState.SHOW_DIALOG) {
        new ReadOnlyStatusDialog(myProject, fileInfos).show();
    } else {
        // the collection passed is modified
        processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
    }
    IdeEventQueue.getInstance().setEventCount(savedEventCount);
    return createResultStatus(files);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) THashSet(gnu.trove.THashSet) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) WritingAccessProvider(com.intellij.openapi.vfs.WritingAccessProvider)

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