remove deprecated ComponentManager.getPicoContainer

GitOrigin-RevId: bd40e0f4255fcdc014c2591cf3a93b6015ed26ff
This commit is contained in:
Vladimir Krivosheev
2023-05-04 10:01:50 +02:00
committed by intellij-monorepo-bot
parent 8ef0fe70e6
commit 5754420093
17 changed files with 163 additions and 244 deletions

View File

@@ -24,7 +24,7 @@ public class RegExpParsingTest extends ParsingTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
myProject.registerService(SmartPointerManager.class, new MockSmartPointerManager());
project.registerService(SmartPointerManager.class, new MockSmartPointerManager());
}
@Override

View File

@@ -65,11 +65,11 @@ public class JavaCoreApplicationEnvironment extends CoreApplicationEnvironment {
registerApplicationExtensionPoint(ContainerProvider.EP_NAME, ContainerProvider.class);
addExtension(ContainerProvider.EP_NAME, new JavaContainerProvider());
myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper());
application.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper());
myApplication.registerService(PsiSubstitutorFactory.class, new PsiSubstitutorFactoryImpl());
myApplication.registerService(JavaDirectoryService.class, createJavaDirectoryService());
myApplication.registerService(JavaVersionService.class, new JavaVersionService());
application.registerService(PsiSubstitutorFactory.class, new PsiSubstitutorFactoryImpl());
application.registerService(JavaDirectoryService.class, createJavaDirectoryService());
application.registerService(JavaVersionService.class, new JavaVersionService());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiPackage.class, new PackagePresentationProvider());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiClass.class, new ClassPresentationProvider());

View File

