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);
}
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);
}
Aggregations