mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-54226 - simplify JavaFileManager, remove "access only after startup activity" assertion
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.file.impl;
|
||||
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JavaFileManagerImpl extends JavaFileManagerBase {
|
||||
|
||||
public JavaFileManagerImpl(final PsiManagerEx manager, final ProjectRootManager projectRootManager, MessageBus bus,
|
||||
final StartupManager startupManager) {
|
||||
super(manager, projectRootManager, bus);
|
||||
|
||||
if (!((StartupManagerEx)startupManager).startupActivityPassed() &&
|
||||
!ApplicationManager.getApplication().isUnitTestMode() &&
|
||||
!manager.getProject().isDefault()) {
|
||||
Logger.getInstance("#com.intellij.psi.impl.file.impl.JavaFileManagerImpl")
|
||||
.error("Access to psi files should be performed only after startup activity");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-16
@@ -19,6 +19,7 @@ import com.intellij.ProjectTopics;
|
||||
import com.intellij.ide.highlighter.JavaClassFileType;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -32,8 +33,6 @@ import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.Query;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
@@ -43,24 +42,18 @@ import java.util.*;
|
||||
/**
|
||||
* Author: dmitrylomov
|
||||
*/
|
||||
public abstract class JavaFileManagerBase implements JavaFileManager, Disposable {
|
||||
public class JavaFileManagerImpl implements JavaFileManager, Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.file.impl.JavaFileManagerImpl");
|
||||
private final ConcurrentHashMap<GlobalSearchScope, PsiClass> myCachedObjectClassMap = new ConcurrentHashMap<GlobalSearchScope, PsiClass>();
|
||||
private final PsiManagerEx myManager;
|
||||
private final ProjectRootManager myProjectRootManager;
|
||||
private volatile Set<String> myNontrivialPackagePrefixes = null;
|
||||
private boolean myDisposed = false;
|
||||
private final PackageIndex myPackageIndex;
|
||||
protected final MessageBusConnection myConnection;
|
||||
|
||||
public JavaFileManagerBase(
|
||||
final PsiManagerEx manager, final ProjectRootManager projectRootManager,
|
||||
final MessageBus bus) {
|
||||
myManager = manager;
|
||||
myProjectRootManager = projectRootManager;
|
||||
public JavaFileManagerImpl(Project project) {
|
||||
myManager = (PsiManagerEx)PsiManager.getInstance(project);
|
||||
myPackageIndex = PackageIndex.getInstance(myManager.getProject());
|
||||
myConnection = bus.connect();
|
||||
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
|
||||
project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
|
||||
@Override
|
||||
public void rootsChanged(final ModuleRootEvent event) {
|
||||
myNontrivialPackagePrefixes = null;
|
||||
@@ -201,9 +194,10 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
|
||||
@Override
|
||||
public Collection<String> getNonTrivialPackagePrefixes() {
|
||||
if (myNontrivialPackagePrefixes == null) {
|
||||
Set<String> names = new HashSet<String>();
|
||||
final ProjectRootManager rootManager = myProjectRootManager;
|
||||
Set<String> names = myNontrivialPackagePrefixes;
|
||||
if (names == null) {
|
||||
names = new HashSet<String>();
|
||||
final ProjectRootManager rootManager = ProjectRootManager.getInstance(myManager.getProject());
|
||||
final List<VirtualFile> sourceRoots = rootManager.getModuleSourceRoots(JavaModuleSourceRootTypes.SOURCES);
|
||||
final ProjectFileIndex fileIndex = rootManager.getFileIndex();
|
||||
for (final VirtualFile sourceRoot : sourceRoots) {
|
||||
@@ -214,7 +208,7 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
}
|
||||
myNontrivialPackagePrefixes = names;
|
||||
}
|
||||
return myNontrivialPackagePrefixes;
|
||||
return names;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user