Java Code Examples for com.intellij.openapi.vfs.VirtualFile#move()
The following examples show how to use
com.intellij.openapi.vfs.VirtualFile#move() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UndoChangeRevertingVisitor.java From consulo with Apache License 2.0 | 6 votes |
@Override public void visit(MoveChange c) throws StopVisitingException { if (shouldRevert(c)) { VirtualFile f = myGateway.findVirtualFile(c.getPath()); if (f != null) { try { VirtualFile parent = myGateway.findOrCreateFileSafely(c.getOldParent(), true); VirtualFile existing = parent.findChild(f.getName()); if (existing != null) existing.delete(LocalHistory.VFS_EVENT_REQUESTOR); f.move(LocalHistory.VFS_EVENT_REQUESTOR, parent); } catch (IOException e) { throw new RuntimeIOException(e); } } } checkShouldStop(c); }
Example 2
Source File: DifferenceReverterTest.java From consulo with Apache License 2.0 | 6 votes |
public void testMovement() throws Exception { VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1"); VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2"); VirtualFile f = dir1.createChildData(this, "foo.txt"); f.setBinaryContent(new byte[]{123}, -1, 4000); f.move(this, dir2); revertLastChange(); assertNull(dir2.findChild("foo.txt")); f = dir1.findChild("foo.txt"); assertNotNull(f); assertEquals(123, f.contentsToByteArray()[0]); assertEquals(4000, f.getTimeStamp()); }
Example 3
Source File: DifferenceReverterTest.java From consulo with Apache License 2.0 | 6 votes |
public void testRevertingMoveFromOldRevisionsWhenDirDoesNotExists() throws Exception { VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1"); VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2"); VirtualFile f = dir1.createChildData(this, "foo.txt"); f.move(this, dir2); dir1.delete(this); dir2.delete(this); revertChange(2); dir1 = myRoot.findChild("dir1"); assertNotNull(dir1); assertNull(myRoot.findChild("dir2")); assertNotNull(dir1.findChild("foo.txt")); }
Example 4
Source File: PathsVerifier.java From consulo with Apache License 2.0 | 6 votes |
private static VirtualFile moveFile(final VirtualFile file, final VirtualFile newParent) throws IOException { file.move(FilePatch.class, newParent); return file; /*final Ref<IOException> ioExceptionRef = new Ref<IOException>(); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { file.move(FilePatch.class, newParent); } catch (IOException e) { ioExceptionRef.set(e); } } }); if (! ioExceptionRef.isNull()) { throw ioExceptionRef.get(); } return file;*/ }
Example 5
Source File: MoveFilesOrDirectoriesUtil.java From consulo with Apache License 2.0 | 6 votes |
/** * Moves the specified file to the specified directory. Does not process non-code usages! file may be invalidated, need to be refreshed before use, like {@code newDirectory.findFile(file.getName())} * * @param file the file to move. * @param newDirectory the directory to move the file into. * @throws IncorrectOperationException if the modification is not supported or not possible for some reason. */ public static void doMoveFile(@Nonnull PsiFile file, @Nonnull PsiDirectory newDirectory) throws IncorrectOperationException { // the class is already there, this is true when multiple classes are defined in the same file if (!newDirectory.equals(file.getContainingDirectory())) { // do actual move checkMove(file, newDirectory); VirtualFile vFile = file.getVirtualFile(); if (vFile == null) { throw new IncorrectOperationException("Non-physical file: " + file + " (" + file.getClass() + ")"); } try { vFile.move(file.getManager(), newDirectory.getVirtualFile()); } catch (IOException e) { throw new IncorrectOperationException(e); } } }
Example 6
Source File: UpdateBreakpointsAfterRenameTest.java From consulo with Apache License 2.0 | 5 votes |
public void testMoveFile() throws Exception { final VirtualFile file = createFile("dir/a.txt"); final VirtualFile targetDir = createFile("dir2/b.txt").getParent(); final XLineBreakpoint<?> b = putBreakpoint(file); file.move(this, targetDir); assertTrue(b.getFileUrl().endsWith("dir2/a.txt")); }
Example 7
Source File: ApplyFilePatchBase.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static VirtualFile findPatchTarget(final ApplyPatchContext context, final String beforeName, final String afterName, final boolean isNewFile) throws IOException { VirtualFile file = null; if (beforeName != null) { file = findFileToPatchByName(context, beforeName, isNewFile); } if (file == null) { file = findFileToPatchByName(context, afterName, isNewFile); } else if (context.isAllowRename() && afterName != null && !beforeName.equals(afterName)) { String[] beforeNameComponents = beforeName.split("/"); String[] afterNameComponents = afterName.split("/"); if (!beforeNameComponents [beforeNameComponents.length-1].equals(afterNameComponents [afterNameComponents.length-1])) { context.registerBeforeRename(file); file.rename(FilePatch.class, afterNameComponents [afterNameComponents.length-1]); } boolean needMove = (beforeNameComponents.length != afterNameComponents.length); if (!needMove) { needMove = checkPackageRename(context, beforeNameComponents, afterNameComponents); } if (needMove) { VirtualFile moveTarget = findFileToPatchByComponents(context, afterNameComponents, afterNameComponents.length-1); if (moveTarget == null) { return null; } context.registerBeforeRename(file); file.move(FilePatch.class, moveTarget); } } return file; }