mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[workspace model] IDEA-298714 Add facet bridge initialization if loaded from cache
GitOrigin-RevId: 0ffc17337bff784d1bdb2d0b63c2fb59014962fb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d8472283bf
commit
131873fdfe
+7
-3
@@ -116,12 +116,16 @@ class FacetEntityChangeListener(private val project: Project): Disposable {
|
||||
publisher.fireFacetRemoved(manager.module, facet)
|
||||
}
|
||||
is EntityChange.Replaced -> {
|
||||
val moduleEntity = workspaceFacetContributor.getRelatedModuleEntity(change.newEntity)
|
||||
val facet = event.storageAfter.facetMapping().getDataByEntity(change.newEntity) ?: error("Facet should be available")
|
||||
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||
val facetToOldEntity = workspaceModel.entityStorage.current.facetMapping().getDataByEntity(change.oldEntity)
|
||||
workspaceModel.updateProjectModelSilent {
|
||||
it.mutableFacetMapping().addMapping(change.newEntity, facet)
|
||||
if (facetToOldEntity != null) {
|
||||
it.mutableFacetMapping().removeMapping(change.oldEntity)
|
||||
it.mutableFacetMapping().addMapping(change.newEntity, facetToOldEntity)
|
||||
}
|
||||
}
|
||||
val facet = workspaceModel.entityStorage.current.facetMapping().getDataByEntity(change.newEntity) ?: error("Facet should be available")
|
||||
val moduleEntity = workspaceFacetContributor.getRelatedModuleEntity(change.newEntity)
|
||||
getFacetManager(moduleEntity)?.model?.facetsChanged()
|
||||
val newFacetName = workspaceFacetContributor.getFacetName(change.newEntity)
|
||||
val oldFacetName = workspaceFacetContributor.getFacetName(change.oldEntity)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class FacetEntityContributor: WorkspaceFacetContributor<FacetEntity> {
|
||||
override fun getRootEntityByModuleEntity(moduleEntity: ModuleEntity): FacetEntity = error("Unsupported operation")
|
||||
|
||||
override fun createFacetFromEntity(entity: FacetEntity, project: Project): Facet<*> {
|
||||
val module = ModuleManager.getInstance(project).findModuleByName(entity.module.name) ?: error("Module bridge should be avaliable")
|
||||
val module = ModuleManager.getInstance(project).findModuleByName(entity.module.name) ?: error("Module bridge should be available")
|
||||
val facetManagerBridge = FacetManager.getInstance(module) as FacetManagerBridge
|
||||
return facetManagerBridge.model.createFacet(entity)
|
||||
}
|
||||
|
||||
+17
-21
@@ -29,8 +29,8 @@ import com.intellij.workspaceModel.storage.bridgeEntities.api.modifyEntity
|
||||
import org.jetbrains.jps.model.serialization.facet.FacetState
|
||||
|
||||
class FacetManagerBridge(module: Module) : FacetManagerBase() {
|
||||
val module = module as ModuleBridge
|
||||
val model = FacetModelBridge(this.module)
|
||||
internal val module = module as ModuleBridge
|
||||
internal val model = FacetModelBridge(this.module)
|
||||
|
||||
private fun isThisModule(moduleEntity: ModuleEntity) = moduleEntity.name == module.name
|
||||
|
||||
@@ -128,10 +128,21 @@ class FacetManagerBridge(module: Module) : FacetManagerBase() {
|
||||
open class FacetModelBridge(private val moduleBridge: ModuleBridge) : FacetModelBase() {
|
||||
|
||||
init {
|
||||
val existingEntities = moduleBridge.entityStorage.current.entities(FacetEntity::class.java)
|
||||
.filter { it.moduleId == moduleBridge.moduleEntityId }
|
||||
for (facetEntity in existingEntities) {
|
||||
getOrCreateFacet(facetEntity)
|
||||
// Initialize facet bridges after loading from cache
|
||||
fun createFacetBridgeIfNeeded(entity: WorkspaceEntity, facetContributor: WorkspaceFacetContributor<WorkspaceEntity>, project: Project) {
|
||||
updateDiffOrStorage{ this.getOrPutDataByEntity(entity) { facetContributor.createFacetFromEntity(entity, project) } }
|
||||
}
|
||||
moduleBridge.project
|
||||
val moduleEntity = moduleBridge.entityStorage.current.resolve(moduleBridge.moduleEntityId)
|
||||
?: error("Module entity should be available")
|
||||
WorkspaceFacetContributor.EP_NAME.extensions.forEach { facetContributor ->
|
||||
if (facetContributor.rootEntityType != FacetEntity::class.java) {
|
||||
facetContributor.getRootEntityByModuleEntity(moduleEntity)?.let {
|
||||
createFacetBridgeIfNeeded(it, facetContributor, moduleBridge.project)
|
||||
}
|
||||
} else {
|
||||
moduleEntity.facets.forEach { createFacetBridgeIfNeeded(it, facetContributor, moduleBridge.project) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,21 +211,6 @@ open class FacetModelBridge(private val moduleBridge: ModuleBridge) : FacetModel
|
||||
super.facetsChanged()
|
||||
}
|
||||
|
||||
fun updateEntity(oldEntity: FacetEntity, newEntity: FacetEntity): Facet<*>? {
|
||||
val oldFacet = updateDiffOrStorage {
|
||||
this.removeMapping(oldEntity)
|
||||
}
|
||||
var updatedFacet: Facet<*>? = null
|
||||
if (oldFacet != null) {
|
||||
updatedFacet = updateDiffOrStorage {
|
||||
this.addMapping(newEntity, oldFacet)
|
||||
oldFacet
|
||||
}
|
||||
}
|
||||
facetsChanged()
|
||||
return updatedFacet
|
||||
}
|
||||
|
||||
fun checkConsistency(facetRelatedEntities: List<WorkspaceEntity>,
|
||||
entityTypeToFacetContributor: Map<Class<WorkspaceEntity>, WorkspaceFacetContributor<WorkspaceEntity>>) {
|
||||
val facetEntitiesSet = facetRelatedEntities.toSet()
|
||||
|
||||
+9
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.workspaceModel.ide.impl.jps.serialization
|
||||
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.workspaceModel.ide.JpsImportedEntitySource
|
||||
import com.intellij.workspaceModel.storage.EntitySource
|
||||
@@ -9,6 +10,7 @@ import com.intellij.workspaceModel.storage.bridgeEntities.addFacetEntity
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.api.*
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.jps.model.serialization.facet.FacetState
|
||||
import java.util.function.Consumer
|
||||
|
||||
class DefaultFacetEntitySerializer: CustomFacetRelatedEntitySerializer<FacetEntity> {
|
||||
override val rootEntityType: Class<FacetEntity>
|
||||
@@ -42,6 +44,13 @@ class DefaultFacetEntitySerializer: CustomFacetRelatedEntitySerializer<FacetEnti
|
||||
}
|
||||
|
||||
if (existingFacet == null) {
|
||||
val logger = logger<DefaultFacetEntitySerializer>()
|
||||
logger.info("Add facet entity ${facetState.name}:${facetState.facetType}")
|
||||
logger.info("Stack Trace facet Add")
|
||||
val stackTrace = Thread.currentThread().stackTrace
|
||||
for (stackTraceElement in stackTrace) {
|
||||
logger.info(stackTraceElement.toString())
|
||||
}
|
||||
facetEntity = builder.addFacetEntity(facetState.name, facetState.facetType, configurationXmlTag, moduleEntity, underlyingFacet, entitySource)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user