@@ -37,34 +37,34 @@ public class JavaCoreProjectEnvironment extends CoreProjectEnvironment {
public JavaCoreProjectEnvironment(@NotNull Disposable parentDisposable, @NotNull CoreApplicationEnvironment applicationEnvironment) {
super(parentDisposable, applicationEnvironment);
myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myProject));
myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper());
myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myProject));
myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension());
myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myProject));
myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade());
myProject.registerService(JavaFileCodeStyleFacade.class, new CoreJavaFileCodeStyleFacade());
myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager());
myProject.registerService(ControlFlowFactory.class, new ControlFlowFactory(myProject));
project.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(project));
project.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper());
project.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(project));
project.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension());
project.registerService(JavaResolveCache.class, new JavaResolveCache(project));
project.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade());
project.registerService(JavaFileCodeStyleFacade.class, new CoreJavaFileCodeStyleFacade());
project.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager());
project.registerService(ControlFlowFactory.class, new ControlFlowFactory(project));
myPackageIndex = createCorePackageIndex();
myProject.registerService(PackageIndex.class, myPackageIndex);
project.registerService(PackageIndex.class, myPackageIndex);
myFileManager = createCoreFileManager();
myProject.registerService(JavaFileManager.class, myFileManager);
project.registerService(JavaFileManager.class, myFileManager);
myProject.registerService(JvmPsiConversionHelper.class, new JvmPsiConversionHelperImpl());
project.registerService(JvmPsiConversionHelper.class, new JvmPsiConversionHelperImpl());
registerJavaPsiFacade();
myProject.registerService(JvmFacade.class, new JvmFacadeImpl(myProject));
project.registerService(JvmFacade.class, new JvmFacadeImpl(project));
}
protected void registerJavaPsiFacade() {
JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject);
myProject.registerService(JavaPsiFacade.class, javaPsiFacade);
JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(project);
project.registerService(JavaPsiFacade.class, javaPsiFacade);
}
protected CoreJavaPsiImplementationHelper createJavaPsiImplementationHelper() {
return new CoreJavaPsiImplementationHelper(myProject);
return new CoreJavaPsiImplementationHelper(project);
}
protected JavaFileManager createCoreFileManager() {

View File

@@ -59,12 +59,11 @@ import java.util.List;
public class CoreApplicationEnvironment {
private final CoreFileTypeRegistry myFileTypeRegistry;
protected final MockApplication myApplication;
protected final MockApplication application;
private final CoreLocalFileSystem myLocalFileSystem;
@NotNull
protected final VirtualFileSystem myJarFileSystem;
protected final @NotNull VirtualFileSystem myJarFileSystem;
private final VirtualFileSystem myJrtFileSystem;
@NotNull private final Disposable myParentDisposable;
private final @NotNull Disposable myParentDisposable;
private final boolean myUnitTestMode;
public CoreApplicationEnvironment(@NotNull Disposable parentDisposable) {
@@ -79,8 +78,8 @@ public class CoreApplicationEnvironment {
myFileTypeRegistry = new CoreFileTypeRegistry();
myApplication = createApplication(myParentDisposable);
ApplicationManager.setApplication(myApplication,
application = createApplication(myParentDisposable);
ApplicationManager.setApplication(application,
() -> myFileTypeRegistry,
myParentDisposable);
myLocalFileSystem = createLocalFileSystem();
@@ -111,22 +110,20 @@ public class CoreApplicationEnvironment {
registerApplicationService(CommandProcessor.class, new CoreCommandProcessor());
registerApplicationService(GraphAlgorithms.class, new GraphAlgorithmsImpl());
myApplication.registerService(ApplicationInfo.class, ApplicationInfoImpl.class);
application.registerService(ApplicationInfo.class, ApplicationInfoImpl.class);
registerApplicationExtensionPoint(DynamicBundle.LanguageBundleEP.EP_NAME, DynamicBundle.LanguageBundleEP.class);
}
public <T> void registerApplicationService(@NotNull Class<T> serviceInterface, @NotNull T serviceImplementation) {
myApplication.registerService(serviceInterface, serviceImplementation);
application.registerService(serviceInterface, serviceImplementation);
}
@NotNull
protected VirtualFilePointerManager createVirtualFilePointerManager() {
protected @NotNull VirtualFilePointerManager createVirtualFilePointerManager() {
return new CoreVirtualFilePointerManager();
}
@NotNull
protected MockApplication createApplication(@NotNull Disposable parentDisposable) {
protected @NotNull MockApplication createApplication(@NotNull Disposable parentDisposable) {
return new MockApplication(parentDisposable) {
@Override
public boolean isUnitTestMode() {
@@ -135,45 +132,38 @@ public class CoreApplicationEnvironment {
};
}
@NotNull
protected JobLauncher createJobLauncher() {
protected @NotNull JobLauncher createJobLauncher() {
return new CoreJobLauncher();
}
@NotNull
protected ProgressManager createProgressIndicatorProvider() {
protected @NotNull ProgressManager createProgressIndicatorProvider() {
return new CoreProgressManager();
}
@NotNull
protected VirtualFileSystem createJarFileSystem() {
protected @NotNull VirtualFileSystem createJarFileSystem() {
return new CoreJarFileSystem();
}
@NotNull
protected CoreLocalFileSystem createLocalFileSystem() {
protected @NotNull CoreLocalFileSystem createLocalFileSystem() {
return new CoreLocalFileSystem();
}
@Nullable
protected VirtualFileSystem createJrtFileSystem() {
protected @Nullable VirtualFileSystem createJrtFileSystem() {
return null;
}
@NotNull
public MockApplication getApplication() {
return myApplication;
public @NotNull MockApplication getApplication() {
return application;
}
@NotNull
public Disposable getParentDisposable() {
public @NotNull Disposable getParentDisposable() {
return myParentDisposable;
}
public <T> void registerApplicationComponent(@NotNull Class<T> interfaceClass, @NotNull T implementation) {
registerComponentInstance(myApplication.getPicoContainer(), interfaceClass, implementation);
registerComponentInstance(application.getPicoContainer(), interfaceClass, implementation);
if (implementation instanceof Disposable) {
Disposer.register(myApplication, (Disposable)implementation);
Disposer.register(application, (Disposable)implementation);
}
}
@@ -198,15 +188,15 @@ public class CoreApplicationEnvironment {
addExplicitExtension(LanguageParserDefinitions.INSTANCE, language, parserDefinition);
}
public <T> void addExplicitExtension(@NotNull final FileTypeExtension<T> instance, @NotNull final FileType fileType, @NotNull final T object) {
public <T> void addExplicitExtension(final @NotNull FileTypeExtension<T> instance, final @NotNull FileType fileType, final @NotNull T object) {
instance.addExplicitExtension(fileType, object, myParentDisposable);
}
public <T> void addExplicitExtension(@NotNull final ClassExtension<T> instance, @NotNull final Class aClass, @NotNull final T object) {
public <T> void addExplicitExtension(final @NotNull ClassExtension<T> instance, final @NotNull Class aClass, final @NotNull T object) {
instance.addExplicitExtension(aClass, object, myParentDisposable);
}
public <T> void addExtension(@NotNull ExtensionPointName<T> name, @NotNull final T extension) {
public <T> void addExtension(@NotNull ExtensionPointName<T> name, final @NotNull T extension) {
final ExtensionPoint<T> extensionPoint = Extensions.getRootArea().getExtensionPoint(name);
//noinspection TestOnlyProblems
extensionPoint.registerExtension(extension, myParentDisposable);
@@ -255,18 +245,15 @@ public class CoreApplicationEnvironment {
descriptor.registerExtensions(areaImpl.extensionPoints, descriptor.appContainerDescriptor, null);
}
@NotNull
public CoreLocalFileSystem getLocalFileSystem() {
public @NotNull CoreLocalFileSystem getLocalFileSystem() {
return myLocalFileSystem;
}
@NotNull
public VirtualFileSystem getJarFileSystem() {
public @NotNull VirtualFileSystem getJarFileSystem() {
return myJarFileSystem;
}
@Nullable
public VirtualFileSystem getJrtFileSystem() {
public @Nullable VirtualFileSystem getJrtFileSystem() {
return myJrtFileSystem;
}
}

View File

@@ -31,38 +31,38 @@ public class CoreProjectEnvironment {
protected final FileIndexFacade myFileIndexFacade;
protected final PsiManagerImpl myPsiManager;
protected final MockProject myProject;
protected final MockProject project;
public CoreProjectEnvironment(@NotNull Disposable parentDisposable, @NotNull CoreApplicationEnvironment applicationEnvironment) {
myParentDisposable = parentDisposable;
myEnvironment = applicationEnvironment;
myProject = createProject(myEnvironment.getApplication().getPicoContainer(), myParentDisposable);
project = createProject(myEnvironment.getApplication().getPicoContainer(), myParentDisposable);
preregisterServices();
myFileIndexFacade = createFileIndexFacade();
PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(myProject);
myProject.registerService(PsiModificationTracker.class, modificationTracker);
myProject.registerService(FileIndexFacade.class, myFileIndexFacade);
myProject.registerService(ResolveCache.class, new ResolveCache(myProject));
PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(project);
project.registerService(PsiModificationTracker.class, modificationTracker);
project.registerService(FileIndexFacade.class, myFileIndexFacade);
project.registerService(ResolveCache.class, new ResolveCache(project));
myPsiManager = new PsiManagerImpl(myProject);
myProject.registerService(PsiManager.class, myPsiManager);
myProject.registerService(SmartPointerManager.class, SmartPointerManagerImpl.class);
myProject.registerService(DocumentCommitProcessor.class, new MockDocumentCommitProcessor());
myProject.registerService(PsiDocumentManager.class, new CorePsiDocumentManager(myProject));
myPsiManager = new PsiManagerImpl(project);
project.registerService(PsiManager.class, myPsiManager);
project.registerService(SmartPointerManager.class, SmartPointerManagerImpl.class);
project.registerService(DocumentCommitProcessor.class, new MockDocumentCommitProcessor());
project.registerService(PsiDocumentManager.class, new CorePsiDocumentManager(project));
myProject.registerService(ResolveScopeManager.class, createResolveScopeManager(myPsiManager));
project.registerService(ResolveScopeManager.class, createResolveScopeManager(myPsiManager));
myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager));
myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myProject)));
myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myProject));
myProject.registerService(ProjectScopeBuilder.class, createProjectScopeBuilder());
myProject.registerService(DumbService.class, new MockDumbService(myProject));
myProject.registerService(DumbUtil.class, new MockDumbUtil());
myProject.registerService(CoreEncodingProjectManager.class, CoreEncodingProjectManager.class);
myProject.registerService(InjectedLanguageManager.class, new CoreInjectedLanguageManager());
project.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager));
project.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(project, new PsiCachedValuesFactory(project)));
project.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(project));
project.registerService(ProjectScopeBuilder.class, createProjectScopeBuilder());
project.registerService(DumbService.class, new MockDumbService(project));
project.registerService(DumbUtil.class, new MockDumbUtil());
project.registerService(CoreEncodingProjectManager.class, CoreEncodingProjectManager.class);
project.registerService(InjectedLanguageManager.class, new CoreInjectedLanguageManager());
}
@NotNull
@@ -72,7 +72,7 @@ public class CoreProjectEnvironment {
@NotNull
protected ProjectScopeBuilder createProjectScopeBuilder() {
return new CoreProjectScopeBuilder(myProject, myFileIndexFacade);
return new CoreProjectScopeBuilder(project, myFileIndexFacade);
}
protected void preregisterServices() {
@@ -81,7 +81,7 @@ public class CoreProjectEnvironment {
@NotNull
protected FileIndexFacade createFileIndexFacade() {
return new MockFileIndexFacade(myProject);
return new MockFileIndexFacade(project);
}
@NotNull
@@ -91,13 +91,13 @@ public class CoreProjectEnvironment {
public <T> void addProjectExtension(@NotNull ExtensionPointName<T> name, @NotNull final T extension) {
//noinspection TestOnlyProblems
name.getPoint(myProject).registerExtension(extension, myParentDisposable);
name.getPoint(project).registerExtension(extension, myParentDisposable);
}
public <T> void registerProjectComponent(@NotNull Class<T> interfaceClass, @NotNull T implementation) {
CoreApplicationEnvironment.registerComponentInstance(myProject.getPicoContainer(), interfaceClass, implementation);
CoreApplicationEnvironment.registerComponentInstance(project.getPicoContainer(), interfaceClass, implementation);
if (implementation instanceof Disposable) {
Disposer.register(myProject, (Disposable) implementation);
Disposer.register(project, (Disposable) implementation);
}
}
@@ -113,6 +113,6 @@ public class CoreProjectEnvironment {
@NotNull
public MockProject getProject() {
return myProject;
return project;
}
}

View File

@@ -36,17 +36,15 @@ public class MockApplication extends MockComponentManager implements Application
Extensions.setRootArea(getExtensionArea(), parentDisposable);
}
@NotNull
@TestOnly
public static MockApplication setUp(@NotNull Disposable parentDisposable) {
public static @NotNull MockApplication setUp(@NotNull Disposable parentDisposable) {
MockApplication app = new MockApplication(parentDisposable);
ApplicationManager.setApplication(app, parentDisposable);
return app;
}
@Nullable
@Override
public final <T> T getServiceIfCreated(@NotNull Class<T> serviceClass) {
public final @Nullable <T> T getServiceIfCreated(@NotNull Class<T> serviceClass) {
return doGetService(serviceClass, false);
}
@@ -151,15 +149,13 @@ public class MockApplication extends MockComponentManager implements Application
return true;
}
@NotNull
@Override
public Future<?> executeOnPooledThread(@NotNull Runnable action) {
public @NotNull Future<?> executeOnPooledThread(@NotNull Runnable action) {
return AppExecutorUtil.getAppExecutorService().submit(action);
}
@NotNull
@Override
public <T> Future<T> executeOnPooledThread(@NotNull Callable<T> action) {
public @NotNull <T> Future<T> executeOnPooledThread(@NotNull Callable<T> action) {
return AppExecutorUtil.getAppExecutorService().submit(action);
}
@@ -213,15 +209,13 @@ public class MockApplication extends MockComponentManager implements Application
return computation.compute();
}
@NotNull
@Override
public AccessToken acquireReadActionLock() {
public @NotNull AccessToken acquireReadActionLock() {
return AccessToken.EMPTY_ACCESS_TOKEN;
}
@NotNull
@Override
public AccessToken acquireWriteActionLock(@Nullable Class<?> marker) {
public @NotNull AccessToken acquireWriteActionLock(@Nullable Class<?> marker) {
return AccessToken.EMPTY_ACCESS_TOKEN;
}
@@ -252,18 +246,17 @@ public class MockApplication extends MockComponentManager implements Application
return 0;
}
@NotNull
@Override
public ModalityState getNoneModalityState() {
public @NotNull ModalityState getNoneModalityState() {
return ModalityState.NON_MODAL;
}
@Override
public void invokeLater(@NotNull final Runnable runnable, @NotNull final Condition<?> expired) {
public void invokeLater(final @NotNull Runnable runnable, final @NotNull Condition<?> expired) {
}
@Override
public void invokeLater(@NotNull final Runnable runnable, @NotNull final ModalityState state, @NotNull final Condition<?> expired) {
public void invokeLater(final @NotNull Runnable runnable, final @NotNull ModalityState state, final @NotNull Condition<?> expired) {
}
@Override
@@ -276,8 +269,7 @@ public class MockApplication extends MockComponentManager implements Application
@Deprecated
@Override
@NotNull
public ModalityInvokator getInvokator() {
public @NotNull ModalityInvokator getInvokator() {
throw new UnsupportedOperationException();
}
@@ -301,27 +293,23 @@ public class MockApplication extends MockComponentManager implements Application
invokeAndWait(runnable, getDefaultModalityState());
}
@NotNull
@Override
public ModalityState getCurrentModalityState() {
public @NotNull ModalityState getCurrentModalityState() {
return getNoneModalityState();
}
@NotNull
@Override
public ModalityState getAnyModalityState() {
public @NotNull ModalityState getAnyModalityState() {
return AnyModalityState.ANY;
}
@NotNull
@Override
public ModalityState getModalityStateForComponent(@NotNull Component c) {
public @NotNull ModalityState getModalityStateForComponent(@NotNull Component c) {
return getNoneModalityState();
}
@NotNull
@Override
public ModalityState getDefaultModalityState() {
public @NotNull ModalityState getDefaultModalityState() {
return getNoneModalityState();
}
@@ -358,7 +346,7 @@ public class MockApplication extends MockComponentManager implements Application
}
@Override
public void assertIsDispatchThread(@Nullable final JComponent component) {
public void assertIsDispatchThread(final @Nullable JComponent component) {
}
@Override

View File

@@ -23,7 +23,6 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.PicoContainer;
import java.util.HashMap;
@@ -32,7 +31,7 @@ import java.util.Set;
public class MockComponentManager extends UserDataHolderBase implements ComponentManager, MessageBusOwner {
private final MessageBus myMessageBus = MessageBusFactoryImpl.createRootBus(this);
private final DefaultPicoContainer myPicoContainer;
private final DefaultPicoContainer picoContainer;
private final ExtensionsAreaImpl myExtensionArea;
private final Map<Class<?>, Object> myComponents = new HashMap<>();
@@ -40,7 +39,7 @@ public class MockComponentManager extends UserDataHolderBase implements Componen
private boolean myDisposed;
public MockComponentManager(@Nullable PicoContainer parent, @NotNull Disposable parentDisposable) {
myPicoContainer = new DefaultPicoContainer((DefaultPicoContainer)parent) {
picoContainer = new DefaultPicoContainer((DefaultPicoContainer)parent) {
@Override
public @Nullable Object getComponentInstance(@NotNull Object componentKey) {
if (myDisposed) {
@@ -53,11 +52,15 @@ public class MockComponentManager extends UserDataHolderBase implements Componen
}
};
myPicoContainer.registerComponentInstance(getClass(), this);
picoContainer.registerComponentInstance(getClass(), this);
myExtensionArea = new ExtensionsAreaImpl(this);
Disposer.register(parentDisposable, this);
}
public DefaultPicoContainer getPicoContainer() {
return picoContainer;
}
@Override
public @NotNull ExtensionsAreaImpl getExtensionArea() {
return myExtensionArea;
@@ -96,8 +99,8 @@ public class MockComponentManager extends UserDataHolderBase implements Componen
}
public <T> void registerService(@NotNull Class<T> serviceInterface, @NotNull Class<? extends T> serviceImplementation) {
myPicoContainer.unregisterComponent(serviceInterface.getName());
myPicoContainer.registerComponentImplementation(serviceInterface.getName(), serviceImplementation);
picoContainer.unregisterComponent(serviceInterface.getName());
picoContainer.registerComponentImplementation(serviceInterface.getName(), serviceImplementation);
}
public <T> void registerService(@NotNull Class<T> serviceImplementation) {
@@ -105,14 +108,14 @@ public class MockComponentManager extends UserDataHolderBase implements Componen
}
public <T> void registerService(@NotNull Class<T> serviceInterface, @NotNull T serviceImplementation) {
myPicoContainer.registerComponentInstance(serviceInterface.getName(), serviceImplementation);
picoContainer.registerComponentInstance(serviceInterface.getName(), serviceImplementation);
registerComponentInDisposer(serviceImplementation);
}
public <T> void registerService(@NotNull Class<T> serviceInterface, @NotNull T serviceImplementation, @NotNull Disposable parentDisposable) {
String key = serviceInterface.getName();
registerService(serviceInterface, serviceImplementation);
Disposer.register(parentDisposable, () -> myPicoContainer.unregisterComponent(key));
Disposer.register(parentDisposable, () -> picoContainer.unregisterComponent(key));
}
public <T> void addComponent(@NotNull Class<T> interfaceClass, @NotNull T instance) {
@@ -122,25 +125,20 @@ public class MockComponentManager extends UserDataHolderBase implements Componen
@Override
public @Nullable <T> T getComponent(@NotNull Class<T> interfaceClass) {
final Object o = myPicoContainer.getComponentInstance(interfaceClass);
final Object o = picoContainer.getComponentInstance(interfaceClass);
//noinspection unchecked
return (T)(o != null ? o : myComponents.get(interfaceClass));
}
@Override
public <T> T getService(@NotNull Class<T> serviceClass) {
T result = myPicoContainer.getService(serviceClass);
T result = picoContainer.getService(serviceClass);
registerComponentInDisposer(result);
return result;
}
@Override
public final @NotNull MutablePicoContainer getPicoContainer() {
return myPicoContainer;
}
public final ComponentAdapter getComponentAdapter(@NotNull Object componentKey) {
return myPicoContainer.getComponentAdapter(componentKey);
return picoContainer.getComponentAdapter(componentKey);
}
@Override

View File

@@ -9,7 +9,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.pico.DefaultPicoContainer;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.GlobalScope;
import org.jetbrains.annotations.NonNls;
@@ -99,8 +98,7 @@ public class MockProject extends MockComponentManager implements Project {
public @NotNull <T> List<T> getComponentInstancesOfType(@NotNull Class<T> componentType) {
List<T> result = new ArrayList<>();
DefaultPicoContainer container = (DefaultPicoContainer)getPicoContainer();
container.getComponentAdapters().forEach(componentAdapter -> {
getPicoContainer().getComponentAdapters().forEach(componentAdapter -> {
Class<?> descendant = componentAdapter.getComponentImplementation();
if (componentType == descendant || componentType.isAssignableFrom(descendant)) {
//noinspection unchecked

View File

@@ -14,7 +14,6 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.picocontainer.PicoContainer;
import java.util.Collections;
import java.util.List;
@@ -48,20 +47,12 @@ public interface ComponentManager extends UserDataHolder, Disposable, AreaInstan
/**
* Checks whether there is a component with the specified interface class.
*
* @param interfaceClass interface class of component to be checked
* @param interfaceClass interface class of a component to be checked
* @return {@code true} if there is a component with the specified interface class;
* {@code false} otherwise
*/
boolean hasComponent(@NotNull Class<?> interfaceClass);
/**
* @deprecated Use ComponentManager API
*/
@Deprecated
@ApiStatus.Internal
@ApiStatus.ScheduledForRemoval
@NotNull PicoContainer getPicoContainer();
@ApiStatus.Internal
boolean isInjectionForExtensionSupported();

View File

@@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.After;
import org.junit.Test;
import org.picocontainer.PicoContainer;
import java.util.*;
import java.util.function.BiConsumer;
@@ -367,11 +366,6 @@ public class ExtensionPointImplTest {
throw new UnsupportedOperationException();
}
@Override
public @NotNull PicoContainer getPicoContainer() {
throw new UnsupportedOperationException();
}
@Override
public boolean isInjectionForExtensionSupported() {
return false;

View File

@@ -18,7 +18,6 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.SystemIndependent;
import org.picocontainer.PicoContainer;
import java.util.Map;
@@ -86,11 +85,6 @@ public final class DummyProject extends UserDataHolderBase implements Project {
return false;
}
@Override
public @NotNull PicoContainer getPicoContainer() {
throw new UnsupportedOperationException("getPicoContainer is not implement in : " + getClass());
}
@Override
public boolean isInjectionForExtensionSupported() {
return false;

View File

@@ -25,7 +25,6 @@ import com.intellij.serviceContainer.ComponentManagerImpl;
import com.intellij.util.messages.MessageBus;
import kotlinx.coroutines.CoroutineScope;
import org.jetbrains.annotations.*;
import org.picocontainer.PicoContainer;
import java.util.Map;
@@ -230,11 +229,6 @@ final class DefaultProject extends UserDataHolderBase implements Project {
return getDelegate().getComponent(interfaceClass);
}
@Override
public @NotNull PicoContainer getPicoContainer() {
throw new UnsupportedOperationException();
}
@Override
public boolean isInjectionForExtensionSupported() {
return true;

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("ReplaceNegatedIsEmptyWithIsNotEmpty", "ReplaceGetOrSet", "ReplacePutWithAssignment", "OVERRIDE_DEPRECATION")
@file:Suppress("ReplaceNegatedIsEmptyWithIsNotEmpty", "ReplaceGetOrSet", "ReplacePutWithAssignment")
package com.intellij.serviceContainer
import com.intellij.concurrency.resetThreadContext
@@ -17,6 +17,7 @@ import com.intellij.openapi.components.ServiceDescriptor.PreloadMode
import com.intellij.openapi.components.impl.stores.IComponentStore
import com.intellij.openapi.diagnostic.Attachment
import com.intellij.openapi.diagnostic.ControlFlowException
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.extensions.*
import com.intellij.openapi.extensions.impl.ExtensionPointImpl
@@ -40,7 +41,6 @@ import kotlinx.coroutines.*
import org.jetbrains.annotations.ApiStatus.Internal
import org.jetbrains.annotations.TestOnly
import org.picocontainer.ComponentAdapter
import org.picocontainer.PicoContainer
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodType
@@ -55,7 +55,9 @@ import java.util.concurrent.atomic.AtomicReference
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
internal val LOG = logger<ComponentManagerImpl>()
internal val LOG: Logger
get() = logger<ComponentManagerImpl>()
private val constructorParameterResolver = ConstructorParameterResolver()
private val methodLookup = MethodHandles.lookup()
private val emptyConstructorMethodType = MethodType.methodType(Void.TYPE)
@@ -148,9 +150,11 @@ abstract class ComponentManagerImpl(
@Volatile
private var isServicePreloadingCancelled = false
private fun debugString(short: Boolean = false): String = "${if (short) javaClass.simpleName else javaClass.name}@${System.identityHashCode(this)}"
private fun debugString(short: Boolean = false): String {
return "${if (short) javaClass.simpleName else javaClass.name}@${System.identityHashCode(this)}"
}
internal val serviceParentDisposable = Disposer.newDisposable("services of ${debugString()}")
internal val serviceParentDisposable: Disposable = Disposer.newDisposable("services of ${debugString()}")
protected open val isLightServiceSupported = parent?.parent == null
protected open val isMessageBusSupported = parent?.parent == null
@@ -191,16 +195,6 @@ abstract class ComponentManagerImpl(
}
}
private val picoContainerAdapter: PicoContainer = object : PicoContainer {
override fun getComponentInstance(componentKey: Any): Any? {
return this@ComponentManagerImpl.getComponentInstance(componentKey)
}
override fun getComponentInstanceOfType(componentType: Class<*>): Any? {
throw UnsupportedOperationException("Do not use getComponentInstanceOfType()")
}
}
internal fun getComponentInstance(componentKey: Any): Any? {
assertComponentsSupported()
@@ -209,12 +203,6 @@ abstract class ComponentManagerImpl(
return if (adapter == null) parent?.getComponentInstance(componentKey) else adapter.componentInstance
}
@Deprecated("Use ComponentManager API", level = DeprecationLevel.ERROR)
final override fun getPicoContainer(): PicoContainer {
checkState()
return picoContainerAdapter
}
private fun registerAdapter(componentAdapter: ComponentAdapter, pluginDescriptor: PluginDescriptor?) {
if (componentKeyToAdapter.putIfAbsent(componentAdapter.componentKey, componentAdapter) != null) {
val error = "Key ${componentAdapter.componentKey} duplicated"
@@ -292,8 +280,8 @@ abstract class ComponentManagerImpl(
var activity = activityNamePrefix?.let { StartUpMeasurer.startActivity("${it}service and ep registration") }
// register services before registering extensions because plugins can access services in their
// extensions which can be invoked right away if the plugin is loaded dynamically
// register services before registering extensions because plugins can access services in their extensions,
// which can be invoked right away if the plugin is loaded dynamically
val extensionPoints = if (precomputedExtensionModel == null) HashMap(extensionArea.extensionPoints) else null
for (rootModule in modules) {
executeRegisterTask(rootModule) { module ->
@@ -1488,7 +1476,7 @@ abstract class ComponentManagerImpl(
* Key: plugin coroutine scope.
* Value: intersection of this container scope and plugin coroutine scope.
*/
private val pluginScopes: AtomicReference<PersistentMap<CoroutineScope, CoroutineScope>> = AtomicReference(persistentHashMapOf())
private val pluginScopes = AtomicReference<PersistentMap<CoroutineScope, CoroutineScope>>(persistentHashMapOf())
internal fun instanceCoroutineScope(pluginClass: Class<*>): CoroutineScope {
val pluginClassloader = pluginClass.classLoader
@@ -1498,10 +1486,11 @@ abstract class ComponentManagerImpl(
?: pluginScope
intersectionCoroutineScope(parentScope)
}
else { // non-unloadable
else {
// non-unloadable
getCoroutineScope()
}
// The parent scope should become cancelled only when the container is disposed, or the plugin is unloaded.
// The parent scope should become canceled only when the container is disposed, or the plugin is unloaded.
// Leaking the parent scope might lead to premature cancellation.
// Fool proofing: a fresh child scope is created per instance to avoid leaking the parent to clients.
return intersectionScope.namedChildScope(pluginClass.name)
@@ -1540,7 +1529,7 @@ abstract class ComponentManagerImpl(
}
private fun removePluginScope(pluginScope: CoroutineScope) {
pluginScopes.updateAndGet { scopes: PersistentMap<CoroutineScope, CoroutineScope> ->
pluginScopes.updateAndGet { scopes ->
scopes.remove(pluginScope)
}
}

View File

@@ -20,7 +20,7 @@ public class MockModule extends MockComponentManager implements Module {
this(null, parentDisposable);
}
public MockModule(@Nullable final Project project, @NotNull Disposable parentDisposable) {
public MockModule(@Nullable MockProject project, @NotNull Disposable parentDisposable) {
super(project == null ? null : project.getPicoContainer(), parentDisposable);
myProject = project;
}
@@ -31,14 +31,12 @@ public class MockModule extends MockComponentManager implements Module {
}
@Override
@NotNull
public Path getModuleNioFile() {
public @NotNull Path getModuleNioFile() {
return Paths.get("");
}
@NotNull
@Override
public GlobalSearchScope getModuleRuntimeScope(final boolean includeTests) {
public @NotNull GlobalSearchScope getModuleRuntimeScope(final boolean includeTests) {
return new MockGlobalSearchScope();
}
@@ -52,65 +50,55 @@ public class MockModule extends MockComponentManager implements Module {
throw new UnsupportedOperationException("Method getModuleTestSourceScope is not yet implemented in " + getClass().getName());
}
@NotNull
@Override
public GlobalSearchScope getModuleScope() {
public @NotNull GlobalSearchScope getModuleScope() {
return new MockGlobalSearchScope();
}
@NotNull
@Override
public GlobalSearchScope getModuleScope(boolean includeTests) {
public @NotNull GlobalSearchScope getModuleScope(boolean includeTests) {
return new MockGlobalSearchScope();
}
@NotNull
@Override
public GlobalSearchScope getModuleTestsWithDependentsScope() {
public @NotNull GlobalSearchScope getModuleTestsWithDependentsScope() {
return new MockGlobalSearchScope();
}
@NotNull
@Override
public GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(final boolean includeTests) {
public @NotNull GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(final boolean includeTests) {
return new MockGlobalSearchScope();
//throw new UnsupportedOperationException( "Method getModuleWithDependenciesAndLibrariesScope is not yet implemented in " + getClass().getName());
}
@NotNull
@Override
public GlobalSearchScope getModuleWithDependenciesScope() {
public @NotNull GlobalSearchScope getModuleWithDependenciesScope() {
return new MockGlobalSearchScope();
}
@NotNull
@Override
public GlobalSearchScope getModuleContentWithDependenciesScope() {
public @NotNull GlobalSearchScope getModuleContentWithDependenciesScope() {
throw new UnsupportedOperationException("Method getModuleContentWithDependenciesScope is not yet implemented in " + getClass().getName());
}
@NotNull
@Override
public GlobalSearchScope getModuleContentScope() {
public @NotNull GlobalSearchScope getModuleContentScope() {
throw new UnsupportedOperationException("Method getModuleContentScope is not yet implemented in " + getClass().getName());
}
@NotNull
@Override
public GlobalSearchScope getModuleWithDependentsScope() {
public @NotNull GlobalSearchScope getModuleWithDependentsScope() {
throw new UnsupportedOperationException("Method getModuleWithDependentsScope is not yet implemented in " + getClass().getName());
}
@NotNull
@Override
public GlobalSearchScope getModuleWithLibrariesScope() {
public @NotNull GlobalSearchScope getModuleWithLibrariesScope() {
throw new UnsupportedOperationException("Method getModuleWithLibrariesScope is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public String getName() {
public @NotNull String getName() {
return myName;
}
@@ -125,19 +113,17 @@ public class MockModule extends MockComponentManager implements Module {
}
@Override
@Nullable
public String getOptionValue(@NotNull final String optionName) {
public @Nullable String getOptionValue(@NotNull String optionName) {
throw new UnsupportedOperationException("Method getOptionValue is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public Project getProject() {
public @NotNull Project getProject() {
return myProject;
}
@Override
public void setOption(@NotNull final String optionName, @NotNull final String optionValue) {
public void setOption(@NotNull String optionName, @Nullable String optionValue) {
throw new UnsupportedOperationException("Method setOption is not yet implemented in " + getClass().getName());
}
}

View File

@@ -4,7 +4,6 @@ package com.intellij.mock;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ComponentManagerEx;
import com.intellij.openapi.project.ex.ProjectEx;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,7 +16,7 @@ public class MockProjectEx extends MockProject implements ProjectEx {
private static @Nullable PicoContainer getParentContainer() {
Application app = ApplicationManager.getApplication();
return app == null || app instanceof ComponentManagerEx ? null : app.getPicoContainer();
return app instanceof MockApplication ? ((MockApplication)app).getPicoContainer() : null;
}
@Override

View File

@@ -62,10 +62,10 @@ import java.util.*;
/** @noinspection JUnitTestCaseWithNonTrivialConstructors*/
public abstract class ParsingTestCase extends UsefulTestCase {
private PluginDescriptor myPluginDescriptor;
private PluginDescriptor pluginDescriptor;
private MockApplication myApp;
protected MockProjectEx myProject;
private MockApplication app;
protected MockProjectEx project;
protected String myFilePrefix = "";
protected String myFileExt;
@@ -91,7 +91,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
@NotNull
protected MockApplication getApplication() {
return myApp;
return app;
}
@Override
@@ -99,7 +99,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
super.setUp();
MockApplication app = MockApplication.setUp(getTestRootDisposable());
myApp = app;
this.app = app;
MutablePicoContainer appContainer = app.getPicoContainer();
ComponentAdapter component = appContainer.getComponentAdapter(ProgressManager.class.getName());
if (component == null) {
@@ -107,8 +107,8 @@ public abstract class ParsingTestCase extends UsefulTestCase {
}
IdeaForkJoinWorkerThreadFactory.setupForkJoinCommonPool(true);
myProject = new MockProjectEx(getTestRootDisposable());
myPsiManager = new MockPsiManager(myProject);
project = new MockProjectEx(getTestRootDisposable());
myPsiManager = new MockPsiManager(project);
myFileFactory = new PsiFileFactoryImpl(myPsiManager);
appContainer.registerComponentInstance(MessageBus.class, app.getMessageBus());
appContainer.registerComponentInstance(SchemeManagerFactory.class, new MockSchemeManagerFactory());
@@ -121,11 +121,11 @@ public abstract class ParsingTestCase extends UsefulTestCase {
app.registerService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
app.registerService(DefaultASTFactory.class, new DefaultASTFactoryImpl());
app.registerService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl());
myProject.registerService(PsiDocumentManager.class, new MockPsiDocumentManager());
myProject.registerService(PsiManager.class, myPsiManager);
myProject.registerService(TreeAspect.class, new TreeAspect());
myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myProject)));
myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject, myProject.getCoroutineScope()));
project.registerService(PsiDocumentManager.class, new MockPsiDocumentManager());
project.registerService(PsiManager.class, myPsiManager);
project.registerService(TreeAspect.class, new TreeAspect());
project.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(project, new PsiCachedValuesFactory(project)));
project.registerService(StartupManager.class, new StartupManagerImpl(project, project.getCoroutineScope()));
registerExtensionPoint(app.getExtensionArea(), FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
registerExtensionPoint(app.getExtensionArea(), MetaLanguage.EP_NAME, MetaLanguage.class);
@@ -140,7 +140,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
}
// That's for reparse routines
myProject.registerService(PomModel.class, new PomModelImpl(myProject));
project.registerService(PomModel.class, new PomModelImpl(project));
Registry.markAsLoaded();
}
@@ -166,7 +166,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
myLanguage = definition.getFileNodeType().getLanguage();
myFileExt = extension;
registerParserDefinition(definition);
myApp.registerService(FileTypeManager.class, new MockFileTypeManager(new MockLanguageFileType(myLanguage, myFileExt)));
app.registerService(FileTypeManager.class, new MockFileTypeManager(new MockLanguageFileType(myLanguage, myFileExt)));
}
protected final <T> void registerExtension(@NotNull ExtensionPointName<T> name, @NotNull T extension) {
@@ -175,7 +175,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
}
protected final <T> void registerExtensions(@NotNull ExtensionPointName<T> name, @NotNull Class<T> extensionClass, @NotNull List<? extends T> extensions) {
ExtensionsAreaImpl area = myApp.getExtensionArea();
ExtensionsAreaImpl area = app.getExtensionArea();
ExtensionPoint<T> point = area.getExtensionPointIfRegistered(name.getName());
if (point == null) {
point = registerExtensionPoint(area, name, extensionClass);
@@ -189,7 +189,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
}
protected final <T> void addExplicitExtension(@NotNull LanguageExtension<T> collector, @NotNull Language language, @NotNull T object) {
ExtensionsAreaImpl area = myApp.getExtensionArea();
ExtensionsAreaImpl area = app.getExtensionArea();
PluginDescriptor pluginDescriptor = getPluginDescriptor();
if (!area.hasExtensionPoint(collector.getName())) {
area.registerFakeBeanPoint(collector.getName(), pluginDescriptor);
@@ -200,7 +200,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
}
protected final <T> void registerExtensionPoint(@NotNull ExtensionPointName<T> extensionPointName, @NotNull Class<T> aClass) {
registerExtensionPoint(myApp.getExtensionArea(), extensionPointName, aClass);
registerExtensionPoint(app.getExtensionArea(), extensionPointName, aClass);
}
protected <T> ExtensionPointImpl<T> registerExtensionPoint(@NotNull ExtensionsAreaImpl extensionArea,
@@ -219,17 +219,17 @@ public abstract class ParsingTestCase extends UsefulTestCase {
@NotNull
// easy debug of not disposed extension
private PluginDescriptor getPluginDescriptor() {
PluginDescriptor pluginDescriptor = myPluginDescriptor;
PluginDescriptor pluginDescriptor = this.pluginDescriptor;
if (pluginDescriptor == null) {
pluginDescriptor = new DefaultPluginDescriptor(PluginId.getId(getClass().getName() + "." + getName()), ParsingTestCase.class.getClassLoader());
myPluginDescriptor = pluginDescriptor;
this.pluginDescriptor = pluginDescriptor;
}
return pluginDescriptor;
}
@NotNull
public MockProjectEx getProject() {
return myProject;
return project;
}
public MockPsiManager getPsiManager() {
@@ -239,7 +239,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
@Override
protected void tearDown() throws Exception {
myFile = null;
myProject = null;
project = null;
myPsiManager = null;
myFileFactory = null;
super.tearDown();
@@ -519,11 +519,11 @@ public abstract class ParsingTestCase extends UsefulTestCase {
}
public void registerMockInjectedLanguageManager() {
registerExtensionPoint(myProject.getExtensionArea(), MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME, MultiHostInjector.class);
registerExtensionPoint(project.getExtensionArea(), MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME, MultiHostInjector.class);
registerExtensionPoint(myApp.getExtensionArea(), LanguageInjector.EXTENSION_POINT_NAME, LanguageInjector.class);
myProject.registerService(DumbService.class, new MockDumbService(myProject));
registerExtensionPoint(app.getExtensionArea(), LanguageInjector.EXTENSION_POINT_NAME, LanguageInjector.class);
project.registerService(DumbService.class, new MockDumbService(project));
getApplication().registerService(EditorWindowTracker.class, new EditorWindowTrackerImpl());
myProject.registerService(InjectedLanguageManager.class, new InjectedLanguageManagerImpl(myProject));
project.registerService(InjectedLanguageManager.class, new InjectedLanguageManagerImpl(project));
}
}

View File

@@ -2,6 +2,7 @@
package org.jetbrains.kotlin.idea.test.testFramework
import com.intellij.mock.MockApplication
import com.intellij.mock.MockProject
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
@@ -13,7 +14,7 @@ interface ProjectEx : Project {
fun setProjectName(name: String)
}
class MockProjectEx(parentDisposable: Disposable) : MockProject(if (ApplicationManager.getApplication() != null) ApplicationManager.getApplication().picoContainer else null, parentDisposable), ProjectEx {
class MockProjectEx(parentDisposable: Disposable) : MockProject(if (ApplicationManager.getApplication() is MockApplication) (ApplicationManager.getApplication() as MockApplication).picoContainer else null, parentDisposable), ProjectEx {
override fun setProjectName(name: String) {
}