public static <T extends PsiElement> T assertResolveResult(PsiElement element, Class<T> aClass, String name, @Nullable String containingFilePath) { assertInstanceOf(element, aClass); assertEquals(name, ((PsiNamedElement) element).getName()); if (containingFilePath != null) { VirtualFile virtualFile = element.getContainingFile().getVirtualFile(); if (virtualFile.getFileSystem() instanceof TempFileSystem) { assertEquals(containingFilePath, virtualFile.getPath()); } else { assertEquals(containingFilePath, virtualFile.getName()); } } return (T)element; }
@Override @Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) return null; if (!file.isPhysical()) return null; if (file.getViewProvider().getBaseLanguage() != file.getLanguage()) return null; VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) return null; if (virtualFile.getFileSystem() != LocalFileSystem.getInstance() // tests && virtualFile.getFileSystem() != TempFileSystem.getInstance()) return null; String text = file.getText(); Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text); // no sense in checking transparently decoded file: all characters there are already safely encoded if (charset instanceof Native2AsciiCharset) return null; List<ProblemDescriptor> descriptors = new SmartList<ProblemDescriptor>(); boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, text, virtualFile, charset, descriptors); if (ok) { checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors); } return descriptors.toArray(new ProblemDescriptor[descriptors.size()]); }
public static boolean isWriteAccessAllowed(@Nonnull VirtualFile file, @Nonnull Project project) { if (isAllAccessAllowed()) return true; if (file.isDirectory()) return true; if (!(file.getFileSystem() instanceof LocalFileSystem)) return true; // do not block e.g., HttpFileSystem, LightFileSystem etc. if (file.getFileSystem() instanceof TempFileSystem) return true; if (ArrayUtil.contains(file, IdeDocumentHistory.getInstance(project).getChangedFiles())) return true; if (!getApp().isUnitTestMode() && FileUtil.isAncestor(new File(FileUtil.getTempDirectory()), VfsUtilCore.virtualToIoFile(file), true)) { return true; } VirtualFile each = file; while (each != null) { if (ACCESS_ALLOWED.getValue(each).get() > 0) return true; each = each.getParent(); } return isProjectFile(file, project); }
@Nullable private static VirtualFile getByFullPath(String filePath) { final VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(filePath); if (fileByPath != null) { return fileByPath; } // if we are in UnitTest mode probably TempFileSystem is used instead of LocalFileSystem if (ApplicationManager.getApplication().isUnitTestMode()) { return TempFileSystem.getInstance().findFileByPath(filePath); } return null; }
@SuppressWarnings("UnsafeVfsRecursion") public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, @Nullable VirtualFileFilter fileFilter) throws IOException { FileDocumentManager.getInstance().saveAllDocuments(); VirtualFile[] childrenAfter = dirAfter.getChildren(); if (dirAfter.isInLocalFileSystem() && dirAfter.getFileSystem() != TempFileSystem.getInstance()) { File[] ioAfter = new File(dirAfter.getPath()).listFiles(); shallowCompare(childrenAfter, ioAfter); } VirtualFile[] childrenBefore = dirBefore.getChildren(); if (dirBefore.isInLocalFileSystem() && dirBefore.getFileSystem() != TempFileSystem.getInstance()) { File[] ioBefore = new File(dirBefore.getPath()).listFiles(); shallowCompare(childrenBefore, ioBefore); } HashMap<String, VirtualFile> mapAfter = buildNameToFileMap(childrenAfter, fileFilter); HashMap<String, VirtualFile> mapBefore = buildNameToFileMap(childrenBefore, fileFilter); Set<String> keySetAfter = mapAfter.keySet(); Set<String> keySetBefore = mapBefore.keySet(); assertEquals(dirAfter.getPath(), keySetAfter, keySetBefore); for (String name : keySetAfter) { VirtualFile fileAfter = mapAfter.get(name); VirtualFile fileBefore = mapBefore.get(name); if (fileAfter.isDirectory()) { assertDirectoriesEqual(fileAfter, fileBefore, fileFilter); } else { assertFilesEqual(fileAfter, fileBefore); } } }
private void cleanSourceRoot(@NotNull VirtualFile contentRoot) throws IOException { TempFileSystem tempFs = (TempFileSystem)contentRoot.getFileSystem(); for (VirtualFile child : contentRoot.getChildren()) { if (!tempFs.exists(child)) { tempFs.createChildFile(this, contentRoot, child.getName()); } child.delete(this); } }
@Override @NotNull public VirtualFile[] getLocalRoots() { List<VirtualFile> roots = ContainerUtil.newSmartList(); for (NewVirtualFile root : myRoots.values()) { if (root.isInLocalFileSystem() && !(root.getFileSystem() instanceof TempFileSystem)) { roots.add(root); } } return VfsUtilCore.toVirtualFileArray(roots); }
VirtualFilePointerManagerImpl(@NotNull VirtualFileManager virtualFileManager, @NotNull MessageBus bus, @NotNull TempFileSystem tempFileSystem, @NotNull LocalFileSystem localFileSystem, @NotNull JarFileSystem jarFileSystem) { myVirtualFileManager = virtualFileManager; myBus = bus; bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this); TEMP_FILE_SYSTEM = tempFileSystem; LOCAL_FILE_SYSTEM = localFileSystem; JAR_FILE_SYSTEM = jarFileSystem; }
public void testLocalRoots() { VirtualFile tempRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///"); assertNotNull(tempRoot); VirtualFile[] roots = myFs.getLocalRoots(); for (VirtualFile root : roots) { assertTrue("root=" + root, root.isInLocalFileSystem()); VirtualFileSystem fs = root.getFileSystem(); assertTrue("fs=" + fs, fs instanceof LocalFileSystem); assertFalse("fs=" + fs, fs instanceof TempFileSystem); } }
public void testMultipleCreationOfTheSamePointerPerformance() throws IOException { final LoggingListener listener = new LoggingListener(); final String url = VfsUtilCore.pathToUrl("/a/b/c/d/e"); final VirtualFilePointer thePointer = myVirtualFilePointerManager.create(url, disposable, listener); TempFileSystem.getInstance(); PlatformTestUtil.startPerformanceTest("same url vfp create", 5000, new ThrowableRunnable() { @Override public void run() throws Throwable { for (int i=0; i<10000000; i++) { VirtualFilePointer pointer = myVirtualFilePointerManager.create(url, disposable, listener); assertSame(pointer, thePointer); } } }).assertTiming(); }
public VirtualFile findFile(String filePath) { VirtualFile vf = TempFileSystem.getInstance().findFileByPath(filePath); if (vf == null) { // this might be a relative path filePath = makePathRelativeToTestFixture(filePath); vf = tempDirTestFixture.getFile(filePath); } return vf; }
public void testMultipleCreationOfTheSamePointerPerformance() throws IOException { FilePointerPartNode.pushDebug(false, disposable); final LoggingListener listener = new LoggingListener(); final VirtualFilePointer thePointer = myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/e"), disposable, listener); TempFileSystem.getInstance(); PlatformTestUtil.startPerformanceTest("same url vfp create", 500, new ThrowableRunnable() { @Override public void run() throws Throwable { for (int i=0; i<1000000; i++) { VirtualFilePointer pointer = myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/e"), disposable, listener); assertSame(pointer, thePointer); } } }).assertTiming(); }
@Override public FileBasedIndex.InputFilter getInputFilter() { return new DefaultFileTypeSpecificInputFilter(ImageFileTypeManager.getInstance().getImageFileType()) { @Override public boolean acceptInput(final VirtualFile file) { return (file.getFileSystem() == LocalFileSystem.getInstance() || file.getFileSystem() instanceof TempFileSystem) && (file.getLength() / 1024) < ourMaxImageSize ; } }; }
@Override public FileBasedIndex.InputFilter getInputFilter() { return new DefaultFileTypeSpecificInputFilter(StdFileTypes.HTML, StdFileTypes.XHTML) { @Override public boolean acceptInput(final VirtualFile file) { if (file.getFileSystem() != LocalFileSystem.getInstance() && !(file.getFileSystem() instanceof TempFileSystem)) { return false; } return true; } }; }
public void testMultipleCreationOfTheSamePointerPerformance() throws IOException { final LoggingListener listener = new LoggingListener(); final VirtualFilePointer thePointer = myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/e"), disposable, listener); TempFileSystem.getInstance(); PlatformTestUtil.startPerformanceTest("same url vfp create", 500, new ThrowableRunnable() { @Override public void run() throws Throwable { for (int i=0; i<1000000; i++) { VirtualFilePointer pointer = myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/e"), disposable, listener); assertSame(pointer, thePointer); } } }).assertTiming(); }
@Override @Nonnull public VirtualFile[] getLocalRoots() { List<VirtualFile> roots = ContainerUtil.newSmartList(); for (NewVirtualFile root : myRoots.values()) { if (root.isInLocalFileSystem() && !(root.getFileSystem() instanceof TempFileSystem)) { roots.add(root); } } return VfsUtilCore.toVirtualFileArray(roots); }
VirtualFilePointerManagerImpl(@Nonnull VirtualFileManager virtualFileManager, @Nonnull MessageBus bus, @Nonnull TempFileSystem tempFileSystem, @Nonnull LocalFileSystem localFileSystem) { myVirtualFileManager = virtualFileManager; myBus = bus; bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this); TEMP_FILE_SYSTEM = tempFileSystem; LOCAL_FILE_SYSTEM = localFileSystem; }
@Override public boolean acceptInput(Project project, final VirtualFile file) { if (file.getFileSystem() != LocalFileSystem.getInstance() && !(file.getFileSystem() instanceof TempFileSystem)) { return false; } final FileType fileType = file.getFileType(); return fileType == HtmlFileType.INSTANCE || fileType == XHtmlFileType.INSTANCE; }
private static VirtualFile getJarRootForLocalFile(VirtualFile file) { return ApplicationManager.getApplication().isUnitTestMode() ? TempFileSystem.getInstance().findFileByPath(file.getPath() + JarFileSystem.JAR_SEPARATOR) : JarFileSystem.getInstance().getJarRootForLocalFile(file); }