From ccd30e2f7636f5563af01072e9f36fd59cb2f863 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 10 Dec 2012 14:24:20 +0100 Subject: [PATCH] Remove a notion of persistence from core --- .../vfs/newvfs/FileSystemPersistence.java | 33 ------- .../core/CoreApplicationEnvironment.java | 35 ++------ .../vfs/impl/VirtualFileManagerImpl.java | 54 +++++------- .../roots/impl/DirectoryIndexComponent.java | 63 +++++++++++++- .../openapi/vfs/newvfs/ManagingFS.java | 17 ++-- .../vfs/PlatformVirtualFileManager.java | 53 +++++++++++ .../newvfs/persistent/PersistentFSImpl.java | 56 +++++------- .../src/componentSets/Platform.xml | 2 +- .../src/com/intellij/core/ProjectModel.java | 14 ++- .../roots/impl/DirectoryIndexImpl.java | 87 +++---------------- 10 files changed, 202 insertions(+), 212 deletions(-) delete mode 100644 platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java create mode 100644 platform/platform-impl/src/com/intellij/openapi/vfs/PlatformVirtualFileManager.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java deleted file mode 100644 index 6fa77487cb6d..000000000000 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.vfs.newvfs; - -import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author yole - */ -public interface FileSystemPersistence { - void refresh(boolean asynchronous, @Nullable Runnable postAction, @NotNull ModalityState modalityState); - - int getCheapFileSystemModificationCount(); - - @Nullable - VirtualFile findFileById(int id); -} diff --git a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java index d0314c60b19e..373cd2124f49 100644 --- a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java @@ -23,7 +23,6 @@ import com.intellij.mock.MockFileDocumentManagerImpl; import com.intellij.mock.MockReferenceProvidersRegistry; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.ExtensionAreas; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.impl.DocumentImpl; @@ -36,7 +35,6 @@ import com.intellij.openapi.fileTypes.*; import com.intellij.openapi.progress.*; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.StaticGetter; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.openapi.vfs.encoding.EncodingRegistry; @@ -44,7 +42,6 @@ import com.intellij.openapi.vfs.impl.CoreVirtualFilePointerManager; import com.intellij.openapi.vfs.impl.VirtualFileManagerImpl; import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem; import com.intellij.openapi.vfs.local.CoreLocalFileSystem; -import com.intellij.openapi.vfs.newvfs.FileSystemPersistence; import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.psi.PsiReferenceService; import com.intellij.psi.PsiReferenceServiceImpl; @@ -57,12 +54,14 @@ import com.intellij.util.Function; import com.intellij.util.Processor; import com.intellij.util.messages.impl.MessageBusImpl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.picocontainer.MutablePicoContainer; import java.lang.reflect.Modifier; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; /** * @author yole @@ -100,30 +99,11 @@ public class CoreApplicationEnvironment { } }, null)); - FileSystemPersistence fileSystemPersistence = new FileSystemPersistence() { - @Override - public void refresh(boolean asynchronous, Runnable postAction, @NotNull ModalityState modalityState) { - } + VirtualFileSystem[] fs = {myLocalFileSystem, myJarFileSystem}; + VirtualFileManagerImpl virtualFileManager = new VirtualFileManagerImpl(fs, new MessageBusImpl(myApplication, null)); + registerComponentInstance(appContainer, VirtualFileManager.class, virtualFileManager); - @Override - public int getCheapFileSystemModificationCount() { - return 0; - } - - @Nullable - @Override - public VirtualFile findFileById(int id) { - return null; - } - }; - VirtualFileManagerImpl virtualFileManager = new VirtualFileManagerImpl(new VirtualFileSystem[]{myLocalFileSystem, myJarFileSystem}, - new MessageBusImpl(myApplication, null), - fileSystemPersistence - ); - registerComponentInstance(appContainer, VirtualFileManager.class, virtualFileManager - ); myApplication.registerService(VirtualFilePointerManager.class, createVirtualFilePointerManager()); - myApplication.registerService(DefaultASTFactory.class, new CoreASTFactory()); myApplication.registerService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl()); myApplication.registerService(ReferenceProvidersRegistry.class, new MockReferenceProvidersRegistry()); @@ -136,7 +116,6 @@ public class CoreApplicationEnvironment { ProgressIndicatorProvider.ourInstance = createProgressIndicatorProvider(); myApplication.registerService(JobLauncher.class, createJobLauncher()); - } protected VirtualFilePointerManager createVirtualFilePointerManager() { diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 501cb0886979..bbb94176b61f 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -26,7 +26,6 @@ import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.CachingVirtualFileSystem; -import com.intellij.openapi.vfs.newvfs.FileSystemPersistence; import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; @@ -52,13 +51,9 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { private final List myPhysicalFileSystems = new ArrayList(); private final EventDispatcher myVirtualFileListenerMulticaster = EventDispatcher.create(VirtualFileListener.class); private final List myVirtualFileManagerListeners = ContainerUtil.createEmptyCOWList(); - private final FileSystemPersistence myPersistence; - private int myRefreshCount = 0; - public VirtualFileManagerImpl(@NotNull VirtualFileSystem[] fileSystems, @NotNull MessageBus bus, @NotNull FileSystemPersistence persistence) { - myPersistence = persistence; - + public VirtualFileManagerImpl(@NotNull VirtualFileSystem[] fileSystems, @NotNull MessageBus bus) { for (VirtualFileSystem fileSystem : fileSystems) { registerFileSystem(fileSystem); } @@ -93,6 +88,23 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { refresh(asynchronous, null); } + @Override + public void refresh(boolean asynchronous, @Nullable final Runnable postAction) { + doRefresh(asynchronous, postAction); + } + + protected void doRefresh(boolean asynchronous, @Nullable Runnable postAction) { + if (!asynchronous) { + ApplicationManager.getApplication().assertIsDispatchThread(); + } + + for (VirtualFileSystem fileSystem : getPhysicalFileSystems()) { + if (!(fileSystem instanceof CachingVirtualFileSystem)) { + fileSystem.refresh(asynchronous); + } + } + } + @Override public void refreshWithoutFileWatcher(final boolean asynchronous) { if (!asynchronous) { @@ -109,26 +121,6 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { } } - @Override - public void refresh(boolean asynchronous, @Nullable final Runnable postAction) { - refresh(asynchronous, postAction, ModalityState.NON_MODAL); - } - - public void refresh(boolean asynchronous, @Nullable Runnable postAction, @NotNull ModalityState modalityState) { - if (!asynchronous) { - ApplicationManager.getApplication().assertIsDispatchThread(); - } - - // todo: get an idea how to deliver changes from local FS to jar fs before they go refresh - myPersistence.refresh(asynchronous, postAction, modalityState); - - for (VirtualFileSystem fileSystem : getPhysicalFileSystems()) { - if (!(fileSystem instanceof CachingVirtualFileSystem)) { - fileSystem.refresh(asynchronous); - } - } - } - private List getPhysicalFileSystems() { return myPhysicalFileSystems; } @@ -241,6 +233,11 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { } } + @Override + public long getModificationCount() { + return 0; + } + private static class LoggingListener implements VirtualFileListener { @Override public void propertyChanged(VirtualFilePropertyEvent event) { @@ -298,9 +295,4 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { ", newParent = " + event.getNewParent() + ", requestor = " + event.getRequestor()); } } - - @Override - public long getModificationCount() { - return myPersistence.getCheapFileSystemModificationCount(); - } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexComponent.java index f9559e9f8672..e8e302a5c074 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexComponent.java @@ -24,11 +24,15 @@ import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; import com.intellij.openapi.startup.StartupManager; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter; +import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.util.*; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; @@ -40,8 +44,10 @@ import java.util.List; */ public class DirectoryIndexComponent extends DirectoryIndexImpl { private final MessageBusConnection myConnection; + private final ManagingFS myManagingFS; + private final PackageSink mySink; - public DirectoryIndexComponent(Project project, StartupManager startupManager) { + public DirectoryIndexComponent(@NotNull Project project, @NotNull StartupManager startupManager, @NotNull ManagingFS managingFS) { super(project); myConnection = project.getMessageBus().connect(project); startupManager.registerPreStartupActivity(new Runnable() { @@ -50,6 +56,55 @@ public class DirectoryIndexComponent extends DirectoryIndexImpl { initialize(); } }); + myManagingFS = managingFS; + mySink = new PackageSink(); + } + + private class PackageSink extends QueryFactory>> { + private final Condition IS_VALID = new Condition() { + @Override + public boolean value(final VirtualFile virtualFile) { + return virtualFile.isValid(); + } + }; + + private PackageSink() { + registerExecutor(new QueryExecutor>>() { + @Override + public boolean execute(@NotNull final Pair> stateAndDirs, + @NotNull final Processor consumer) { + for (VirtualFile dir : stateAndDirs.second) { + DirectoryInfo info = stateAndDirs.first.myDirToInfoMap.get(getId(dir)); + assert info != null; + + if (!info.isInLibrarySource() || info.isInModuleSource() || info.hasLibraryClassRoot()) { + if (!consumer.process(dir)) return false; + } + } + return true; + } + }); + } + + public Query search(@NotNull String packageName, boolean includeLibrarySources) { + checkAvailability(); + dispatchPendingEvents(); + + IndexState state = myState; + int[] allDirs = state.getDirsForPackage(packageName); + if (allDirs == null) allDirs = ArrayUtil.EMPTY_INT_ARRAY; + + List files = new ArrayList(allDirs.length); + for (int dir : allDirs) { + VirtualFile file = myManagingFS.findFileById(dir); + if (file != null) { + files.add(file); + } + } + + Query query = includeLibrarySources ? new CollectionQuery(files) : createQuery(Pair.create(state, files)); + return new FilteredQuery(query, IS_VALID); + } } @Override @@ -59,6 +114,12 @@ public class DirectoryIndexComponent extends DirectoryIndexImpl { markContentRootsForRefresh(); } + @Override + @NotNull + public Query getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) { + return mySink.search(packageName, includeLibrarySources); + } + private void subscribeToFileChanges() { myConnection.subscribe(FileTypeManager.TOPIC, new FileTypeListener.Adapter() { @Override diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java index 53c263adf238..aba3996c8563 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.openapi.vfs.newvfs; import com.intellij.openapi.application.ApplicationManager; @@ -29,7 +25,10 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.util.List; -public abstract class ManagingFS implements FileSystemInterface, FileSystemPersistence { +/** + * @author max + */ +public abstract class ManagingFS implements FileSystemInterface { private static class ManagingFSHolder { private static final ManagingFS ourInstance = ApplicationManager.getApplication().getComponent(ManagingFS.class); } @@ -47,7 +46,6 @@ public abstract class ManagingFS implements FileSystemInterface, FileSystemPersi public abstract int getModificationCount(@NotNull VirtualFile fileOrDirectory); // Only counts modifications done in current IDEA session - @Override public abstract int getCheapFileSystemModificationCount(); public abstract int getFilesystemModificationCount(); @@ -63,7 +61,8 @@ public abstract class ManagingFS implements FileSystemInterface, FileSystemPersi @Nullable public abstract NewVirtualFile findRoot(@NotNull String basePath, @NotNull NewVirtualFileSystem fs); - public abstract void refresh(final boolean asynchronous); + @NotNull + public abstract VirtualFile[] getRoots(); @NotNull public abstract VirtualFile[] getRoots(@NotNull NewVirtualFileSystem fs); @@ -71,10 +70,6 @@ public abstract class ManagingFS implements FileSystemInterface, FileSystemPersi @NotNull public abstract VirtualFile[] getLocalRoots(); - @Override @Nullable public abstract VirtualFile findFileById(int id); - - @NotNull - public abstract VirtualFile[] getRoots(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/PlatformVirtualFileManager.java b/platform/platform-impl/src/com/intellij/openapi/vfs/PlatformVirtualFileManager.java new file mode 100644 index 000000000000..48a39c930ed2 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/PlatformVirtualFileManager.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.vfs; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.vfs.impl.VirtualFileManagerImpl; +import com.intellij.openapi.vfs.newvfs.ManagingFS; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.openapi.vfs.newvfs.RefreshSession; +import com.intellij.util.messages.MessageBus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PlatformVirtualFileManager extends VirtualFileManagerImpl { + @NotNull private final ManagingFS myManagingFS; + + public PlatformVirtualFileManager(@NotNull VirtualFileSystem[] fileSystems, @NotNull MessageBus bus, @NotNull ManagingFS managingFS) { + super(fileSystems, bus); + myManagingFS = managingFS; + } + + @Override + protected void doRefresh(boolean asynchronous, @Nullable Runnable postAction) { + if (!asynchronous) { + ApplicationManager.getApplication().assertIsDispatchThread(); + } + + // todo: get an idea how to deliver changes from local FS to jar fs before they go refresh + RefreshSession session = RefreshQueue.getInstance().createSession(asynchronous, true, postAction); + session.addAllFiles(myManagingFS.getRoots()); + session.launch(); + + super.doRefresh(asynchronous, postAction); + } + + @Override + public long getModificationCount() { + return myManagingFS.getCheapFileSystemModificationCount(); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 398526d04672..4577d834de38 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -16,7 +16,6 @@ package com.intellij.openapi.vfs.newvfs.persistent; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; @@ -24,7 +23,10 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.*; import com.intellij.openapi.vfs.*; -import com.intellij.openapi.vfs.newvfs.*; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; +import com.intellij.openapi.vfs.newvfs.FileAttribute; +import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; import com.intellij.openapi.vfs.newvfs.events.*; import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile; import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl; @@ -817,36 +819,6 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone } } - @Override - public void refresh(boolean asynchronous) { - RefreshQueue.getInstance().refresh(asynchronous, true, null, getRoots()); - } - - @Override - public void refresh(boolean asynchronous, @Nullable Runnable postAction, @NotNull ModalityState modalityState) { - RefreshQueue.getInstance().refresh(asynchronous, true, postAction, modalityState, getRoots()); - } - - @Override - @NotNull - public VirtualFile[] getLocalRoots() { - final List roots = new ArrayList(); - - myRootsLock.readLock().lock(); - try { - for (NewVirtualFile root : myRoots.values()) { - if (root.isInLocalFileSystem()) { - roots.add(root); - } - } - } - finally { - myRootsLock.readLock().unlock(); - } - - return VfsUtilCore.toVirtualFileArray(roots); - } - @NotNull private final ConcurrentIntObjectMap myIdToDirCache = new StripedLockIntObjectConcurrentHashMap(); @Override @@ -955,6 +927,26 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone return VfsUtilCore.toVirtualFileArray(roots); } + @Override + @NotNull + public VirtualFile[] getLocalRoots() { + final List roots = new ArrayList(); + + myRootsLock.readLock().lock(); + try { + for (NewVirtualFile root : myRoots.values()) { + if (root.isInLocalFileSystem()) { + roots.add(root); + } + } + } + finally { + myRootsLock.readLock().unlock(); + } + + return VfsUtilCore.toVirtualFileArray(roots); + } + private void applyEvent(@NotNull VFileEvent event) { try { if (event instanceof VFileCreateEvent) { diff --git a/platform/platform-resources/src/componentSets/Platform.xml b/platform/platform-resources/src/componentSets/Platform.xml index 4b6900d619f2..19fd018dda07 100644 --- a/platform/platform-resources/src/componentSets/Platform.xml +++ b/platform/platform-resources/src/componentSets/Platform.xml @@ -17,7 +17,7 @@ com.intellij.openapi.vfs.VirtualFileManager - com.intellij.openapi.vfs.impl.VirtualFileManagerImpl + com.intellij.openapi.vfs.PlatformVirtualFileManager diff --git a/platform/projectModel-impl/src/com/intellij/core/ProjectModel.java b/platform/projectModel-impl/src/com/intellij/core/ProjectModel.java index 7b0f1ebbf863..4f0e10b9f6af 100644 --- a/platform/projectModel-impl/src/com/intellij/core/ProjectModel.java +++ b/platform/projectModel-impl/src/com/intellij/core/ProjectModel.java @@ -37,6 +37,9 @@ import com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable; import com.intellij.openapi.roots.impl.libraries.LibraryTablesRegistrarImpl; import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Query; +import org.jetbrains.annotations.NotNull; /** * @author yole @@ -45,6 +48,7 @@ public class ProjectModel { public static class InitApplicationEnvironment { protected final CoreApplicationEnvironment myApplicationEnvironment; + public InitApplicationEnvironment(CoreApplicationEnvironment env) { myApplicationEnvironment = env; Extensions.registerAreaClass(ExtensionAreas.IDEA_MODULE, null); @@ -109,7 +113,13 @@ public class ProjectModel { } protected DirectoryIndex createDirectoryIndex() { - return new DirectoryIndexImpl(myProject); + return new DirectoryIndexImpl(myProject) { + @NotNull + @Override + public Query getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) { + throw new UnsupportedOperationException(); + } + }; } private ProjectPathMacroManager createProjectPathMacroManager() { @@ -119,6 +129,6 @@ public class ProjectModel { protected ModuleManager createModuleManager() { return new CoreModuleManager(myProject, myProjectEnvironment.getParentDisposable()); } - } + } 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 f2d0d81986e2..37aedb8b677f 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 @@ -16,7 +16,6 @@ package com.intellij.openapi.roots.impl; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileTypeRegistry; @@ -29,13 +28,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.*; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.*; -import com.intellij.openapi.vfs.newvfs.FileSystemPersistence; -import com.intellij.util.*; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileVisitor; +import com.intellij.openapi.vfs.VirtualFileWithId; +import com.intellij.util.ArrayUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.containers.Stack; import gnu.trove.*; @@ -45,7 +44,7 @@ import org.jetbrains.annotations.TestOnly; import java.util.*; -public class DirectoryIndexImpl extends DirectoryIndex { +public abstract class DirectoryIndexImpl extends DirectoryIndex { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.DirectoryIndexImpl"); protected final Project myProject; @@ -67,10 +66,6 @@ public class DirectoryIndexImpl extends DirectoryIndex { }); } - private static class FileSystemPersistenceHolder { - private static final FileSystemPersistence persistence = ApplicationManager.getApplication().getComponents(FileSystemPersistence.class)[0]; - } - @Override @TestOnly public void checkConsistency() { @@ -178,62 +173,6 @@ public class DirectoryIndexImpl extends DirectoryIndex { return dir instanceof VirtualFileWithId && myState.myProjectExcludeRoots.contains(getId(dir)); } - private final PackageSink mySink = new PackageSink(); - - private static final Condition IS_VALID = new Condition() { - @Override - public boolean value(final VirtualFile virtualFile) { - return virtualFile.isValid(); - } - }; - - private class PackageSink extends QueryFactory>> { - private PackageSink() { - registerExecutor(new QueryExecutor>>() { - @Override - public boolean execute(@NotNull final Pair> stateAndDirs, - @NotNull final Processor consumer) { - for (VirtualFile dir : stateAndDirs.second) { - DirectoryInfo info = stateAndDirs.first.myDirToInfoMap.get(getId(dir)); - assert info != null; - - if (!info.isInLibrarySource() || info.isInModuleSource() || info.hasLibraryClassRoot()) { - if (!consumer.process(dir)) return false; - } - } - return true; - } - }); - } - - public Query search(@NotNull String packageName, boolean includeLibrarySources) { - checkAvailability(); - dispatchPendingEvents(); - - IndexState state = myState; - int[] allDirs = state.getDirsForPackage(packageName); - if (allDirs == null) allDirs = ArrayUtil.EMPTY_INT_ARRAY; - - List files = new ArrayList(allDirs.length); - for (int dir : allDirs) { - VirtualFile file = FileSystemPersistenceHolder.persistence.findFileById(dir); - if (file != null) { - files.add(file); - } - } - - Query query = includeLibrarySources ? new CollectionQuery(files) - : createQuery(Pair.create(state, files)); - return new FilteredQuery(query, IS_VALID); - } - } - - @Override - @NotNull - public Query getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) { - return mySink.search(packageName, includeLibrarySources); - } - @Override public String getPackageName(@NotNull VirtualFile dir) { checkAvailability(); @@ -244,11 +183,10 @@ public class DirectoryIndexImpl extends DirectoryIndex { protected void dispatchPendingEvents() { } - private void checkAvailability() { + protected void checkAvailability() { if (!myInitialized) { LOG.error("Directory index is not initialized yet for " + myProject); } - if (myDisposed) { LOG.error("Directory index is already disposed for " + myProject); } @@ -268,17 +206,18 @@ public class DirectoryIndexImpl extends DirectoryIndex { final List multiDirPackages = new ArrayList(Arrays.asList(new int[]{-1})); final TIntObjectHashMap myDirToPackageName = new TIntObjectHashMap(); - public IndexState() { - } + public IndexState() { } @Nullable - private int[] getDirsForPackage(String packageName) { + public int[] getDirsForPackage(String packageName) { int i = myPackageNameToDirsMap.get(packageName); return i == 0 ? null : i > 0 ? new int[]{i} : multiDirPackages.get(-i); } + private void removeDirFromPackage(@NotNull String packageName, int dirId) { int i = myPackageNameToDirsMap.get(packageName); - int[] oldPackageDirs = i == 0 ? null : i > 0 ? new int[]{i} : multiDirPackages.get(-i); + assert i != 0; + int[] oldPackageDirs = i > 0 ? new int[]{i} : multiDirPackages.get(-i); int index = ArrayUtil.find(oldPackageDirs, dirId); assert index != -1; oldPackageDirs = ArrayUtil.remove(oldPackageDirs, index); @@ -294,6 +233,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { multiDirPackages.set(-i, oldPackageDirs); } } + private void addDirToPackage(@NotNull String packageName, int dirId) { int i = myPackageNameToDirsMap.get(packageName); @@ -324,6 +264,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { } return info; } + private DirectoryInfo storeInfo(DirectoryInfo info, int dirId) { myDirToInfoMap.put(dirId, info); return info;