From 2b54e307d2dfac8de68f6d5f73c8283e1b1abac6 Mon Sep 17 00:00:00 2001 From: Denis Mukhametianov Date: Tue, 6 Feb 2024 10:37:50 +0100 Subject: [PATCH] [spellchecker] review fixes: get rid of layers holder, replaced message with messagePointer GitOrigin-RevId: 625692a702c87057e54ba47df667851be9298654 --- .../intellij/spellchecker/DictionaryLevel.kt | 46 ++----------------- .../DictionaryLayerChangesListener.kt | 28 ----------- .../settings/SettingsTransferActivity.kt | 2 +- .../settings/SpellCheckerSettings.java | 2 +- 4 files changed, 7 insertions(+), 71 deletions(-) delete mode 100644 spellchecker/src/com/intellij/spellchecker/settings/DictionaryLayerChangesListener.kt diff --git a/spellchecker/src/com/intellij/spellchecker/DictionaryLevel.kt b/spellchecker/src/com/intellij/spellchecker/DictionaryLevel.kt index e9b10679f955..1197cb539691 100644 --- a/spellchecker/src/com/intellij/spellchecker/DictionaryLevel.kt +++ b/spellchecker/src/com/intellij/spellchecker/DictionaryLevel.kt @@ -1,70 +1,34 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.spellchecker -import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.project.Project import com.intellij.spellchecker.dictionary.EditableDictionary import com.intellij.spellchecker.dictionary.ProjectDictionary -import com.intellij.spellchecker.settings.DictionaryLayerChangesListener -import com.intellij.spellchecker.settings.DictionaryLayersChangesDispatcher import com.intellij.spellchecker.state.AppDictionaryState import com.intellij.spellchecker.state.ProjectDictionaryState import com.intellij.spellchecker.util.SpellCheckerBundle import org.jetbrains.annotations.Nls -import java.util.concurrent.ConcurrentMap +import java.util.function.Supplier interface DictionaryLayersProvider { fun getLayers(project: Project): List - fun startWatchingChanges(project: Project) { } companion object { val EP_NAME = ExtensionPointName.create("com.intellij.spellchecker.dictionaryLayersProvider") @JvmStatic fun getAllLayers(project: Project): Collection { - return project.service().getAllLayers() + return EP_NAME.extensionList.flatMap { it.getLayers(project) } } @JvmStatic fun getLayer(project: Project, layerName: String): DictionaryLayer? { - return project.service().getLayer(layerName) + return EP_NAME.extensionList.flatMap { it.getLayers(project) }.firstOrNull { it.name == layerName } } } } -@Service(Service.Level.PROJECT) -class PerProjectDictionaryLayersHolder(private val project: Project) { - private var layersMap: Map = mapOf() - - init { - project.service() - .register(object : DictionaryLayerChangesListener { - override fun layersChanged() { - rebuild() - } - }) - DictionaryLayersProvider.EP_NAME.extensionList.forEach{ - it.startWatchingChanges(project) - } - rebuild() - } - - fun rebuild() { - layersMap = DictionaryLayersProvider.EP_NAME.extensionList - .flatMap { it.getLayers(project) } - .associateBy { it.name } - } - - fun getLayer(layerName: String): DictionaryLayer? { - return layersMap[layerName] - } - - fun getAllLayers(): Collection { - return layersMap.values - } -} - interface DictionaryLayer { val dictionary: EditableDictionary val name: @Nls String @@ -78,10 +42,10 @@ class PlatformSettingsDictionaryLayersProvider : DictionaryLayersProvider { class ProjectDictionaryLayer(val project: Project) : DictionaryLayer { companion object { - val name = SpellCheckerBundle.message("dictionary.name.project.level") + val name = SpellCheckerBundle.messagePointer("dictionary.name.project.level") } - override val name = Companion.name + override val name = Companion.name.get() override val dictionary: ProjectDictionary = project.service().projectDictionary } diff --git a/spellchecker/src/com/intellij/spellchecker/settings/DictionaryLayerChangesListener.kt b/spellchecker/src/com/intellij/spellchecker/settings/DictionaryLayerChangesListener.kt deleted file mode 100644 index b90f1b2734bf..000000000000 --- a/spellchecker/src/com/intellij/spellchecker/settings/DictionaryLayerChangesListener.kt +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.spellchecker.settings - -import com.intellij.openapi.components.Service -import com.intellij.util.application -import com.intellij.util.messages.MessageBusConnection -import com.intellij.util.messages.Topic - -@Service(Service.Level.PROJECT) -class DictionaryLayersChangesDispatcher { - val publisher: DictionaryLayerChangesListener - get() = application.messageBus.syncPublisher(DictionaryLayerChangesListener.topic) - - fun register(subscriber: DictionaryLayerChangesListener): MessageBusConnection { - val connection = application.messageBus.connect() - connection.subscribe(DictionaryLayerChangesListener.topic, subscriber) - return connection - } -} - -interface DictionaryLayerChangesListener { - companion object { - @Topic.ProjectLevel - val topic = Topic(DictionaryLayerChangesListener::class.java) - } - - fun layersChanged() -} \ No newline at end of file diff --git a/spellchecker/src/com/intellij/spellchecker/settings/SettingsTransferActivity.kt b/spellchecker/src/com/intellij/spellchecker/settings/SettingsTransferActivity.kt index 800c6f5627e4..9334894efb91 100644 --- a/spellchecker/src/com/intellij/spellchecker/settings/SettingsTransferActivity.kt +++ b/spellchecker/src/com/intellij/spellchecker/settings/SettingsTransferActivity.kt @@ -13,7 +13,7 @@ internal class SettingsTransferActivity : ProjectActivity { if (settings.isSettingsTransferred) { return } - if (settings.isUseSingleDictionaryToSave && ProjectDictionaryLayer.name == settings.dictionaryToSave && + if (settings.isUseSingleDictionaryToSave && ProjectDictionaryLayer.name.get() == settings.dictionaryToSave && project.getService(ProjectDictionaryState::class.java).projectDictionary.words.isEmpty()) { settings.dictionaryToSave = ApplicationDictionaryLayer.name } diff --git a/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java b/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java index 194a52b94fdd..e852e0ac5db9 100644 --- a/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java +++ b/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java @@ -30,7 +30,7 @@ public final class SpellCheckerSettings implements PersistentStateComponent