From 06d5fa05e96a9f555f6ebc9c4e7bf0730c889ab3 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 23 Aug 2011 13:06:51 +0200 Subject: [PATCH] we no longer need multiple cache managers; some related cleanup --- .../src/com/intellij/mock/MockPsiManager.java | 30 +---- .../intellij/psi/impl/EmptyCacheManager.java | 2 +- .../com/intellij/psi/impl/PsiManagerImpl.java | 14 +- .../cache/impl/CompositeCacheManager.java | 120 ------------------ 4 files changed, 5 insertions(+), 161 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/psi/impl/cache/impl/CompositeCacheManager.java diff --git a/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java b/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java index 7176f6764b7b..f3e50da8f970 100644 --- a/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java +++ b/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java @@ -23,18 +23,13 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.impl.PsiCachedValuesFactory; +import com.intellij.psi.impl.EmptyCacheManager; import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.PsiModificationTrackerImpl; import com.intellij.psi.impl.PsiTreeChangeEventImpl; import com.intellij.psi.impl.cache.CacheManager; -import com.intellij.psi.impl.cache.impl.CompositeCacheManager; import com.intellij.psi.impl.file.impl.FileManager; -import com.intellij.psi.impl.search.PsiSearchHelperImpl; import com.intellij.psi.impl.source.resolve.ResolveCache; -import com.intellij.psi.search.PsiSearchHelper; -import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.CachedValuesManagerImpl; import com.intellij.util.IncorrectOperationException; @@ -50,10 +45,9 @@ import java.util.Map; public class MockPsiManager extends PsiManagerEx { private final Project myProject; private final Map myDirectories = new THashMap(); - private CachedValuesManagerImpl myCachedValuesManager; private MockFileManager myMockFileManager; private PsiModificationTrackerImpl myPsiModificationTracker; - private final CompositeCacheManager myCompositeCacheManager = new CompositeCacheManager(); + private final CacheManager myCacheManager = new EmptyCacheManager(); private ResolveCache myResolveCache; public MockPsiManager() { @@ -103,16 +97,6 @@ public class MockPsiManager extends PsiManagerEx { public void removePsiTreeChangeListener(@NotNull PsiTreeChangeListener listener) { } - @NotNull - public CodeStyleManager getCodeStyleManager() { - return CodeStyleManager.getInstance(myProject); - } - - @NotNull - public PsiSearchHelper getSearchHelper() { - return new PsiSearchHelperImpl(this); - } - @NotNull public PsiModificationTracker getModificationTracker() { if (myPsiModificationTracker == null) { @@ -121,14 +105,6 @@ public class MockPsiManager extends PsiManagerEx { return myPsiModificationTracker; } - @NotNull - public CachedValuesManager getCachedValuesManager() { - if (myCachedValuesManager == null) { - myCachedValuesManager = new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(this)); - } - return myCachedValuesManager; - } - public void moveFile(@NotNull PsiFile file, @NotNull PsiDirectory newParentDir) throws IncorrectOperationException { } @@ -254,6 +230,6 @@ public class MockPsiManager extends PsiManagerEx { @NotNull public CacheManager getCacheManager() { - return myCompositeCacheManager; + return myCacheManager; } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/EmptyCacheManager.java b/platform/lang-impl/src/com/intellij/psi/impl/EmptyCacheManager.java index 6b17964d027e..7430d624a141 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/EmptyCacheManager.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/EmptyCacheManager.java @@ -29,7 +29,7 @@ import com.intellij.psi.search.IndexPatternProvider; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; -class EmptyCacheManager implements CacheManager { +public class EmptyCacheManager implements CacheManager { public void initialize() { } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java index dc0b08b698f8..f66ed0a7a2d9 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java @@ -42,7 +42,6 @@ import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.psi.*; import com.intellij.psi.impl.cache.CacheManager; import com.intellij.psi.impl.cache.impl.CacheUtil; -import com.intellij.psi.impl.cache.impl.CompositeCacheManager; import com.intellij.psi.impl.cache.impl.IndexCacheManagerImpl; import com.intellij.psi.impl.file.impl.FileManager; import com.intellij.psi.impl.file.impl.FileManagerImpl; @@ -110,19 +109,8 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { myFileManager = isProjectDefault ? new EmptyFileManager(this) : new FileManagerImpl(this, fileTypeManager, fileDocumentManager, projectRootManagerEx); - final CompositeCacheManager cacheManager = new CompositeCacheManager(); - if (isProjectDefault) { - cacheManager.addCacheManager(new EmptyCacheManager()); - } - else { - cacheManager.addCacheManager(new IndexCacheManagerImpl(this)); - } - final CacheManager[] managers = myProject.getComponents(CacheManager.class); - for (CacheManager manager : managers) { - cacheManager.addCacheManager(manager); - } - myCacheManager = cacheManager; + myCacheManager = isProjectDefault ? new EmptyCacheManager() : new IndexCacheManagerImpl(this); myModificationTracker = new PsiModificationTrackerImpl(myProject); myTreeChangePreprocessors.add(myModificationTracker); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/CompositeCacheManager.java b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/CompositeCacheManager.java deleted file mode 100644 index ee60f241dd39..000000000000 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/CompositeCacheManager.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2000-2009 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.psi.impl.cache.impl; - -import com.intellij.ide.caches.CacheUpdater; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.impl.cache.CacheManager; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.search.IndexPattern; -import com.intellij.psi.search.IndexPatternProvider; -import com.intellij.psi.util.PsiUtilBase; -import com.intellij.util.CommonProcessors; -import com.intellij.util.Processor; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author peter - */ -public class CompositeCacheManager implements CacheManager{ - private final List myManagers = new ArrayList(); - - public void addCacheManager(CacheManager manager) { - myManagers.add(manager); - } - - public void initialize() { - for (CacheManager cacheManager : myManagers) { - cacheManager.initialize(); - } - } - - public void dispose() { - for (CacheManager cacheManager : myManagers) { - cacheManager.dispose(); - } - } - - @NotNull - public CacheUpdater[] getCacheUpdaters() { - List updaters = new ArrayList(); - for (CacheManager cacheManager : myManagers) { - ContainerUtil.addAll(updaters, cacheManager.getCacheUpdaters()); - } - return updaters.toArray(new CacheUpdater[updaters.size()]); - } - - @NotNull - public PsiFile[] getFilesWithWord(@NotNull String word, short occurenceMask, @NotNull GlobalSearchScope scope, final boolean caseSensitively) { - CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor(); - processFilesWithWord(processor, word, occurenceMask, scope, caseSensitively); - Collection results = processor.getResults(); - return PsiUtilBase.toPsiFileArray(results); - } - - public boolean processFilesWithWord(@NotNull Processor processor, @NotNull String word, short occurenceMask, @NotNull GlobalSearchScope scope, final boolean caseSensitively) { - for (CacheManager cacheManager : myManagers) { - if (!cacheManager.processFilesWithWord(processor, word, occurenceMask, scope, caseSensitively)) return false; - } - return true; - } - - @NotNull - public PsiFile[] getFilesWithTodoItems() { - List files = null; - for (CacheManager cacheManager : myManagers) { - PsiFile[] items = cacheManager.getFilesWithTodoItems(); - if (items.length != 0 && files == null) { - files = new ArrayList(); - ContainerUtil.addAll(files, items); - } - } - return files == null ? PsiFile.EMPTY_ARRAY : PsiUtilBase.toPsiFileArray(files); - } - - public int getTodoCount(@NotNull VirtualFile file, final IndexPatternProvider patternProvider) { - int count = 0; - for (CacheManager cacheManager : myManagers) { - int todoCount = cacheManager.getTodoCount(file, patternProvider); - if (todoCount == -1) return -1; - count += todoCount; - } - return count; - } - - public int getTodoCount(@NotNull VirtualFile file, IndexPattern pattern) { - int count = 0; - for (CacheManager cacheManager : myManagers) { - int todoCount = cacheManager.getTodoCount(file, pattern); - if (todoCount == -1) return -1; - count += todoCount; - } - return count; - } - - public void addOrInvalidateFile(@NotNull VirtualFile file) { - for (CacheManager cacheManager : myManagers) { - cacheManager.addOrInvalidateFile(file); - } - } -}