diff --git a/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java b/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java index 9e7a7871b622..ecbcdfdcf7ed 100644 --- a/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java +++ b/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java @@ -23,6 +23,7 @@ import com.intellij.psi.impl.PsiElementFactoryImpl; import com.intellij.psi.impl.file.impl.JavaFileManager; import com.intellij.psi.impl.source.resolve.JavaResolveCache; import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl; +import org.jetbrains.annotations.ApiStatus.Internal; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -30,6 +31,7 @@ import java.io.File; /** * Used in Kotlin. */ +@Internal public class JavaCoreProjectEnvironment extends CoreProjectEnvironment { private final JavaFileManager myFileManager; private final PackageIndex myPackageIndex; diff --git a/platform/core-impl/api-dump-unreviewed.txt b/platform/core-impl/api-dump-unreviewed.txt index deb10cd6c285..50d4b52147f6 100644 --- a/platform/core-impl/api-dump-unreviewed.txt +++ b/platform/core-impl/api-dump-unreviewed.txt @@ -115,38 +115,6 @@ c:com.intellij.concurrency.SensitiveProgressWrapper c:com.intellij.core.CoreASTFactory - com.intellij.lang.DefaultASTFactoryImpl - ():V -c:com.intellij.core.CoreApplicationEnvironment -- pf:application:com.intellij.mock.MockApplication -- pf:myJarFileSystem:com.intellij.openapi.vfs.VirtualFileSystem -- (com.intellij.openapi.Disposable):V -- (com.intellij.openapi.Disposable,Z):V -- addExplicitExtension(com.intellij.lang.LanguageExtension,com.intellij.lang.Language,java.lang.Object):V -- addExplicitExtension(com.intellij.openapi.fileTypes.FileTypeExtension,com.intellij.openapi.fileTypes.FileType,java.lang.Object):V -- addExplicitExtension(com.intellij.openapi.util.ClassExtension,java.lang.Class,java.lang.Object):V -- addExtension(com.intellij.openapi.extensions.ExtensionPointName,java.lang.Object):V -- p:createApplication(com.intellij.openapi.Disposable):com.intellij.mock.MockApplication -- p:createJarFileSystem():com.intellij.openapi.vfs.VirtualFileSystem -- p:createJobLauncher():com.intellij.concurrency.JobLauncher -- p:createJrtFileSystem():com.intellij.openapi.vfs.VirtualFileSystem -- p:createLocalFileSystem():com.intellij.openapi.vfs.local.CoreLocalFileSystem -- p:createProgressIndicatorProvider():com.intellij.openapi.progress.ProgressManager -- p:createVirtualFilePointerManager():com.intellij.openapi.vfs.pointers.VirtualFilePointerManager -- getApplication():com.intellij.mock.MockApplication -- getJarFileSystem():com.intellij.openapi.vfs.VirtualFileSystem -- getJrtFileSystem():com.intellij.openapi.vfs.VirtualFileSystem -- getLocalFileSystem():com.intellij.openapi.vfs.local.CoreLocalFileSystem -- getParentDisposable():com.intellij.openapi.Disposable -- registerApplicationComponent(java.lang.Class,java.lang.Object):V -- s:registerApplicationDynamicExtensionPoint(java.lang.String,java.lang.Class):V -- s:registerApplicationExtensionPoint(com.intellij.openapi.extensions.ExtensionPointName,java.lang.Class):V -- registerApplicationService(java.lang.Class,java.lang.Object):V -- s:registerComponentInstance(com.intellij.util.pico.DefaultPicoContainer,java.lang.Class,java.lang.Object):V -- s:registerExtensionPoint(com.intellij.openapi.extensions.ExtensionsArea,com.intellij.openapi.extensions.ExtensionPointName,java.lang.Class):V -- s:registerExtensionPoint(com.intellij.openapi.extensions.ExtensionsArea,java.lang.String,java.lang.Class):V -- s:registerExtensionPointAndExtensions(java.nio.file.Path,java.lang.String,com.intellij.openapi.extensions.ExtensionsArea):V -- registerFileType(com.intellij.openapi.fileTypes.FileType,java.lang.String):V -- registerParserDefinition(com.intellij.lang.Language,com.intellij.lang.ParserDefinition):V -- registerParserDefinition(com.intellij.lang.ParserDefinition):V f:com.intellij.core.CoreFileTypeRegistry - com.intellij.openapi.fileTypes.FileTypeRegistry - ():V @@ -157,20 +125,6 @@ f:com.intellij.core.CoreFileTypeRegistry - getRegisteredFileTypes():com.intellij.openapi.fileTypes.FileType[] - isFileIgnored(com.intellij.openapi.vfs.VirtualFile):Z - registerFileType(com.intellij.openapi.fileTypes.FileType,java.lang.String):V -c:com.intellij.core.CoreProjectEnvironment -- pf:myFileIndexFacade:com.intellij.openapi.roots.FileIndexFacade -- pf:myPsiManager:com.intellij.psi.impl.PsiManagerImpl -- pf:project:com.intellij.mock.MockProject -- (com.intellij.openapi.Disposable,com.intellij.core.CoreApplicationEnvironment):V -- addProjectExtension(com.intellij.openapi.extensions.ExtensionPointName,java.lang.Object):V -- p:createFileIndexFacade():com.intellij.openapi.roots.FileIndexFacade -- p:createProjectScopeBuilder():com.intellij.psi.search.ProjectScopeBuilder -- p:createResolveScopeManager(com.intellij.psi.PsiManager):com.intellij.psi.impl.ResolveScopeManager -- getEnvironment():com.intellij.core.CoreApplicationEnvironment -- getParentDisposable():com.intellij.openapi.Disposable -- getProject():com.intellij.mock.MockProject -- p:preregisterServices():V -- registerProjectComponent(java.lang.Class,java.lang.Object):V c:com.intellij.core.CoreProjectScopeBuilder - (com.intellij.openapi.project.Project,com.intellij.openapi.roots.FileIndexFacade):V - buildAllScope():com.intellij.psi.search.GlobalSearchScope @@ -867,75 +821,6 @@ c:com.intellij.lexer.StringLiteralLexer - p:locateUnicodeEscapeSequence(I,I):I - p:shouldAllowSlashZero():Z - start(java.lang.CharSequence,I,I,I):V -c:com.intellij.mock.MockApplication -- com.intellij.mock.MockComponentManager -- com.intellij.openapi.application.ex.ApplicationEx -- s:INSTANCES_CREATED:I -- (com.intellij.openapi.Disposable):V -- acquireReadActionLock():com.intellij.openapi.application.AccessToken -- acquireWriteActionLock(java.lang.Class):com.intellij.openapi.application.AccessToken -- addApplicationListener(com.intellij.openapi.application.ApplicationListener):V -- addApplicationListener(com.intellij.openapi.application.ApplicationListener,com.intellij.openapi.Disposable):V -- assertIsDispatchThread():V -- assertIsDispatchThread(javax.swing.JComponent):V -- assertIsNonDispatchThread():V -- assertReadAccessAllowed():V -- assertReadAccessNotAllowed():V -- assertWriteAccessAllowed():V -- assertWriteIntentLockAcquired():V -- dispose():V -- executeOnPooledThread(java.lang.Runnable):java.util.concurrent.Future -- executeOnPooledThread(java.util.concurrent.Callable):java.util.concurrent.Future -- getAnyModalityState():com.intellij.openapi.application.ModalityState -- getCoroutineScope():kotlinx.coroutines.CoroutineScope -- getCurrentModalityState():com.intellij.openapi.application.ModalityState -- getDefaultModalityState():com.intellij.openapi.application.ModalityState -- getIdleTime():J -- getModalityStateForComponent(java.awt.Component):com.intellij.openapi.application.ModalityState -- getNoneModalityState():com.intellij.openapi.application.ModalityState -- f:getService(java.lang.Class):java.lang.Object -- f:getServiceIfCreated(java.lang.Class):java.lang.Object -- getStartTime():J -- hasWriteAction(java.lang.Class):Z -- holdsReadLock():Z -- invokeAndWait(java.lang.Runnable):V -- invokeAndWait(java.lang.Runnable,com.intellij.openapi.application.ModalityState):V -- invokeLater(java.lang.Runnable):V -- invokeLater(java.lang.Runnable,com.intellij.openapi.application.ModalityState):V -- invokeLater(java.lang.Runnable,com.intellij.openapi.application.ModalityState,com.intellij.openapi.util.Condition):V -- invokeLater(java.lang.Runnable,com.intellij.openapi.util.Condition):V -- invokeLaterOnWriteThread(java.lang.Runnable):V -- invokeLaterOnWriteThread(java.lang.Runnable,com.intellij.openapi.application.ModalityState):V -- invokeLaterOnWriteThread(java.lang.Runnable,com.intellij.openapi.application.ModalityState,com.intellij.openapi.util.Condition):V -- isActive():Z -- isCommandLine():Z -- isDispatchThread():Z -- isEAP():Z -- isHeadlessEnvironment():Z -- isInternal():Z -- isReadAccessAllowed():Z -- isRestartCapable():Z -- isSaveAllowed():Z -- isUnitTestMode():Z -- isWriteAccessAllowed():Z -- isWriteActionInProgress():Z -- isWriteActionPending():Z -- isWriteIntentLockAcquired():Z -- removeApplicationListener(com.intellij.openapi.application.ApplicationListener):V -- restart(Z):V -- restart(Z,Z):V -- runProcessWithProgressSynchronously(java.lang.Runnable,java.lang.String,Z,Z,com.intellij.openapi.project.Project,javax.swing.JComponent,java.lang.String):Z -- runReadAction(com.intellij.openapi.util.Computable):java.lang.Object -- runReadAction(com.intellij.openapi.util.ThrowableComputable):java.lang.Object -- runReadAction(java.lang.Runnable):V -- runWriteAction(com.intellij.openapi.util.Computable):java.lang.Object -- runWriteAction(com.intellij.openapi.util.ThrowableComputable):java.lang.Object -- runWriteAction(java.lang.Runnable):V -- saveAll():V -- saveSettings():V -- setSaveAllowed(Z):V -- s:setUp(com.intellij.openapi.Disposable):com.intellij.mock.MockApplication -- tryRunReadAction(java.lang.Runnable):Z c:com.intellij.mock.MockComponentManager - com.intellij.openapi.Disposable - com.intellij.openapi.components.ComponentManager diff --git a/platform/core-impl/exposed-private-api.txt b/platform/core-impl/exposed-private-api.txt index 1ac834e0e0df..76560694ac7d 100644 --- a/platform/core-impl/exposed-private-api.txt +++ b/platform/core-impl/exposed-private-api.txt @@ -1,11 +1,9 @@ -com/intellij/concurrency/JobLauncher com/intellij/diagnostic/ActivityCategory com/intellij/lang/impl/PsiBuilderImpl$MyTreeStructure com/intellij/lang/impl/PsiBuilderImpl$StartMarker com/intellij/openapi/command/impl/CoreCommandProcessor$CommandDescriptor com/intellij/openapi/extensions/impl/ExtensionsAreaImpl com/intellij/psi/impl/DiffLog -com/intellij/psi/search/ProjectScopeBuilder com/intellij/psi/stubs/StubBuilderType com/intellij/psi/stubs/StubInconsistencyReporter$EnforcedInconsistencyType com/intellij/psi/stubs/StubInconsistencyReporter$SourceOfCheck diff --git a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java index dec7b10c99d8..9a965fa2724a 100644 --- a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java @@ -52,6 +52,7 @@ import com.intellij.util.KeyedLazyInstanceEP; import com.intellij.util.graph.GraphAlgorithms; import com.intellij.util.graph.impl.GraphAlgorithmsImpl; import com.intellij.util.pico.DefaultPicoContainer; +import org.jetbrains.annotations.ApiStatus.Internal; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,6 +62,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +@Internal public class CoreApplicationEnvironment { private final CoreFileTypeRegistry myFileTypeRegistry; protected final MockApplication application; @@ -118,7 +120,7 @@ public class CoreApplicationEnvironment { registerApplicationService(GraphAlgorithms.class, new GraphAlgorithmsImpl()); registerApplicationExtensionPoint(StubElementRegistryServiceImplKt.STUB_REGISTRY_EP, StubRegistryExtension.class); - registerApplicationService(StubElementRegistryService.class, new StubElementRegistryServiceImpl()); + registerApplicationService(StubElementRegistryService.class, new StubElementRegistryServiceImpl(application.getCoroutineScope())); application.registerService(ApplicationInfo.class, ApplicationInfoImpl.class); diff --git a/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java index df2df65c2d69..47ab8f0301ec 100644 --- a/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.ApiStatus.Internal; import org.jetbrains.annotations.NotNull; import org.picocontainer.PicoContainer; +@Internal public class CoreProjectEnvironment { private final Disposable myParentDisposable; private final CoreApplicationEnvironment myEnvironment; diff --git a/platform/core-impl/src/com/intellij/mock/MockApplication.kt b/platform/core-impl/src/com/intellij/mock/MockApplication.kt index 8c4e0fe41f45..47502efc1454 100644 --- a/platform/core-impl/src/com/intellij/mock/MockApplication.kt +++ b/platform/core-impl/src/com/intellij/mock/MockApplication.kt @@ -1,4 +1,6 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +@file:Suppress("OVERRIDE_DEPRECATION") + package com.intellij.mock import com.intellij.lang.MetaLanguage @@ -11,6 +13,7 @@ import com.intellij.openapi.application.ex.ApplicationEx import com.intellij.openapi.application.impl.AnyModalityState import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.project.Project @@ -19,7 +22,9 @@ import com.intellij.openapi.util.Condition import com.intellij.openapi.util.ThrowableComputable import com.intellij.util.concurrency.AppExecutorUtil import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import org.jetbrains.annotations.ApiStatus.Internal import org.jetbrains.annotations.TestOnly import java.awt.Component import java.lang.reflect.Modifier @@ -29,35 +34,41 @@ import javax.swing.JComponent import javax.swing.SwingUtilities import kotlin.concurrent.Volatile +@Internal open class MockApplication(parentDisposable: Disposable) : MockComponentManager(null, parentDisposable), ApplicationEx { companion object { var INSTANCES_CREATED: Int = 0 + private set @TestOnly + @JvmStatic fun setUp(parentDisposable: Disposable): MockApplication { val app = MockApplication(parentDisposable) ApplicationManager.setApplication(app, parentDisposable) return app } - private val logger: Logger - get() = Logger.getInstance(MockApplication::class.java) + private val LOG: Logger + get() = logger() @Volatile private var warningLogged = false } + @Suppress("RAW_SCOPE_CREATION") + private val appCoroutineScope = CoroutineScope(SupervisorJob()) + init { INSTANCES_CREATED++ @Suppress("TestOnlyProblems") Extensions.setRootArea(getExtensionArea(), parentDisposable) } - override fun getServiceIfCreated(serviceClass: Class): T? = doGetService(serviceClass = serviceClass, createIfNeeded = false) + override fun getServiceIfCreated(serviceClass: Class): T? = doGetService(serviceClass = serviceClass, createIfNeeded = false) - override fun getService(serviceClass: Class): T? = doGetService(serviceClass = serviceClass, createIfNeeded = true) + override fun getService(serviceClass: Class): T? = doGetService(serviceClass = serviceClass, createIfNeeded = true) - private fun doGetService(serviceClass: Class, createIfNeeded: Boolean): T? { + private fun doGetService(serviceClass: Class, createIfNeeded: Boolean): T? { super.getService(serviceClass)?.let { return it } @@ -78,7 +89,7 @@ open class MockApplication(parentDisposable: Disposable) : MockComponentManager( override fun isEAP(): Boolean = false - override fun getCoroutineScope(): CoroutineScope = GlobalScope + override fun getCoroutineScope(): CoroutineScope = appCoroutineScope override fun isDispatchThread(): Boolean = SwingUtilities.isEventDispatchThread() @@ -276,19 +287,24 @@ open class MockApplication(parentDisposable: Disposable) : MockComponentManager( } override fun dispose() { - // A mock application may cause incorrect caching during tests. It does not fire extension point removed events. - // Ensure that we have cached against correct application. - MetaLanguage.clearAllMatchingMetaLanguagesCache() - super.dispose() + try { + // A mock application may cause incorrect caching during tests. It does not fire extension point removed events. + // Ensure that we have cached against correct application. + MetaLanguage.clearAllMatchingMetaLanguagesCache() + appCoroutineScope.cancel() + } + finally { + super.dispose() + } } - private fun logInsufficientIsolation(methodName: String?, vararg args: Any?) { + private fun logInsufficientIsolation(@Suppress("SameParameterValue") methodName: String?, vararg args: Any?) { if (warningLogged || !isUnitTestMode()) { return } warningLogged = true - logger.warn( + LOG.warn( "Attempt to execute method \"" + methodName + "\" with arguments `" + args.contentToString() + "` within a MockApplication.\n" + "This is likely caused by an improper test isolation. Please consider writing tests with JUnit 5 fixtures.", Throwable()) diff --git a/platform/core-impl/src/com/intellij/psi/stubs/StubElementRegistryServiceImpl.kt b/platform/core-impl/src/com/intellij/psi/stubs/StubElementRegistryServiceImpl.kt index 4d414a1b8ba6..c78fa84f1025 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubElementRegistryServiceImpl.kt +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubElementRegistryServiceImpl.kt @@ -4,15 +4,15 @@ package com.intellij.psi.stubs import com.intellij.lang.Language import com.intellij.lang.LanguageExtension import com.intellij.lang.LanguageParserDefinitions -import com.intellij.openapi.Disposable import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IFileElementType import com.intellij.psi.tree.TemplateLanguageStubBaseVersion.dropVersion +import kotlinx.coroutines.CoroutineScope import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal -open class StubElementRegistryServiceImpl : CoreStubElementRegistryServiceImpl(), Disposable.Default { +open class StubElementRegistryServiceImpl(coroutineScope: CoroutineScope) : CoreStubElementRegistryServiceImpl() { @Volatile private lateinit var factories: Map> @Volatile private lateinit var lightFactories: Map> @Volatile private lateinit var type2serializerMap: Map> @@ -20,8 +20,8 @@ open class StubElementRegistryServiceImpl : CoreStubElementRegistryServiceImpl() private set init { - STUB_REGISTRY_EP.addChangeListener(Runnable { init() }, this) - STUB_DEFINITION_EP.point?.addChangeListener(Runnable { onStubDefinitionChange() }, this) + STUB_REGISTRY_EP.addChangeListener(coroutineScope) { init() } + STUB_DEFINITION_EP.point?.addChangeListener(coroutineScope) { onStubDefinitionChange() } init() } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index d7354d33b0e6..4c16eec6807d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -130,7 +130,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da System.out.println("----- TEST STATISTICS -----"); UsefulTestCase.logSetupTeardownCosts(); System.out.printf("##teamcity[buildStatisticValue key='ideaTests.appInstancesCreated' value='%d']%n", - MockApplication.INSTANCES_CREATED); + MockApplication.Companion.getINSTANCES_CREATED()); System.out.printf("##teamcity[buildStatisticValue key='ideaTests.projectInstancesCreated' value='%d']%n", TestProjectManagerKt.getTotalCreatedProjectsCount()); long totalGcTime = 0;