[workspace model] provide implementation of FacetManager which stores data in workspa...
[idea/community.git] / platform / workspaceModel-ide / src / com / intellij / workspace / legacyBridge / intellij / LegacyBridgeModuleImpl.kt
1 // 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.
2 package com.intellij.workspace.legacyBridge.intellij
3
4 import com.intellij.facet.FacetManager
5 import com.intellij.ide.plugins.IdeaPluginDescriptorImpl
6 import com.intellij.ide.plugins.PluginManagerCore
7 import com.intellij.openapi.components.impl.stores.IComponentStore
8 import com.intellij.openapi.module.impl.ModuleImpl
9 import com.intellij.openapi.project.Project
10 import com.intellij.openapi.roots.ModuleRootManager
11 import com.intellij.openapi.vfs.LocalFileSystem
12 import com.intellij.openapi.vfs.VirtualFile
13 import com.intellij.workspace.api.ModuleId
14 import com.intellij.workspace.api.TypedEntityStorageDiffBuilder
15 import com.intellij.workspace.api.TypedEntityStore
16 import com.intellij.workspace.legacyBridge.facet.FacetManagerViaWorkspaceModel
17 import java.io.File
18
19 internal class LegacyBridgeModuleImpl(
20   override var moduleEntityId: ModuleId,
21   name: String,
22   project: Project,
23   private val filePath: String,
24   override var entityStore: TypedEntityStore,
25   override var diff: TypedEntityStorageDiffBuilder?
26 ) : ModuleImpl(name, project, filePath), LegacyBridgeModule {
27
28   override fun rename(newName: String, notifyStorage: Boolean) {
29     moduleEntityId = moduleEntityId.copy(name = newName)
30     super<ModuleImpl>.rename(newName, notifyStorage)
31   }
32
33   override fun registerComponents(plugins: List<IdeaPluginDescriptorImpl>,
34                                   notifyListeners: Boolean) {
35     super.registerComponents(plugins, false)
36
37     val pluginDescriptor = PluginManagerCore.getPlugin(PluginManagerCore.CORE_ID)
38                            ?: error("Could not find plugin by id: ${PluginManagerCore.CORE_ID}")
39
40     registerComponent(ModuleRootManager::class.java, LegacyBridgeModuleRootComponent::class.java, pluginDescriptor, true)
41     registerComponent(FacetManager::class.java, FacetManagerViaWorkspaceModel::class.java, pluginDescriptor, true)
42
43     registerService(LegacyBridgeFilePointerProvider::class.java, LegacyBridgeFilePointerProviderImpl::class.java, pluginDescriptor, false)
44     registerService(IComponentStore::class.java, LegacyBridgeModuleStoreImpl::class.java, pluginDescriptor, true)
45   }
46
47   override fun getModuleFile(): VirtualFile? = LocalFileSystem.getInstance().findFileByIoFile(File(filePath))
48
49   // TODO It should participate in rename too
50   override fun getModuleFilePath(): String = filePath
51 }