mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove a notion of persistence from core
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<VirtualFileSystem> myPhysicalFileSystems = new ArrayList<VirtualFileSystem>();
|
||||
private final EventDispatcher<VirtualFileListener> myVirtualFileListenerMulticaster = EventDispatcher.create(VirtualFileListener.class);
|
||||
private final List<VirtualFileManagerListener> 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<VirtualFileSystem> 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();
|
||||
}
|
||||
}
|
||||
|
||||
+62
-1
@@ -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<VirtualFile, Pair<IndexState, List<VirtualFile>>> {
|
||||
private final Condition<VirtualFile> IS_VALID = new Condition<VirtualFile>() {
|
||||
@Override
|
||||
public boolean value(final VirtualFile virtualFile) {
|
||||
return virtualFile.isValid();
|
||||
}
|
||||
};
|
||||
|
||||
private PackageSink() {
|
||||
registerExecutor(new QueryExecutor<VirtualFile, Pair<IndexState, List<VirtualFile>>>() {
|
||||
@Override
|
||||
public boolean execute(@NotNull final Pair<IndexState, List<VirtualFile>> stateAndDirs,
|
||||
@NotNull final Processor<VirtualFile> 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<VirtualFile> 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<VirtualFile> files = new ArrayList<VirtualFile>(allDirs.length);
|
||||
for (int dir : allDirs) {
|
||||
VirtualFile file = myManagingFS.findFileById(dir);
|
||||
if (file != null) {
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
Query<VirtualFile> query = includeLibrarySources ? new CollectionQuery<VirtualFile>(files) : createQuery(Pair.create(state, files));
|
||||
return new FilteredQuery<VirtualFile>(query, IS_VALID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,6 +114,12 @@ public class DirectoryIndexComponent extends DirectoryIndexImpl {
|
||||
markContentRootsForRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Query<VirtualFile> getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
|
||||
return mySink.search(packageName, includeLibrarySources);
|
||||
}
|
||||
|
||||
private void subscribeToFileChanges() {
|
||||
myConnection.subscribe(FileTypeManager.TOPIC, new FileTypeListener.Adapter() {
|
||||
@Override
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
+24
-32
@@ -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<VirtualFile> roots = new ArrayList<VirtualFile>();
|
||||
|
||||
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<NewVirtualFile> myIdToDirCache = new StripedLockIntObjectConcurrentHashMap<NewVirtualFile>();
|
||||
|
||||
@Override
|
||||
@@ -955,6 +927,26 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone
|
||||
return VfsUtilCore.toVirtualFileArray(roots);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VirtualFile[] getLocalRoots() {
|
||||
final List<VirtualFile> roots = new ArrayList<VirtualFile>();
|
||||
|
||||
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) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.openapi.vfs.VirtualFileManager</interface-class>
|
||||
<implementation-class>com.intellij.openapi.vfs.impl.VirtualFileManagerImpl</implementation-class>
|
||||
<implementation-class>com.intellij.openapi.vfs.PlatformVirtualFileManager</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
|
||||
@@ -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<VirtualFile> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-73
@@ -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<VirtualFile> IS_VALID = new Condition<VirtualFile>() {
|
||||
@Override
|
||||
public boolean value(final VirtualFile virtualFile) {
|
||||
return virtualFile.isValid();
|
||||
}
|
||||
};
|
||||
|
||||
private class PackageSink extends QueryFactory<VirtualFile, Pair<IndexState, List<VirtualFile>>> {
|
||||
private PackageSink() {
|
||||
registerExecutor(new QueryExecutor<VirtualFile, Pair<IndexState, List<VirtualFile>>>() {
|
||||
@Override
|
||||
public boolean execute(@NotNull final Pair<IndexState, List<VirtualFile>> stateAndDirs,
|
||||
@NotNull final Processor<VirtualFile> 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<VirtualFile> 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<VirtualFile> files = new ArrayList<VirtualFile>(allDirs.length);
|
||||
for (int dir : allDirs) {
|
||||
VirtualFile file = FileSystemPersistenceHolder.persistence.findFileById(dir);
|
||||
if (file != null) {
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
Query<VirtualFile> query = includeLibrarySources ? new CollectionQuery<VirtualFile>(files)
|
||||
: createQuery(Pair.create(state, files));
|
||||
return new FilteredQuery<VirtualFile>(query, IS_VALID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Query<VirtualFile> 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<int[]> multiDirPackages = new ArrayList<int[]>(Arrays.asList(new int[]{-1}));
|
||||
final TIntObjectHashMap<String> myDirToPackageName = new TIntObjectHashMap<String>();
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user