use ConcurrentFactoryMap to simplify implementation of CoreJarFileSystem; add API to clear list of handlers

This commit is contained in:
Dmitry Jemerov
2015-11-16 17:58:31 +01:00
parent bbbe7ddfba
commit 6369b5cb05
@@ -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<String, CoreJarHandler> myHandlers = new HashMap<String, CoreJarHandler>();
private final Map<String, CoreJarHandler> myHandlers = new ConcurrentFactoryMap<String, CoreJarHandler>() {
@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<String> 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();
}
}