Search in sources :

Example 1 with PsiBinaryFile

use of com.intellij.psi.PsiBinaryFile in project intellij-community by JetBrains.

the class FileTypesTest method testAutoDetectEmptyFile.

public void testAutoDetectEmptyFile() throws IOException {
    File dir = createTempDirectory();
    File file = FileUtil.createTempFile(dir, "x", "xxx_xx_xx", true);
    VirtualFile virtualFile = getVirtualFile(file);
    assertNotNull(virtualFile);
    assertEquals(FileTypes.UNKNOWN, virtualFile.getFileType());
    PsiFile psi = getPsiManager().findFile(virtualFile);
    assertTrue(psi instanceof PsiBinaryFile);
    assertEquals(FileTypes.UNKNOWN, virtualFile.getFileType());
    setBinaryContent(virtualFile, "xxxxxxx".getBytes(CharsetToolkit.UTF8_CHARSET));
    assertEquals(FileTypes.PLAIN_TEXT, virtualFile.getFileType());
    PsiFile after = getPsiManager().findFile(virtualFile);
    assertNotSame(psi, after);
    assertFalse(psi.isValid());
    assertTrue(after.isValid());
    assertTrue(after instanceof PsiPlainTextFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiPlainTextFile(com.intellij.psi.PsiPlainTextFile) PsiFile(com.intellij.psi.PsiFile) PsiBinaryFile(com.intellij.psi.PsiBinaryFile) File(java.io.File) PsiBinaryFile(com.intellij.psi.PsiBinaryFile) PsiPlainTextFile(com.intellij.psi.PsiPlainTextFile)

Example 2 with PsiBinaryFile

use of com.intellij.psi.PsiBinaryFile in project intellij-community by JetBrains.

the class FindInProjectTask method findFile.

private Pair.NonNull<PsiFile, VirtualFile> findFile(@NotNull final VirtualFile virtualFile) {
    PsiFile psiFile = myPsiManager.findFile(virtualFile);
    if (psiFile != null && !(psiFile instanceof PsiBinaryFile)) {
        PsiFile sourceFile = (PsiFile) psiFile.getNavigationElement();
        if (sourceFile != null)
            psiFile = sourceFile;
        if (psiFile.getFileType().isBinary()) {
            psiFile = null;
        }
    }
    VirtualFile sourceVirtualFile = PsiUtilCore.getVirtualFile(psiFile);
    if (psiFile == null || psiFile.getFileType().isBinary() || sourceVirtualFile == null) {
        return null;
    }
    return Pair.createNonNull(psiFile, sourceVirtualFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) PsiBinaryFile(com.intellij.psi.PsiBinaryFile)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiBinaryFile (com.intellij.psi.PsiBinaryFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiPlainTextFile (com.intellij.psi.PsiPlainTextFile)1 File (java.io.File)1