Search in sources :

Example 81 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project kotlin by JetBrains.

the class KotlinTestUtils method createFile.

@NotNull
public static KtFile createFile(@NotNull @NonNls final String name, @NotNull String text, @NotNull Project project) {
    String shortName = name.substring(name.lastIndexOf('/') + 1);
    shortName = shortName.substring(shortName.lastIndexOf('\\') + 1);
    LightVirtualFile virtualFile = new LightVirtualFile(shortName, KotlinLanguage.INSTANCE, text) {

        @NotNull
        @Override
        public String getPath() {
            //TODO: patch LightVirtualFile
            return "/" + name;
        }
    };
    virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
    PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
    //noinspection ConstantConditions
    return (KtFile) factory.trySetupPsiForFile(virtualFile, KotlinLanguage.INSTANCE, true, false);
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 82 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project kotlin by JetBrains.

the class KtParsingTestCase 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 83 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project kotlin by JetBrains.

the class TestCheckerUtil method createCheckAndReturnPsiFile.

@NotNull
public static KtFile createCheckAndReturnPsiFile(@NotNull String fileName, @NotNull String text, @NotNull Project project) {
    KtFile myFile = KotlinTestUtils.createFile(fileName, text, project);
    ensureParsed(myFile);
    TestCase.assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) myFile.getVirtualFile()).getContent().toString());
    TestCase.assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
    //noinspection ConstantConditions
    TestCase.assertEquals("doc text mismatch", text, myFile.getViewProvider().getDocument().getText());
    TestCase.assertEquals("psi text mismatch", text, myFile.getText());
    return myFile;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with LightVirtualFile

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

the class PythonConsoleParsingTest method createFile.

@Override
protected PsiFile createFile(String name, String text) {
    LightVirtualFile originalFile = new LightVirtualFile(name, myLanguage, text);
    LightVirtualFile virtualFile = new LightVirtualFile(name, myLanguage, text);
    virtualFile.setOriginalFile(originalFile);
    originalFile.setCharset(CharsetToolkit.UTF8_CHARSET);
    originalFile.putUserData(LanguageLevel.KEY, myLanguageLevel);
    PyConsoleUtil.markIPython(originalFile);
    return createFile(virtualFile);
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 85 with LightVirtualFile

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

the class CellOperationTest method testAddCell.

public void testAddCell() throws IOException {
    final String fileName = "testData/emptyFile.ipynb";
    final String fileText = IpnbTestCase.getFileText(fileName);
    final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
    ipnbFile.addCell(IpnbCodeCell.createEmptyCodeCell(), ipnbFile.getCells().size());
    final IpnbCodeCell cell = (IpnbCodeCell) ipnbFile.getCells().get(ipnbFile.getCells().size() - 1);
    assertTrue(cell.getCellOutputs().isEmpty());
    assertNull(cell.getPromptNumber());
    assertTrue(cell.getMetadata().isEmpty());
}
Also used : IpnbCodeCell(org.jetbrains.plugins.ipnb.format.cells.IpnbCodeCell) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) IpnbFile(org.jetbrains.plugins.ipnb.format.IpnbFile)

Aggregations

LightVirtualFile (com.intellij.testFramework.LightVirtualFile)102 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 NotNull (org.jetbrains.annotations.NotNull)14 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)13 Nullable (org.jetbrains.annotations.Nullable)13 PsiFile (com.intellij.psi.PsiFile)12 Project (com.intellij.openapi.project.Project)11 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)8 FileType (com.intellij.openapi.fileTypes.FileType)8 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)7 FileManager (com.intellij.psi.impl.file.impl.FileManager)7 IpnbFile (org.jetbrains.plugins.ipnb.format.IpnbFile)7 BlobExplorerFileEditor (com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor)6 QueueFileEditor (com.microsoft.intellij.helpers.storage.QueueFileEditor)6 TableFileEditor (com.microsoft.intellij.helpers.storage.TableFileEditor)6 Language (com.intellij.lang.Language)5 PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)5 FileElement (com.intellij.psi.impl.source.tree.FileElement)5 FileViewProvider (com.intellij.psi.FileViewProvider)4