From 6369b5cb05a2a7fedac3e9eafee8f4a8946fef1f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 16 Nov 2015 17:57:25 +0100 Subject: [PATCH] use ConcurrentFactoryMap to simplify implementation of CoreJarFileSystem; add API to clear list of handlers --- .../vfs/impl/jar/CoreJarFileSystem.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 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 a106c2a0f277..312a1edf4d3b 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 @@ -19,17 +19,24 @@ import com.intellij.openapi.util.Couple; 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 org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.Map; /** * @author yole */ public class CoreJarFileSystem extends DeprecatedVirtualFileSystem { - private final Map myHandlers = new HashMap(); + private final Map myHandlers = new ConcurrentFactoryMap() { + @Nullable + @Override + protected CoreJarHandler create(String key) { + return new CoreJarHandler(CoreJarFileSystem.this, key); + } + }; @NotNull @Override @@ -40,7 +47,7 @@ public class CoreJarFileSystem extends DeprecatedVirtualFileSystem { @Override public VirtualFile findFileByPath(@NotNull @NonNls String path) { Couple pair = splitPath(path); - return getHandler(pair.first).findFileByPath(pair.second); + return myHandlers.get(pair.first).findFileByPath(pair.second); } @NotNull @@ -54,16 +61,6 @@ public class CoreJarFileSystem extends DeprecatedVirtualFileSystem { return Couple.of(localPath, pathInJar); } - @NotNull - private CoreJarHandler getHandler(String localPath) { - CoreJarHandler handler = myHandlers.get(localPath); - if (handler == null) { - handler = new CoreJarHandler(this, localPath); - myHandlers.put(localPath, handler); - } - return handler; - } - @Override public void refresh(boolean asynchronous) { } @@ -71,4 +68,9 @@ public class CoreJarFileSystem extends DeprecatedVirtualFileSystem { public VirtualFile refreshAndFindFileByPath(@NotNull String path) { return findFileByPath(path); } + + @SuppressWarnings("unused") // used in Kotlin + public void clearHandlersCache() { + myHandlers.clear(); + } }