require psiManager when need

This commit is contained in:
Vladimir Krivosheev
2019-01-07 17:03:58 +01:00
parent 7272c19b89
commit 9ae0e5776e
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.cache.impl;
@@ -44,11 +30,9 @@ import java.util.Set;
*/
public class IndexTodoCacheManagerImpl implements TodoCacheManager {
private final Project myProject;
private final PsiManager myPsiManager;
public IndexTodoCacheManagerImpl(PsiManager psiManager) {
myPsiManager = psiManager;
myProject = psiManager.getProject();
public IndexTodoCacheManagerImpl(@NotNull Project project) {
myProject = project;
}
@Override
@@ -64,10 +48,11 @@ public class IndexTodoCacheManagerImpl implements TodoCacheManager {
final Collection<VirtualFile> files = fileBasedIndex.getContainingFiles(
TodoIndex.NAME,
new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), GlobalSearchScope.allScope(myProject));
PsiManager psiManager = PsiManager.getInstance(myProject);
ApplicationManager.getApplication().runReadAction(() -> {
for (VirtualFile file : files) {
if (projectFileIndex.isInContent(file)) {
final PsiFile psiFile = myPsiManager.findFile(file);
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile != null) {
allFiles.add(psiFile);
}