mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[platform] refactoring: extract interface from PackageDirectoryCache
It's used from several (bundled) plugins, so it makes sense to define clear API for it. This will also make it simpler to reuse it for incremental directory index (IDEA-276394). GitOrigin-RevId: 5f924bbfeb440f0ecee49e59da5252f34a05ab87
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7ab1528831
commit
d855d8e8e8
@@ -6,7 +6,7 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.PackageDirectoryCache;
|
||||
import com.intellij.openapi.roots.PackageDirectoryCache;
|
||||
import com.intellij.openapi.util.LowMemoryWatcher;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
|
||||
@@ -5,7 +5,7 @@ package com.intellij.structuralsearch;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.PackageDirectoryCache;
|
||||
import com.intellij.openapi.roots.PackageDirectoryCache;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.NonClasspathClassFinder;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.roots.impl.PackageDirectoryCacheImpl;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides a fast way to retrieve information about packages corresponding to nested directories when root directories are given.
|
||||
*/
|
||||
public interface PackageDirectoryCache {
|
||||
@NotNull List<VirtualFile> getDirectoriesByPackageName(@NotNull String packageName);
|
||||
|
||||
@NotNull Set<String> getSubpackageNames(@NotNull String packageName, @NotNull GlobalSearchScope scope);
|
||||
|
||||
static @NotNull PackageDirectoryCache createCache(@NotNull List<? extends VirtualFile> roots) {
|
||||
MultiMap<String, VirtualFile> map = MultiMap.create();
|
||||
map.putValues("", roots);
|
||||
return new PackageDirectoryCacheImpl(map);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.roots.PackageDirectoryCache;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -18,13 +19,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PackageDirectoryCache {
|
||||
private static final Logger LOG = Logger.getInstance(PackageDirectoryCache.class);
|
||||
public class PackageDirectoryCacheImpl implements PackageDirectoryCache {
|
||||
private static final Logger LOG = Logger.getInstance(PackageDirectoryCacheImpl.class);
|
||||
private final MultiMap<String, VirtualFile> myRootsByPackagePrefix = MultiMap.create();
|
||||
private final Map<String, PackageInfo> myDirectoriesByPackageNameCache = new ConcurrentHashMap<>();
|
||||
private final Set<String> myNonExistentPackages = ContainerUtil.newConcurrentSet();
|
||||
|
||||
public PackageDirectoryCache(@NotNull MultiMap<String, VirtualFile> rootsByPackagePrefix) {
|
||||
public PackageDirectoryCacheImpl(@NotNull MultiMap<String, VirtualFile> rootsByPackagePrefix) {
|
||||
for (String prefix : rootsByPackagePrefix.keySet()) {
|
||||
for (VirtualFile file : rootsByPackagePrefix.get(prefix)) {
|
||||
if (!file.isValid()) {
|
||||
@@ -46,6 +47,7 @@ public class PackageDirectoryCache {
|
||||
myNonExistentPackages.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<VirtualFile> getDirectoriesByPackageName(final @NotNull String packageName) {
|
||||
PackageInfo info = getPackageInfo(packageName);
|
||||
return info == null ? Collections.emptyList() : Collections.unmodifiableList(info.myPackageDirectories);
|
||||
@@ -90,6 +92,7 @@ public class PackageDirectoryCache {
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getSubpackageNames(final @NotNull String packageName, @NotNull GlobalSearchScope scope) {
|
||||
final PackageInfo info = getPackageInfo(packageName);
|
||||
if (info == null) return Collections.emptySet();
|
||||
@@ -105,12 +108,6 @@ public class PackageDirectoryCache {
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
public static @NotNull PackageDirectoryCache createCache(@NotNull List<? extends VirtualFile> roots) {
|
||||
MultiMap<String, VirtualFile> map = MultiMap.create();
|
||||
map.putValues("", roots);
|
||||
return new PackageDirectoryCache(map);
|
||||
}
|
||||
|
||||
private final class PackageInfo {
|
||||
final @NotNull String myQname;
|
||||
final @NotNull List<? extends VirtualFile> myPackageDirectories;
|
||||
|
||||
@@ -57,7 +57,7 @@ class RootIndex {
|
||||
private final ConcurrentBitSet myNonInterestingIds = ConcurrentBitSet.create();
|
||||
@NotNull private final Project myProject;
|
||||
private final RootFileSupplier myRootSupplier;
|
||||
final PackageDirectoryCache myPackageDirectoryCache;
|
||||
final PackageDirectoryCacheImpl myPackageDirectoryCache;
|
||||
private volatile OrderEntryGraph myOrderEntryGraph;
|
||||
|
||||
RootIndex(@NotNull Project project) {
|
||||
@@ -100,7 +100,7 @@ class RootIndex {
|
||||
storeContentsBeneathExcluded(allRoots, hierarchies);
|
||||
storeOutsideProjectRootsButHasContentInside();
|
||||
|
||||
myPackageDirectoryCache = new PackageDirectoryCache(rootsByPackagePrefix) {
|
||||
myPackageDirectoryCache = new PackageDirectoryCacheImpl(rootsByPackagePrefix) {
|
||||
@Override
|
||||
protected boolean isPackageDirectory(@NotNull VirtualFile dir, @NotNull String packageName) {
|
||||
return getInfoForFile(dir).isInProject(dir) && packageName.equals(getPackageName(dir));
|
||||
|
||||
@@ -4,8 +4,8 @@ package org.jetbrains.plugins.gradle.config;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.externalSystem.psi.search.ExternalModuleBuildGlobalSearchScope;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.PackageDirectoryCache;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.impl.PackageDirectoryCache;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.NonClasspathClassFinder;
|
||||
import com.intellij.psi.PsiClass;
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalS
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.PackageDirectoryCache;
|
||||
import com.intellij.openapi.roots.PackageDirectoryCache;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
|
||||
Reference in New Issue
Block a user