mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
we no longer need multiple cache managers; some related cleanup
This commit is contained in:
@@ -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<VirtualFile,PsiDirectory> myDirectories = new THashMap<VirtualFile, PsiDirectory>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
-120
@@ -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<CacheManager> myManagers = new ArrayList<CacheManager>();
|
||||
|
||||
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<CacheUpdater> updaters = new ArrayList<CacheUpdater>();
|
||||
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<PsiFile> processor = new CommonProcessors.CollectProcessor<PsiFile>();
|
||||
processFilesWithWord(processor, word, occurenceMask, scope, caseSensitively);
|
||||
Collection<PsiFile> results = processor.getResults();
|
||||
return PsiUtilBase.toPsiFileArray(results);
|
||||
}
|
||||
|
||||
public boolean processFilesWithWord(@NotNull Processor<PsiFile> 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<PsiFile> files = null;
|
||||
for (CacheManager cacheManager : myManagers) {
|
||||
PsiFile[] items = cacheManager.getFilesWithTodoItems();
|
||||
if (items.length != 0 && files == null) {
|
||||
files = new ArrayList<PsiFile>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user