mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
rename ModuleEx.init to initNewlyAddedModule and note for the method
GitOrigin-RevId: 8683ae0e2e0ed7ef86802ea56a71dd2ee97fc4a7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3d17eb0b90
commit
7354a4e504
@@ -20,10 +20,8 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.serviceContainer.ComponentManagerImpl
|
||||
import com.intellij.serviceContainer.PrecomputedExtensionModel
|
||||
import com.intellij.serviceContainer.emptyConstructorMethodType
|
||||
import com.intellij.serviceContainer.findConstructorOrNull
|
||||
import com.intellij.serviceContainer.*
|
||||
import com.intellij.util.concurrency.annotations.RequiresBlockingContext
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleBridgeImpl
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
@@ -54,6 +52,22 @@ class ModuleComponentManager(parent: ComponentManagerImpl) : ComponentManagerImp
|
||||
emptyConstructorMethodType,
|
||||
)
|
||||
|
||||
internal fun initModuleContainer(plugins: List<IdeaPluginDescriptorImpl>, precomputedExtensionModel: PrecomputedExtensionModel) {
|
||||
// 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
|
||||
for (plugin in plugins) {
|
||||
registerServices(plugin.moduleContainerDescriptor.services, plugin)
|
||||
for (content in plugin.contentModules) {
|
||||
val services = content.descriptor.moduleContainerDescriptor.services
|
||||
if (services.isNotEmpty()) {
|
||||
registerServices(services, plugin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerExtensionPointsAndExtensionByPrecomputedModel(precomputedExtensionModel, null)
|
||||
}
|
||||
|
||||
fun initForModule(module: Module) {
|
||||
this.module = module
|
||||
registerServiceInstance(serviceInterface = Module::class.java, instance = module, pluginDescriptor = fakeCorePluginDescriptor)
|
||||
@@ -104,6 +118,7 @@ class ModuleComponentManager(parent: ComponentManagerImpl) : ComponentManagerImp
|
||||
|
||||
// expose to call it via ModuleImpl
|
||||
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||
@RequiresBlockingContext
|
||||
public override fun createComponents() {
|
||||
super.createComponents()
|
||||
}
|
||||
@@ -114,13 +129,13 @@ class ModuleComponentManager(parent: ComponentManagerImpl) : ComponentManagerImp
|
||||
precomputedExtensionModel: PrecomputedExtensionModel?,
|
||||
listenerCallbacks: MutableList<in Runnable>?,
|
||||
) {
|
||||
assert(listenerCallbacks.isNullOrEmpty())
|
||||
if (precomputedExtensionModel == null) {
|
||||
LOG.error("precomputedExtensionModel must not be null")
|
||||
super.registerComponents(modules, app, null, listenerCallbacks)
|
||||
initModuleContainer(modules, precomputeModuleLevelExtensionModel())
|
||||
}
|
||||
else {
|
||||
assert(listenerCallbacks.isNullOrEmpty())
|
||||
super.initModuleContainer(modules, precomputedExtensionModel)
|
||||
initModuleContainer(modules, precomputedExtensionModel)
|
||||
}
|
||||
|
||||
if (modules.any { it.pluginId == PluginManagerCore.CORE_ID }) {
|
||||
|
||||
@@ -6,6 +6,7 @@ package com.intellij.openapi.module.impl
|
||||
import com.intellij.configurationStore.NonPersistentModuleStore
|
||||
import com.intellij.configurationStore.RenameableStateStorageManager
|
||||
import com.intellij.ide.highlighter.ModuleFileType
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.components.impl.stores.ComponentStoreOwner
|
||||
import com.intellij.openapi.components.impl.stores.IComponentStore
|
||||
@@ -22,8 +23,8 @@ import com.intellij.openapi.util.SimpleModificationTracker
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.serviceContainer.ComponentManagerImpl.Companion.fakeCorePluginDescriptor
|
||||
import com.intellij.serviceContainer.getComponentManagerImpl
|
||||
import com.intellij.serviceContainer.precomputeModuleLevelExtensionModel
|
||||
import com.intellij.util.messages.MessageBus
|
||||
import com.intellij.util.xmlb.annotations.MapAnnotation
|
||||
import com.intellij.util.xmlb.annotations.Property
|
||||
@@ -71,11 +72,11 @@ open class ModuleImpl(
|
||||
|
||||
internal fun getModuleComponentManager(): ModuleComponentManager = componentManager.getComponentManagerImpl() as ModuleComponentManager
|
||||
|
||||
override fun init() {
|
||||
override fun initNewlyAddedModule() {
|
||||
// do not measure (activityNamePrefix method not overridden by this class)
|
||||
// because there are a lot of modules and no need to measure each one
|
||||
val moduleComponentManager = getModuleComponentManager()
|
||||
moduleComponentManager.registerComponents()
|
||||
moduleComponentManager.initModuleContainer(PluginManagerCore.getPluginSet().enabledPlugins, precomputeModuleLevelExtensionModel())
|
||||
@Suppress("DEPRECATION")
|
||||
moduleComponentManager.createComponents()
|
||||
}
|
||||
|
||||
+6
-5
@@ -107,6 +107,7 @@ open class ModuleManagerComponentBridge(private val project: Project, coroutineS
|
||||
else {
|
||||
null
|
||||
}
|
||||
|
||||
for (change in moduleChanges) {
|
||||
if (change !is EntityChange.Added<ModuleEntity>) {
|
||||
continue
|
||||
@@ -189,7 +190,7 @@ open class ModuleManagerComponentBridge(private val project: Project, coroutineS
|
||||
init: (ModuleBridge) -> Unit,
|
||||
): ModuleBridge {
|
||||
val componentManager = ModuleComponentManager(project.getComponentManagerImpl())
|
||||
return ModuleBridgeImpl(
|
||||
val moduleBridge = ModuleBridgeImpl(
|
||||
moduleEntityId = symbolicId,
|
||||
name = name,
|
||||
project = project,
|
||||
@@ -197,10 +198,10 @@ open class ModuleManagerComponentBridge(private val project: Project, coroutineS
|
||||
entityStorage = entityStorage,
|
||||
diff = diff,
|
||||
componentManager = componentManager,
|
||||
).also {
|
||||
componentManager.initForModule(it)
|
||||
init(it)
|
||||
}
|
||||
)
|
||||
componentManager.initForModule(moduleBridge)
|
||||
init(moduleBridge)
|
||||
return moduleBridge
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public interface ModuleEx extends Module {
|
||||
default void init() {
|
||||
// not called for module on loading, only if module created after project opening
|
||||
default void initNewlyAddedModule() {
|
||||
}
|
||||
|
||||
default void markAsLoaded() {
|
||||
|
||||
+8
-2
@@ -1,5 +1,5 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplaceGetOrSet", "ReplacePutWithAssignment")
|
||||
@file:Suppress("ReplaceGetOrSet", "ReplacePutWithAssignment", "ReplaceJavaStaticMethodWithKotlinAnalog")
|
||||
|
||||
package com.intellij.serviceContainer
|
||||
|
||||
@@ -16,9 +16,11 @@ class PrecomputedExtensionModel(
|
||||
@JvmField val nameToExtensions: Map<String, List<Pair<IdeaPluginDescriptor, List<ExtensionDescriptor>>>>,
|
||||
)
|
||||
|
||||
private val EMPTY = PrecomputedExtensionModel(extensionPoints = java.util.List.of(), nameToExtensions = java.util.Map.of())
|
||||
|
||||
@ApiStatus.Internal
|
||||
fun precomputeModuleLevelExtensionModel(): PrecomputedExtensionModel {
|
||||
val modules = PluginManagerCore.getPluginSet().getEnabledModules()
|
||||
val modules = PluginManagerCore.getPluginSet().enabledPlugins
|
||||
|
||||
var extensionPointTotalCount = 0
|
||||
val mutableNameToExtensions = HashMap<String, MutableList<Pair<IdeaPluginDescriptor, List<ExtensionDescriptor>>>>()
|
||||
@@ -36,6 +38,10 @@ fun precomputeModuleLevelExtensionModel(): PrecomputedExtensionModel {
|
||||
}
|
||||
}
|
||||
|
||||
if (extensionPointDescriptors.isEmpty() || mutableNameToExtensions.isEmpty()) {
|
||||
return EMPTY
|
||||
}
|
||||
|
||||
val nameToExtensions = java.util.Map.copyOf(mutableNameToExtensions)
|
||||
// step 2 - collect container level extensions
|
||||
executeRegisterTask(modules) { pluginDescriptor ->
|
||||
|
||||
+24
-15
@@ -13,6 +13,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.platform.backend.workspace.WorkspaceModel
|
||||
import com.intellij.platform.diagnostic.telemetry.helpers.MillisecondsMeasurer
|
||||
@@ -60,17 +61,25 @@ internal class ModifiableModuleModelBridgeImpl(
|
||||
override fun getModules(): Array<Module> = currentModuleSet.toTypedArray()
|
||||
|
||||
override fun newNonPersistentModule(moduleName: String, moduleTypeId: String): Module {
|
||||
val moduleEntity = diff addEntity ModuleEntity(name = moduleName,
|
||||
dependencies = listOf(ModuleSourceDependency),
|
||||
entitySource = NonPersistentEntitySource
|
||||
)
|
||||
val moduleEntity = diff.addEntity(ModuleEntity(
|
||||
name = moduleName,
|
||||
dependencies = listOf(ModuleSourceDependency),
|
||||
entitySource = NonPersistentEntitySource,
|
||||
))
|
||||
|
||||
val module = moduleManager.createModule(moduleEntity.symbolicId, moduleName, null, entityStorageOnDiff, diff) {}
|
||||
val module = moduleManager.createModule(
|
||||
symbolicId = moduleEntity.symbolicId,
|
||||
name = moduleName,
|
||||
virtualFileUrl = null,
|
||||
entityStorage = entityStorageOnDiff,
|
||||
diff = diff,
|
||||
init = {},
|
||||
)
|
||||
diff.mutableModuleMap.addMapping(moduleEntity, module)
|
||||
modulesToAdd.put(moduleName, module)
|
||||
currentModuleSet.add(module)
|
||||
|
||||
module.init()
|
||||
module.initNewlyAddedModule()
|
||||
module.setModuleType(moduleTypeId)
|
||||
return module
|
||||
}
|
||||
@@ -79,7 +88,7 @@ internal class ModifiableModuleModelBridgeImpl(
|
||||
// TODO Handle filePath, add correct iml source with a path
|
||||
|
||||
// TODO Must be in sync with module loading. It is not now
|
||||
val canonicalPath = FileUtil.toSystemIndependentName(resolveShortWindowsName(filePath))
|
||||
val canonicalPath = FileUtilRt.toSystemIndependentName(resolveShortWindowsName(filePath))
|
||||
|
||||
val existingModule = getModuleByFilePath(canonicalPath)
|
||||
if (existingModule != null) {
|
||||
@@ -118,16 +127,16 @@ internal class ModifiableModuleModelBridgeImpl(
|
||||
}
|
||||
|
||||
private fun createModuleInstance(moduleEntity: ModuleEntity, isNew: Boolean): ModuleBridge {
|
||||
val plugins = PluginManagerCore.getPluginSet().getEnabledModules()
|
||||
val moduleInstance = moduleManager.createModuleInstance(moduleEntity = moduleEntity,
|
||||
versionedStorage = entityStorageOnDiff,
|
||||
diff = diff,
|
||||
isNew = isNew,
|
||||
precomputedExtensionModel = precomputeModuleLevelExtensionModel(),
|
||||
plugins = plugins
|
||||
val moduleInstance = moduleManager.createModuleInstance(
|
||||
moduleEntity = moduleEntity,
|
||||
versionedStorage = entityStorageOnDiff,
|
||||
diff = diff,
|
||||
isNew = isNew,
|
||||
precomputedExtensionModel = precomputeModuleLevelExtensionModel(),
|
||||
plugins = PluginManagerCore.getPluginSet().enabledPlugins,
|
||||
)
|
||||
diff.mutableModuleMap.addMapping(moduleEntity, moduleInstance)
|
||||
modulesToAdd[moduleEntity.name] = moduleInstance
|
||||
modulesToAdd.put(moduleEntity.name, moduleInstance)
|
||||
currentModuleSet.add(moduleInstance)
|
||||
return moduleInstance
|
||||
}
|
||||
|
||||
+6
-18
@@ -41,6 +41,7 @@ import com.intellij.openapi.util.*
|
||||
import com.intellij.platform.instanceContainer.internal.*
|
||||
import com.intellij.platform.util.coroutines.childScope
|
||||
import com.intellij.util.concurrency.ThreadingAssertions
|
||||
import com.intellij.util.concurrency.annotations.RequiresBlockingContext
|
||||
import com.intellij.util.containers.UList
|
||||
import com.intellij.util.messages.MessageBus
|
||||
import com.intellij.util.messages.MessageBusFactory
|
||||
@@ -394,24 +395,10 @@ abstract class ComponentManagerImpl(
|
||||
}
|
||||
}
|
||||
|
||||
protected fun initModuleContainer(plugins: List<IdeaPluginDescriptorImpl>, precomputedExtensionModel: PrecomputedExtensionModel) {
|
||||
// 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
|
||||
for (plugin in plugins) {
|
||||
registerServices(plugin.moduleContainerDescriptor.services, plugin)
|
||||
for (content in plugin.contentModules) {
|
||||
val services = content.descriptor.moduleContainerDescriptor.services
|
||||
if (services.isNotEmpty()) {
|
||||
registerServices(services, plugin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerExtensionPointsAndExtensionByPrecomputedModel(precomputedExtensionModel, null)
|
||||
}
|
||||
|
||||
private fun registerExtensionPointsAndExtensionByPrecomputedModel(precomputedExtensionModel: PrecomputedExtensionModel,
|
||||
listenerCallbacks: MutableList<in Runnable>?) {
|
||||
protected fun registerExtensionPointsAndExtensionByPrecomputedModel(
|
||||
precomputedExtensionModel: PrecomputedExtensionModel,
|
||||
listenerCallbacks: MutableList<in Runnable>?,
|
||||
) {
|
||||
if (precomputedExtensionModel.extensionPoints.isEmpty()) {
|
||||
return
|
||||
}
|
||||
@@ -503,6 +490,7 @@ abstract class ComponentManagerImpl(
|
||||
|
||||
@Suppress("DuplicatedCode")
|
||||
@Deprecated(message = "Use createComponentsNonBlocking")
|
||||
@RequiresBlockingContext
|
||||
protected open fun createComponents() {
|
||||
LOG.assertTrue(containerState.get() == ContainerState.PRE_INIT)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user