Search in sources :

Example 36 with LightVirtualFile

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

the class LiveObjectsNode method getNavigatable.

@Override
public Navigatable getNavigatable() {
    if (navigatableCache == null) {
        final VirtualFile virtualFile = new LightVirtualFile(runConfigurationName, new LiveObjectsFileType(), "") {

            @NotNull
            @Override
            public String getPath() {
                return getName();
            }
        };
        virtualFile.putUserData(ProfileData.CONTROLLER, liveModelController);
        virtualFile.putUserData(ProfileData.PROFILING_MANAGER, profilingManager);
        navigatableCache = new OpenFileDescriptor(module.getProject(), virtualFile);
    }
    return navigatableCache;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) LiveObjectsFileType(com.jetbrains.actionscript.profiler.file.LiveObjectsFileType)

Example 37 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project smali by JesusFreke.

the class LightCodeInsightParsingTestCase method doTest.

protected void doTest(boolean checkResult) {
    String name = getTestName(false);
    try {
        String text = loadFile(name + "." + myFileExt);
        PsiFile f = createPsiFile(name, text);
        if (f instanceof PsiFileImpl) {
            // Also want to test stub serialization/deserialization
            StubTree stubTree = ((PsiFileImpl) f).calcStubTree();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            SerializationManagerImpl.getInstanceEx().serialize(stubTree.getRoot(), baos);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            SerializationManagerImpl.getInstanceEx().deserialize(bais);
        }
        ensureParsed(f);
        assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) f.getVirtualFile()).getContent().toString());
        assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(f.getVirtualFile()));
        assertEquals("doc text mismatch", text, f.getViewProvider().getDocument().getText());
        assertEquals("psi text mismatch", text, f.getText());
        if (checkResult) {
            checkResult(name, f);
        } else {
            toParseTreeText(f, skipSpaces(), includeRanges());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (SerializerNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) ByteArrayInputStream(java.io.ByteArrayInputStream) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SerializerNotFoundException(com.intellij.psi.stubs.SerializerNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 38 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project smali by JesusFreke.

the class LightCodeInsightParsingTestCase method createFile.

protected PsiFile createFile(@NonNls String name, String text) {
    LightVirtualFile virtualFile = new LightVirtualFile(name, myLanguage, text);
    virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
    return createFile(virtualFile);
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 39 with LightVirtualFile

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

the class LibraryUtil method getTestGlobalLibrary.

@TestOnly
static // we cannot use LocalFileSystem, because our test can run outside the idea
VirtualFile getTestGlobalLibrary(boolean isPlayer) {
    String name = (isPlayer ? "player" : "air") + "-catalog.xml";
    File file = new File(DebugPathManager.getTestDataPath() + "/lib/playerglobal", name);
    assert file.exists();
    try {
        return new LightVirtualFile(name, XmlFileType.INSTANCE, IOUtil.getCharSequence(file), StandardCharsets.UTF_8, 0);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) TestOnly(org.jetbrains.annotations.TestOnly)

Example 40 with LightVirtualFile

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

the class PerFileMappingsBase method getMappingInner.

@Nullable
protected T getMappingInner(@Nullable VirtualFile file, @Nullable Map<VirtualFile, T> mappings, @Nullable Key<T> pusherKey) {
    if (file instanceof VirtualFileWindow) {
        final VirtualFileWindow window = (VirtualFileWindow) file;
        file = window.getDelegate();
    }
    VirtualFile originalFile = file instanceof LightVirtualFile ? ((LightVirtualFile) file).getOriginalFile() : null;
    if (Comparing.equal(originalFile, file))
        originalFile = null;
    if (file != null) {
        final T pushedValue = pusherKey == null ? null : file.getUserData(pusherKey);
        if (pushedValue != null)
            return pushedValue;
    }
    if (originalFile != null) {
        final T pushedValue = pusherKey == null ? null : originalFile.getUserData(pusherKey);
        if (pushedValue != null)
            return pushedValue;
    }
    if (mappings == null)
        return null;
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (mappings) {
        T t = getMappingForHierarchy(file, mappings);
        if (t != null)
            return t;
        t = getMappingForHierarchy(originalFile, mappings);
        if (t != null)
            return t;
        Project project = getProject();
        if (project == null || file == null || file.getFileSystem() instanceof NonPhysicalFileSystem || ProjectFileIndex.getInstance(project).isInContent(file)) {
            return mappings.get(null);
        }
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

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