From 1a970b57ed86a6161a4830d030fbb53c6ab34038 Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Thu, 2 Feb 2023 16:52:19 +0100 Subject: [PATCH] [platform] print error to the log if old RootIndex class is instantiated (IDEA-276394) It's still needed to build OrderEntryGraph (IDEA-307389), but in other cases it may be instantiated only if some code uses internal DirectoryIndex class directly. GitOrigin-RevId: 53f0ece11f5ccb5b947b16a9ffa189540c9e02ac --- .../openapi/roots/impl/DirectoryIndexImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index b0470efe847f..19fa30738b65 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -127,7 +127,7 @@ public final class DirectoryIndexImpl extends DirectoryIndex implements Disposab if (myWorkspaceFileIndex != null) { return myWorkspaceFileIndex.getDirectoriesByPackageName(packageName, includeLibrarySources); } - return getRootIndex().getDirectoriesByPackageName(packageName, includeLibrarySources); + return getRootIndex(false).getDirectoriesByPackageName(packageName, includeLibrarySources); } @Override @@ -143,7 +143,7 @@ public final class DirectoryIndexImpl extends DirectoryIndex implements Disposab } List indices = ContainerUtil.append(ContainerUtil.map(branches, DirectoryIndexImpl::obtainBranchRootIndex), - getRootIndex()); + getRootIndex(false)); return new CollectionQuery<>(indices) .flatMapping(i -> i.getDirectoriesByPackageName(packageName, true)) .filtering(scope::contains); @@ -155,7 +155,7 @@ public final class DirectoryIndexImpl extends DirectoryIndex implements Disposab if (branch != null) { return obtainBranchRootIndex(branch); } - return getRootIndex(); + return getRootIndex(false); } private static final Key> BRANCH_ROOT_INDEX = Key.create("BRANCH_ROOT_INDEX"); @@ -170,7 +170,10 @@ public final class DirectoryIndexImpl extends DirectoryIndex implements Disposab return pair.second; } - RootIndex getRootIndex() { + RootIndex getRootIndex(boolean forOrderEntryGraph) { + if (!forOrderEntryGraph && myWorkspaceFileIndex != null) { + LOG.error("Internal DirectoryIndex class must not be used directly to avoid long computations, use ProjectFileIndex API instead"); + } RootIndex rootIndex = myRootIndex; if (rootIndex == null) { myRootIndex = rootIndex = new RootIndex(myProject); @@ -224,7 +227,7 @@ public final class DirectoryIndexImpl extends DirectoryIndex implements Disposab WorkspaceFileInternalInfo fileInfo = myWorkspaceFileIndex.getFileInfo(fileOrDir, true, true, true, true); WorkspaceFileSetWithCustomData fileSet = fileInfo.findFileSet(data -> true); if (fileSet == null) return Collections.emptyList(); - return getRootIndex().getOrderEntries(fileSet.getRoot()); + return getRootIndex(true).getOrderEntries(fileSet.getRoot()); } if (fileOrDir instanceof VirtualFileWindow) { @@ -233,14 +236,14 @@ public final class DirectoryIndexImpl extends DirectoryIndex implements Disposab fileOrDir = BackedVirtualFile.getOriginFileIfBacked(fileOrDir); DirectoryInfo info = getInfoForFile(fileOrDir); if (!(info instanceof DirectoryInfoImpl)) return Collections.emptyList(); - return getRootIndex().getOrderEntries(((DirectoryInfoImpl)info).getRoot()); + return getRootIndex(true).getOrderEntries(((DirectoryInfoImpl)info).getRoot()); } @Override @NotNull public Set getDependentUnloadedModules(@NotNull Module module) { checkAvailability(); - return getRootIndex().getDependentUnloadedModules(module); + return getRootIndex(true).getDependentUnloadedModules(module); } private void checkAvailability() {