mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
IDEA-298358 rootsChanged event for all workspace entities with IndexableEntityProvider<>
GitOrigin-RevId: 2f372521a1a0e540948a0ce6df61a500a8de2757
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dc502b555e
commit
e4be5b87ea
@@ -2,12 +2,15 @@
|
||||
package com.intellij.workspaceModel.ide.impl.legacyBridge.project
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.RootsChangeRescanningInfo
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.util.indexing.roots.IndexableEntityProvider
|
||||
import com.intellij.workspaceModel.storage.EntityChange
|
||||
import com.intellij.workspaceModel.storage.VersionedStorageChange
|
||||
import com.intellij.workspaceModel.storage.WorkspaceEntity
|
||||
@@ -47,16 +50,49 @@ internal class ProjectRootsChangeListener(private val project: Project) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var customEntitiesToFireRootsChanged: Set<Class<out WorkspaceEntity>>
|
||||
|
||||
init {
|
||||
fun isAddable(entityClass: Class<out WorkspaceEntity>) = !LibraryEntity::class.java.isAssignableFrom(entityClass) &&
|
||||
!LibraryPropertiesEntity::class.java.isAssignableFrom(entityClass)
|
||||
|
||||
fun createCustomEntityClasses() =
|
||||
java.util.Set.copyOf(IndexableEntityProvider.EP_NAME.extensionList.map { it.entityClass }.filter {
|
||||
isAddable(it)
|
||||
})
|
||||
|
||||
customEntitiesToFireRootsChanged = createCustomEntityClasses()
|
||||
|
||||
val listener = object : ExtensionPointListener<IndexableEntityProvider<out WorkspaceEntity>> {
|
||||
override fun extensionAdded(extension: IndexableEntityProvider<out WorkspaceEntity>, pluginDescriptor: PluginDescriptor) {
|
||||
reinit(extension)
|
||||
}
|
||||
|
||||
override fun extensionRemoved(extension: IndexableEntityProvider<out WorkspaceEntity>, pluginDescriptor: PluginDescriptor) {
|
||||
reinit(extension)
|
||||
}
|
||||
|
||||
private fun reinit(extension: IndexableEntityProvider<out WorkspaceEntity>) {
|
||||
val entityClass = extension.entityClass
|
||||
if (isAddable(entityClass)) {
|
||||
customEntitiesToFireRootsChanged = createCustomEntityClasses()
|
||||
}
|
||||
}
|
||||
}
|
||||
IndexableEntityProvider.EP_NAME.addExtensionPointListener(listener)
|
||||
}
|
||||
|
||||
internal fun shouldFireRootsChanged(entity: WorkspaceEntity, project: Project): Boolean {
|
||||
return when (entity) {
|
||||
// Library changes should not fire any events if the library is not included in any of order entries
|
||||
is LibraryEntity -> libraryHasOrderEntry(entity, project)
|
||||
is LibraryPropertiesEntity -> libraryHasOrderEntry(entity.library, project)
|
||||
is ModuleEntity, is JavaModuleSettingsEntity, is ModuleCustomImlDataEntity, is ModuleGroupPathEntity,
|
||||
is SourceRootEntity, is JavaSourceRootEntity, is JavaResourceRootEntity, is CustomSourceRootPropertiesEntity,
|
||||
is ContentRootEntity -> true
|
||||
else -> false
|
||||
is ModuleGroupPathEntity, is CustomSourceRootPropertiesEntity -> true
|
||||
else -> {
|
||||
val entityClass = entity::class.java
|
||||
customEntitiesToFireRootsChanged.find { it.isAssignableFrom(entityClass) } != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user