This commit is contained in:
Alexey Kudravtsev
2019-02-01 14:42:51 +03:00
parent 130372f904
commit 895333da78
5 changed files with 56 additions and 52 deletions
@@ -16,6 +16,7 @@
package com.intellij.openapi.vfs;
import com.intellij.util.ThrowableConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -35,7 +36,7 @@ public interface LocalFileOperationsHandler {
* @return true if the handler has performed the deletion, false if the deletion needs to be performed through
* standard core logic.
*/
boolean delete(VirtualFile file) throws IOException;
boolean delete(@NotNull VirtualFile file) throws IOException;
/**
* Intercepts the movement of a file.
@@ -44,7 +45,7 @@ public interface LocalFileOperationsHandler {
* @return true if the handler has performed the move, false if the move needs to be performed through
* standard core logic.
*/
boolean move(VirtualFile file, VirtualFile toDir) throws IOException;
boolean move(@NotNull VirtualFile file, @NotNull VirtualFile toDir) throws IOException;
/**
* Intercepts the copying of a file.
@@ -55,7 +56,7 @@ public interface LocalFileOperationsHandler {
* standard core logic.
*/
@Nullable
File copy(VirtualFile file, VirtualFile toDir, final String copyName) throws IOException;
File copy(@NotNull VirtualFile file, @NotNull VirtualFile toDir, @NotNull String copyName) throws IOException;
/**
* Intercepts the renaming of a file.
@@ -64,7 +65,7 @@ public interface LocalFileOperationsHandler {
* @return true if the handler has performed the rename, false if the rename needs to be performed through
* standard core logic.
*/
boolean rename(VirtualFile file, String newName) throws IOException;
boolean rename(@NotNull VirtualFile file, @NotNull String newName) throws IOException;
/**
* Intercepts the creation of a file.
@@ -73,7 +74,7 @@ public interface LocalFileOperationsHandler {
* @return true if the handler has performed the file creation, false if the creation needs to be performed through
* standard core logic.
*/
boolean createFile(VirtualFile dir, String name) throws IOException;
boolean createFile(@NotNull VirtualFile dir, @NotNull String name) throws IOException;
/**
* Intercepts the creation of a directory.
@@ -82,7 +83,7 @@ public interface LocalFileOperationsHandler {
* @return true if the handler has performed the directory creation, false if the creation needs to be performed through
* standard core logic.
*/
boolean createDirectory(VirtualFile dir, String name) throws IOException;
boolean createDirectory(@NotNull VirtualFile dir, @NotNull String name) throws IOException;
void afterDone(final ThrowableConsumer<LocalFileOperationsHandler, IOException> invoker);
void afterDone(@NotNull ThrowableConsumer<LocalFileOperationsHandler, IOException> invoker);
}
@@ -50,7 +50,9 @@ public abstract class LocalFileSystem extends NewVirtualFileSystem {
public abstract void refreshFiles(@NotNull Iterable<? extends VirtualFile> files, boolean async, boolean recursive, @Nullable Runnable onFinish);
public interface WatchRequest {
@NotNull @SystemIndependent String getRootPath();
@NotNull
@SystemIndependent
String getRootPath();
boolean isToWatchRecursively();
}
@@ -73,10 +75,8 @@ public abstract class LocalFileSystem extends NewVirtualFileSystem {
}
}
public void removeWatchedRoot(@Nullable WatchRequest watchRequest) {
if (watchRequest != null) {
removeWatchedRoots(singleton(watchRequest));
}
public void removeWatchedRoot(@NotNull WatchRequest watchRequest) {
removeWatchedRoots(singleton(watchRequest));
}
public void removeWatchedRoots(@NotNull Collection<? extends WatchRequest> watchRequests) {
@@ -43,13 +43,14 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
private final boolean myWatchRecursively;
private boolean myDominated;
WatchRequestImpl(@SystemDependent String rootPath, boolean watchRecursively) {
WatchRequestImpl(@SystemDependent @NotNull String rootPath, boolean watchRecursively) {
myFSRootPath = rootPath;
myWatchRecursively = watchRecursively;
}
@NotNull
@Override
public @NotNull @SystemIndependent String getRootPath() {
public @SystemIndependent String getRootPath() {
return FileUtil.toSystemIndependentName(myFSRootPath);
}
@@ -89,6 +90,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
myWatcher.dispose();
}
@NotNull
private List<WatchRequestImpl> normalizeRootsForRefresh() {
List<WatchRequestImpl> result = new ArrayList<>();
@@ -168,14 +170,14 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
return parts;
}
private static void visitTree(TreeNode rootNode, Consumer<? super TreeNode> consumer) {
private static void visitTree(@NotNull TreeNode rootNode, @NotNull Consumer<? super TreeNode> consumer) {
for (TreeNode node : rootNode.nodes.values()) {
consumer.consume(node);
visitTree(node, consumer);
}
}
private boolean isAlreadyWatched(final WatchRequestImpl request) {
private boolean isAlreadyWatched(@NotNull WatchRequestImpl request) {
if (myNormalizedTree == null) {
normalizeRootsForRefresh();
}
@@ -206,7 +208,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
}
}
private void markPathsDirty(Iterable<String> dirtyPaths) {
private void markPathsDirty(@NotNull Iterable<String> dirtyPaths) {
for (String dirtyPath : dirtyPaths) {
VirtualFile file = findFileByPathIfCached(dirtyPath);
if (file instanceof NewVirtualFile) {
@@ -215,7 +217,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
}
}
private void markFlatDirsDirty(Iterable<String> dirtyPaths) {
private void markFlatDirsDirty(@NotNull Iterable<String> dirtyPaths) {
for (String dirtyPath : dirtyPaths) {
Pair<NewVirtualFile, NewVirtualFile> pair = VfsImplUtil.findCachedFileByPath(this, dirtyPath);
if (pair.first != null) {
@@ -230,7 +232,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
}
}
private void markRecursiveDirsDirty(Iterable<String> dirtyPaths) {
private void markRecursiveDirsDirty(@NotNull Iterable<String> dirtyPaths) {
for (String dirtyPath : dirtyPaths) {
Pair<NewVirtualFile, NewVirtualFile> pair = VfsImplUtil.findCachedFileByPath(this, dirtyPath);
if (pair.first != null) {
@@ -270,7 +272,8 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
recursiveRoots = ObjectUtils.notNull(recursiveRoots, Collections.emptyList());
flatRoots = ObjectUtils.notNull(flatRoots, Collections.emptyList());
Set<String> recursiveWatches = new HashSet<>(), flatWatches = new HashSet<>();
Set<String> recursiveWatches = new HashSet<>();
Set<String> flatWatches = new HashSet<>();
for (LocalFileSystem.WatchRequest watch : watchRequests) {
(watch.isToWatchRecursively() ? recursiveWatches : flatWatches).add(watch.getRootPath());
}
@@ -281,8 +284,8 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
Set<WatchRequest> result = new HashSet<>();
synchronized (myLock) {
boolean update = doAddRootsToWatch(recursiveRoots, flatRoots, result) |
doRemoveWatchedRoots(watchRequests);
boolean update = doAddRootsToWatch(recursiveRoots, flatRoots, result);
update |= doRemoveWatchedRoots(watchRequests);
if (update) {
myNormalizedTree = null;
setUpFileWatcher();
@@ -291,14 +294,14 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
return result;
}
private boolean doAddRootsToWatch(Collection<String> recursiveRoots, Collection<String> flatRoots, Set<? super WatchRequest> result) {
private boolean doAddRootsToWatch(@NotNull Collection<String> recursiveRoots, @NotNull Collection<String> flatRoots, @NotNull Set<? super WatchRequest> result) {
boolean update = false;
for (String root : recursiveRoots) update |= watch(root, true, result);
for (String root : flatRoots) update |= watch(root, false, result);
return update;
}
private boolean watch(String rootPath, boolean recursively, Set<? super WatchRequest> result) {
private boolean watch(@NotNull String rootPath, boolean recursively, @NotNull Set<? super WatchRequest> result) {
int index = rootPath.indexOf(JarFileSystem.JAR_SEPARATOR);
if (index >= 0) rootPath = rootPath.substring(0, index);
@@ -315,7 +318,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Di
return !request.myDominated;
}
private boolean doRemoveWatchedRoots(Collection<? extends WatchRequest> watchRequests) {
private boolean doRemoveWatchedRoots(@NotNull Collection<? extends WatchRequest> watchRequests) {
boolean update = false;
for (WatchRequest watchRequest : watchRequests) {
@@ -26,6 +26,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vfs.LocalFileOperationsHandler;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ThrowableConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -45,11 +46,11 @@ public class CvsFileOperationsHandler implements LocalFileOperationsHandler {
}
@Override
public boolean delete(final VirtualFile file) throws IOException {
public boolean delete(@NotNull final VirtualFile file) throws IOException {
return processDeletedFile(file);
}
private boolean processDeletedFile(final VirtualFile file) throws IOException {
private boolean processDeletedFile(@NotNull VirtualFile file) throws IOException {
if (myInternalDelete) return false;
final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
if (vcs != CvsVcs2.getInstance(myProject)) return false;
@@ -82,18 +83,18 @@ public class CvsFileOperationsHandler implements LocalFileOperationsHandler {
}
@Override
public boolean move(final VirtualFile file, final VirtualFile toDir) throws IOException {
public boolean move(@NotNull final VirtualFile file, @NotNull final VirtualFile toDir) throws IOException {
return doMoveRename(file, toDir, file.getName());
}
@Override
@Nullable
public File copy(final VirtualFile file, final VirtualFile toDir, final String copyName) {
public File copy(@NotNull final VirtualFile file, @NotNull final VirtualFile toDir, @NotNull final String copyName) {
return null;
}
@Override
public boolean rename(final VirtualFile file, final String newName) throws IOException {
public boolean rename(@NotNull final VirtualFile file, @NotNull final String newName) throws IOException {
return doMoveRename(file, file.getParent(), newName);
}
@@ -129,15 +130,15 @@ public class CvsFileOperationsHandler implements LocalFileOperationsHandler {
}
@Override
public boolean createFile(final VirtualFile dir, final String name) {
public boolean createFile(@NotNull final VirtualFile dir, @NotNull final String name) {
return false;
}
@Override
public boolean createDirectory(final VirtualFile dir, final String name) {
public boolean createDirectory(@NotNull final VirtualFile dir, @NotNull final String name) {
return false;
}
@Override
public void afterDone(final ThrowableConsumer<LocalFileOperationsHandler, IOException> invoker) {}
public void afterDone(@NotNull final ThrowableConsumer<LocalFileOperationsHandler, IOException> invoker) {}
}
@@ -57,7 +57,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
@Nullable private final File myCopyFrom;
private final boolean myRecursive;
AddedFileInfo(final VirtualFile dir, final String name, @Nullable final File copyFrom, boolean recursive) {
AddedFileInfo(@NotNull VirtualFile dir, @NotNull String name, @Nullable final File copyFrom, boolean recursive) {
myDir = dir;
myName = name;
myCopyFrom = copyFrom;
@@ -70,7 +70,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
private final File mySrc;
private final File myDst;
private MovedFileInfo(final Project project, final File src, final File dst) {
private MovedFileInfo(@NotNull Project project, @NotNull File src, @NotNull File dst) {
myProject = project;
mySrc = src;
myDst = dst;
@@ -114,6 +114,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
return e instanceof SvnBindException && ((SvnBindException)e).contains(ErrorCode.ENTRY_EXISTS) ? createMoveTargetExistsError(e) : e;
}
@NotNull
private static VcsException createMoveTargetExistsError(@NotNull Exception e) {
return new VcsException(Arrays.asList("Target of move operation is already under version control.",
"Subversion move had not been performed. ", e.getMessage()));
@@ -121,7 +122,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
@Override
@Nullable
public File copy(final VirtualFile file, final VirtualFile toDir, final String copyName) {
public File copy(@NotNull final VirtualFile file, @NotNull final VirtualFile toDir, @NotNull final String copyName) {
startOperation(file);
SvnVcs vcs = getVCS(toDir);
@@ -158,7 +159,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
return null;
}
private boolean sameRoot(final SvnVcs vcs, final VirtualFile srcDir, final VirtualFile dstDir) {
private boolean sameRoot(@NotNull SvnVcs vcs, @NotNull VirtualFile srcDir, @NotNull VirtualFile dstDir) {
final UUIDHelper helper = new UUIDHelper(vcs);
final String srcUUID = helper.getRepositoryUUID(vcs.getProject(), srcDir);
final String dstUUID = helper.getRepositoryUUID(vcs.getProject(), dstDir);
@@ -169,7 +170,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
private class UUIDHelper {
private final SvnVcs myVcs;
private UUIDHelper(final SvnVcs vcs) {
private UUIDHelper(@NotNull SvnVcs vcs) {
myVcs = vcs;
}
@@ -177,7 +178,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
* passed dir must be under VC control (it is assumed)
*/
@Nullable
public String getRepositoryUUID(final Project project, final VirtualFile dir) {
public String getRepositoryUUID(@NotNull Project project, @NotNull VirtualFile dir) {
try {
final Info info1 = new RepeatSvnActionThroughBusy() {
@Override
@@ -206,7 +207,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
}
@Override
public boolean move(VirtualFile file, VirtualFile toDir) {
public boolean move(@NotNull VirtualFile file, @NotNull VirtualFile toDir) {
startOperation(file);
File srcFile = getIOFile(file);
@@ -237,7 +238,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
}
@Override
public boolean rename(VirtualFile file, String newName) {
public boolean rename(@NotNull VirtualFile file, @NotNull String newName) {
startOperation(file);
File srcFile = getIOFile(file);
@@ -254,7 +255,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
return false;
}
private boolean doMove(@NotNull SvnVcs vcs, final File src, final File dst) {
private boolean doMove(@NotNull SvnVcs vcs, @NotNull File src, @NotNull File dst) {
try {
final boolean isUndo = isUndo(vcs);
final String list = isUndo ? null : SvnChangelistListener.getCurrentMapping(vcs, src);
@@ -399,14 +400,14 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
@Override
public boolean createFile(VirtualFile dir, String name) {
public boolean createFile(@NotNull VirtualFile dir, @NotNull String name) {
startOperation(dir);
return createItem(dir, name, false, false);
}
@Override
public boolean createDirectory(VirtualFile dir, String name) {
public boolean createDirectory(@NotNull VirtualFile dir, @NotNull String name) {
startOperation(dir);
return createItem(dir, name, true, false);
@@ -427,7 +428,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
* deleted: do nothing, return true (strange)
*/
@Override
public boolean delete(VirtualFile file) {
public boolean delete(@NotNull VirtualFile file) {
startOperation(file);
final SvnVcs vcs = getVCS(file);
@@ -965,7 +966,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
}
@Nullable
private static SvnVcs getVCS(VirtualFile file) {
private static SvnVcs getVCS(@NotNull VirtualFile file) {
Project[] projects = ProjectManager.getInstance().getOpenProjects();
for (Project project : projects) {
AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
@@ -977,7 +978,8 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
}
private static File getIOFile(VirtualFile vf) {
@NotNull
private static File getIOFile(@NotNull VirtualFile vf) {
return virtualToIoFile(vf).getAbsoluteFile();
}
@@ -996,10 +998,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
}
}
private static boolean isUndo(SvnVcs vcs) {
if (vcs == null || vcs.getProject() == null) {
return false;
}
private static boolean isUndo(@NotNull SvnVcs vcs) {
Project p = vcs.getProject();
return UndoManager.getInstance(p).isUndoInProgress();
}
@@ -1015,7 +1014,7 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos
}
@Override
public void afterDone(final ThrowableConsumer<LocalFileOperationsHandler, IOException> invoker) {
public void afterDone(@NotNull final ThrowableConsumer<LocalFileOperationsHandler, IOException> invoker) {
if (!myIsInCommand && myGuessedProject != null) {
commandFinished(myGuessedProject);
myGuessedProject = null;