From 01e5d4b270d1ed8f5ea5835f4e51de5a424cc7e6 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 7 Dec 2021 19:06:10 +0100 Subject: [PATCH] Cleanup (warnings; formatting) GitOrigin-RevId: e70e133284dd0f11a3a02bf171613f487c554ef8 --- .../vfs/impl/jar/CoreJarFileSystem.java | 25 ++++++----------- .../openapi/vfs/impl/jar/CoreJarHandler.java | 24 ++++++---------- .../vfs/impl/jar/CoreJarVirtualFile.java | 28 ++++++------------- .../vfs/local/CoreLocalFileSystem.java | 10 ++----- .../vfs/local/CoreLocalVirtualFile.java | 6 ++-- 5 files changed, 32 insertions(+), 61 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java index 904aabebd433..9f564a48a77b 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java @@ -1,42 +1,35 @@ // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vfs.impl.jar; -import com.intellij.openapi.util.Couple; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.DeprecatedVirtualFileSystem; import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ConcurrentFactoryMap; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.util.Map; +import static com.intellij.openapi.util.Pair.pair; public final class CoreJarFileSystem extends DeprecatedVirtualFileSystem { - private final Map myHandlers = - ConcurrentFactoryMap.createMap(key -> new CoreJarHandler(CoreJarFileSystem.this, key)); + private final Map myHandlers = ConcurrentFactoryMap.createMap(key -> new CoreJarHandler(this, key)); - @NotNull @Override - public String getProtocol() { + public @NotNull String getProtocol() { return StandardFileSystems.JAR_PROTOCOL; } @Override - public VirtualFile findFileByPath(@NotNull @NonNls String path) { - Couple pair = splitPath(path); + public VirtualFile findFileByPath(@NotNull String path) { + Pair pair = splitPath(path); return myHandlers.get(pair.first).findFileByPath(pair.second); } - @NotNull - static Couple splitPath(@NotNull String path) { + static @NotNull Pair splitPath(@NotNull String path) { int separator = path.indexOf("!/"); - if (separator < 0) { - throw new IllegalArgumentException("Path in JarFileSystem must contain a separator: " + path); - } - String localPath = path.substring(0, separator); - String pathInJar = path.substring(separator + 2); - return Couple.of(localPath, pathInJar); + if (separator < 0) throw new IllegalArgumentException("Path in JarFileSystem must contain a separator: " + path); + return pair(path.substring(0, separator), path.substring(separator + 2)); } @Override diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarHandler.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarHandler.java index f448c4132e38..26d2d63ec91b 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarHandler.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vfs.impl.jar; import com.intellij.openapi.vfs.VirtualFile; @@ -12,7 +12,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - final class CoreJarHandler extends ZipHandler { private final CoreJarFileSystem myFileSystem; private final VirtualFile myRoot; @@ -23,8 +22,8 @@ final class CoreJarHandler extends ZipHandler { Map entries = new HashMap<>(); - final Map entriesMap = getEntriesMap(); - final Map> childrenMap = FactoryMap.create(key -> new ArrayList<>()); + Map entriesMap = getEntriesMap(); + Map> childrenMap = FactoryMap.create(key -> new ArrayList<>()); for (EntryInfo info : entriesMap.values()) { CoreJarVirtualFile file = getOrCreateFile(info, entries); VirtualFile parent = file.getParent(); @@ -41,27 +40,22 @@ final class CoreJarHandler extends ZipHandler { } } - @NotNull - private CoreJarVirtualFile getOrCreateFile(@NotNull EntryInfo info, @NotNull Map entries) { + private CoreJarVirtualFile getOrCreateFile(EntryInfo info, Map entries) { CoreJarVirtualFile file = entries.get(info); if (file == null) { - EntryInfo parent = info.parent; - file = new CoreJarVirtualFile(this, info.shortName, - info.isDirectory ? -1 : info.length, - info.timestamp, - parent != null ? getOrCreateFile(parent, entries) : null); + long length = info.isDirectory ? -1 : info.length; + CoreJarVirtualFile parent = info.parent != null ? getOrCreateFile(info.parent, entries) : null; + file = new CoreJarVirtualFile(this, info.shortName, length, info.timestamp, parent); entries.put(info, file); } return file; } - @Nullable - VirtualFile findFileByPath(@NotNull String pathInJar) { + @Nullable VirtualFile findFileByPath(@NotNull String pathInJar) { return myRoot != null ? myRoot.findFileByRelativePath(pathInJar) : null; } - @NotNull - CoreJarFileSystem getFileSystem() { + @NotNull CoreJarFileSystem getFileSystem() { return myFileSystem; } } diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java index a3d0ae516026..5cf1349a6248 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java @@ -1,7 +1,7 @@ -// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vfs.impl.jar; -import com.intellij.openapi.util.Couple; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.BufferExposingByteArrayInputStream; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -13,7 +13,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; - final class CoreJarVirtualFile extends VirtualFile { private final CoreJarHandler myHandler; private final CharSequence myName; @@ -22,11 +21,7 @@ final class CoreJarVirtualFile extends VirtualFile { private final VirtualFile myParent; private VirtualFile[] myChildren = VirtualFile.EMPTY_ARRAY; - CoreJarVirtualFile(@NotNull CoreJarHandler handler, - @NotNull CharSequence name, - long length, - long timestamp, - @Nullable CoreJarVirtualFile parent) { + CoreJarVirtualFile(@NotNull CoreJarHandler handler, @NotNull CharSequence name, long length, long timestamp, @Nullable CoreJarVirtualFile parent) { myHandler = handler; myName = name; myLength = length; @@ -38,27 +33,23 @@ final class CoreJarVirtualFile extends VirtualFile { myChildren = children; } - @NotNull @Override - public String getName() { + public @NotNull String getName() { return myName.toString(); } - @NotNull @Override - public CharSequence getNameSequence() { + public @NotNull CharSequence getNameSequence() { return myName; } - @NotNull @Override - public VirtualFileSystem getFileSystem() { + public @NotNull VirtualFileSystem getFileSystem() { return myHandler.getFileSystem(); } @Override - @NotNull - public String getPath() { + public @NotNull String getPath() { if (myParent == null) { return FileUtil.toSystemIndependentName(myHandler.getFile().getPath()) + "!/"; } @@ -99,15 +90,14 @@ final class CoreJarVirtualFile extends VirtualFile { return myChildren; } - @NotNull @Override - public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { + public @NotNull OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { throw new UnsupportedOperationException("JarFileSystem is read-only"); } @Override public byte @NotNull [] contentsToByteArray() throws IOException { - Couple pair = CoreJarFileSystem.splitPath(getPath()); + Pair pair = CoreJarFileSystem.splitPath(getPath()); return myHandler.contentsToByteArray(pair.second); } diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalFileSystem.java b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalFileSystem.java index bf0766fb09b7..61bfaaaa900b 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalFileSystem.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalFileSystem.java @@ -4,7 +4,6 @@ package com.intellij.openapi.vfs.local; import com.intellij.openapi.vfs.DeprecatedVirtualFileSystem; import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,11 +12,9 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; - public class CoreLocalFileSystem extends DeprecatedVirtualFileSystem { - @NotNull @Override - public String getProtocol() { + public @NotNull String getProtocol() { return StandardFileSystems.FILE_PROTOCOL; } @@ -30,13 +27,12 @@ public class CoreLocalFileSystem extends DeprecatedVirtualFileSystem { } @Override - public VirtualFile findFileByPath(@NotNull @NonNls String path) { + public VirtualFile findFileByPath(@NotNull String path) { return findFileByNioFile(FileSystems.getDefault().getPath(path)); } @Override - public void refresh(boolean asynchronous) { - } + public void refresh(boolean asynchronous) { } @Override public VirtualFile refreshAndFindFileByPath(@NotNull String path) { diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java index 6e2e047c0a48..82a2986188e4 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java @@ -131,9 +131,8 @@ public class CoreLocalVirtualFile extends VirtualFile { return myChildren; } - @NotNull @Override - public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { + public @NotNull OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { throw new UnsupportedOperationException(); } @@ -143,8 +142,7 @@ public class CoreLocalVirtualFile extends VirtualFile { } @Override - public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) { - } + public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) { } @Override public @NotNull InputStream getInputStream() throws IOException {