From 6cc7a5ae332b49adc2ee52bdccff38aa63eb807a Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 13 Oct 2016 12:46:49 +0300 Subject: [PATCH] cleanup --- .../openapi/vfs/ex/temp/TempFileSystem.java | 40 +++++-------------- .../vfs/impl/local/LocalFileSystemBase.java | 6 +-- .../vfs/impl/local/LocalFileSystemImpl.java | 5 +-- 3 files changed, 12 insertions(+), 39 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java index ee73224c2672..83b1112a2c0c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java @@ -21,15 +21,11 @@ import com.intellij.openapi.util.io.FileAttributes; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.local.LocalFileSystemBase; -import com.intellij.openapi.vfs.newvfs.ManagingFS; -import com.intellij.openapi.vfs.newvfs.RefreshQueue; -import com.intellij.openapi.vfs.newvfs.VfsImplUtil; import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile; import com.intellij.openapi.vfs.newvfs.persistent.FSRecords; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.LocalTimeCounter; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -57,7 +53,7 @@ public class TempFileSystem extends LocalFileSystemBase { } @Nullable - private FSItem convert(VirtualFile file) { + private FSItem convert(@NotNull VirtualFile file) { final VirtualFile parentFile = file.getParent(); if (parentFile == null) return myRoot; @@ -233,26 +229,6 @@ public class TempFileSystem extends LocalFileSystemBase { }; } - @Override - public void refresh(final boolean asynchronous) { - RefreshQueue.getInstance().refresh(asynchronous, true, null, ManagingFS.getInstance().getRoots(this)); - } - - @Override - public VirtualFile findFileByPath(@NotNull @NonNls String path) { - return VfsImplUtil.findFileByPath(this, path); - } - - @Override - public VirtualFile findFileByPathIfCached(@NotNull @NonNls String path) { - return VfsImplUtil.findFileByPathIfCached(this, path); - } - - @Override - public VirtualFile refreshAndFindFileByPath(@NotNull String path) { - return VfsImplUtil.refreshAndFindFileByPath(this, path); - } - @Override public long getLength(@NotNull final VirtualFile file) { try { @@ -269,7 +245,7 @@ public class TempFileSystem extends LocalFileSystemBase { private long myTimestamp; private boolean myWritable; - protected FSItem(final FSDir parent, final String name) { + FSItem(@Nullable FSDir parent, @NotNull String name) { myParent = parent; myName = name; myTimestamp = LocalTimeCounter.currentTime(); @@ -283,7 +259,7 @@ public class TempFileSystem extends LocalFileSystemBase { return null; } - public void setName(final String name) { + void setName(@NotNull String name) { myName = name; } @@ -291,6 +267,7 @@ public class TempFileSystem extends LocalFileSystemBase { return myParent; } + @NotNull public String[] list() { return ArrayUtil.EMPTY_STRING_ARRAY; } @@ -304,7 +281,7 @@ public class TempFileSystem extends LocalFileSystemBase { private static class FSDir extends FSItem { private final List myChildren = new ArrayList<>(); - public FSDir(final FSDir parent, final String name) { + FSDir(@Nullable FSDir parent, @NotNull String name) { super(parent, name); } @@ -325,17 +302,18 @@ public class TempFileSystem extends LocalFileSystemBase { return true; } - public void addChild(final FSItem item) { + void addChild(@NotNull FSItem item) { myChildren.add(item); } - public void removeChild(final FSItem fsItem) { + void removeChild(@NotNull FSItem fsItem) { if (fsItem.myName.equals("src") && getParent() == null) { throw new RuntimeException("removing src directory"); } myChildren.remove(fsItem); } + @NotNull @Override public String[] list() { String[] names = ArrayUtil.newStringArray(myChildren.size()); @@ -347,7 +325,7 @@ public class TempFileSystem extends LocalFileSystemBase { } private static class FSFile extends FSItem { - public FSFile(final FSDir parent, final String name) { + FSFile(@NotNull FSDir parent, @NotNull String name) { super(parent, name); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java index 3551e65ddb7a..c509cd8c4b62 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java @@ -447,8 +447,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { @Override @NotNull public byte[] contentsToByteArray(@NotNull final VirtualFile file) throws IOException { - final InputStream stream = new FileInputStream(convertToIOFileAndCheck(file)); - try { + try (InputStream stream = new FileInputStream(convertToIOFileAndCheck(file))) { long l = file.getLength(); if (l > Integer.MAX_VALUE) throw new IOException("File is too large: " + l + ", " + file); final int length = (int)l; @@ -457,9 +456,6 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { // so let's do buffered requests with buffer size 8192 that will use stack allocated buffer return loadBytes(length <= 8192 ? stream : new BufferedInputStream(stream), length); } - finally { - stream.close(); - } } @NotNull diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index 064c8ac4b0e2..76b4d175489f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -59,7 +59,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap private final boolean myWatchRecursively; private boolean myDominated; - public WatchRequestImpl(String rootPath, boolean watchRecursively) { + WatchRequestImpl(String rootPath, boolean watchRecursively) { myFSRootPath = rootPath; myWatchRecursively = watchRecursively; } @@ -125,7 +125,6 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap String rootPath = request.getRootPath(); TreeNode currentNode = rootNode; - MainLoop: for (String subPath : splitPath(rootPath)) { TreeNode nextNode = currentNode.nodes.get(subPath); if (nextNode != null) { @@ -133,7 +132,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap if (currentNode.watchRequest != null && currentNode.watchRequest.isToWatchRecursively()) { // a parent path of this request is already being watched recursively - do not need to add this one request.myDominated = true; - break MainLoop; + break; } } else {