mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
do not mutate dictionaryStates
GitOrigin-RevId: b7efde66abf4497947a0ca0506852ff394197084
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8362b6229c
commit
e317447ff1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 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.
|
||||
// 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.dictionary;
|
||||
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
@@ -12,7 +12,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public final class ProjectDictionary implements EditableDictionary {
|
||||
@NonNls private static final String DEFAULT_CURRENT_USER_NAME = "default.user";
|
||||
private static final @NonNls String DEFAULT_CURRENT_USER_NAME = "default.user";
|
||||
private static final String DEFAULT_PROJECT_DICTIONARY_NAME = "project";
|
||||
private String activeName;
|
||||
private Set<EditableDictionary> dictionaries;
|
||||
@@ -24,9 +24,8 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
this.dictionaries = dictionaries;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
public @NotNull String getName() {
|
||||
return DEFAULT_PROJECT_DICTIONARY_NAME;
|
||||
}
|
||||
|
||||
@@ -35,11 +34,12 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Boolean contains(@NotNull String word) {
|
||||
public @Nullable Boolean contains(@NotNull String word) {
|
||||
if (dictionaries == null) {
|
||||
return null; // still ("WORD_OF_ENTIRELY_UNKNOWN_LETTERS_FOR_ALL");
|
||||
// still ("WORD_OF_ENTIRELY_UNKNOWN_LETTERS_FOR_ALL");
|
||||
return null;
|
||||
}
|
||||
|
||||
int errors = 0;
|
||||
for (Dictionary dictionary : dictionaries) {
|
||||
Boolean contains = dictionary.contains(word);
|
||||
@@ -50,7 +50,11 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (errors == dictionaries.size()) return null;//("WORD_OF_ENTIRELY_UNKNOWN_LETTERS_FOR_ALL");
|
||||
|
||||
//("WORD_OF_ENTIRELY_UNKNOWN_LETTERS_FOR_ALL");
|
||||
if (errors == dictionaries.size()) {
|
||||
return null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,13 +68,11 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
getActiveDictionary().removeFromDictionary(word);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private EditableDictionary getActiveDictionary() {
|
||||
private @NotNull EditableDictionary getActiveDictionary() {
|
||||
return ensureCurrentUserDictionary();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private EditableDictionary ensureCurrentUserDictionary() {
|
||||
private @NotNull EditableDictionary ensureCurrentUserDictionary() {
|
||||
if (activeName == null) {
|
||||
activeName = DEFAULT_CURRENT_USER_NAME;
|
||||
}
|
||||
@@ -85,8 +87,7 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private EditableDictionary getDictionaryByName(@NotNull String name) {
|
||||
private @Nullable EditableDictionary getDictionaryByName(@NotNull String name) {
|
||||
if (dictionaries == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -112,8 +113,7 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<String> getWords() {
|
||||
public @NotNull Set<String> getWords() {
|
||||
if (dictionaries == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@@ -125,8 +125,7 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<String> getEditableWords() {
|
||||
public @NotNull Set<String> getEditableWords() {
|
||||
return getActiveDictionary().getWords();
|
||||
}
|
||||
|
||||
@@ -161,9 +160,8 @@ public final class ProjectDictionary implements EditableDictionary {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@Override
|
||||
public String toString() {
|
||||
public @NonNls String toString() {
|
||||
return "ProjectDictionary{" + "activeName='" + activeName + '\'' + ", dictionaries=" + dictionaries + '}';
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 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.
|
||||
// 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.dictionary;
|
||||
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
@@ -12,36 +12,31 @@ import java.util.Set;
|
||||
public final class UserDictionary implements EditableDictionary {
|
||||
private final String name;
|
||||
|
||||
@NotNull
|
||||
private final Set<String> words = CollectionFactory.createSmallMemoryFootprintSet();
|
||||
private final @NotNull Set<String> words = CollectionFactory.createSmallMemoryFootprintSet();
|
||||
|
||||
public UserDictionary(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
public @NotNull String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Boolean contains(@NotNull String word) {
|
||||
public @Nullable Boolean contains(@NotNull String word) {
|
||||
boolean contains = words.contains(word);
|
||||
if (contains) return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getWords() {
|
||||
public @NotNull Set<String> getWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<String> getEditableWords() {
|
||||
public @NotNull Set<String> getEditableWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
@@ -97,9 +92,8 @@ public final class UserDictionary implements EditableDictionary {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@Override
|
||||
public String toString() {
|
||||
public @NonNls String toString() {
|
||||
return "UserDictionary{" + "name='" + name + '\'' + ", words.count=" + words.size() + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// 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.state;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
@@ -12,6 +12,7 @@ import com.intellij.util.xmlb.annotations.Property;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import com.intellij.util.xmlb.annotations.XCollection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -23,22 +24,23 @@ import java.util.Set;
|
||||
public final class ProjectDictionaryState implements PersistentStateComponent<ProjectDictionaryState> {
|
||||
@Property(surroundWithTag = false)
|
||||
@XCollection(elementTypes = DictionaryState.class)
|
||||
public List<DictionaryState> dictionaryStates = new ArrayList<>();
|
||||
public @Unmodifiable List<DictionaryState> dictionaryStates = new ArrayList<>();
|
||||
|
||||
private ProjectDictionary projectDictionary;
|
||||
|
||||
private final EventDispatcher<DictionaryStateListener> myDictListenerEventDispatcher =
|
||||
private final EventDispatcher<DictionaryStateListener> dictListenerEventDispatcher =
|
||||
EventDispatcher.create(DictionaryStateListener.class);
|
||||
|
||||
@Transient
|
||||
public void setProjectDictionary(ProjectDictionary projectDictionary) {
|
||||
dictionaryStates.clear();
|
||||
List<DictionaryState> dictionaryStates = new ArrayList<>();
|
||||
Set<EditableDictionary> projectDictionaries = projectDictionary.getDictionaries();
|
||||
if (projectDictionaries != null) {
|
||||
for (EditableDictionary dic : projectDictionary.getDictionaries()) {
|
||||
dictionaryStates.add(new DictionaryState(dic));
|
||||
}
|
||||
}
|
||||
this.dictionaryStates = dictionaryStates;
|
||||
}
|
||||
|
||||
@Transient
|
||||
@@ -66,6 +68,7 @@ public final class ProjectDictionaryState implements PersistentStateComponent<Pr
|
||||
|
||||
private void retrieveProjectDictionaries() {
|
||||
Set<EditableDictionary> dictionaries = new HashSet<>();
|
||||
List<DictionaryState> dictionaryStates = this.dictionaryStates;
|
||||
if (dictionaryStates != null) {
|
||||
for (DictionaryState dictionaryState : dictionaryStates) {
|
||||
dictionaryState.loadState(dictionaryState);
|
||||
@@ -73,7 +76,7 @@ public final class ProjectDictionaryState implements PersistentStateComponent<Pr
|
||||
}
|
||||
}
|
||||
projectDictionary = new ProjectDictionary(dictionaries);
|
||||
myDictListenerEventDispatcher.getMulticaster().dictChanged(projectDictionary);
|
||||
dictListenerEventDispatcher.getMulticaster().dictChanged(projectDictionary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +85,6 @@ public final class ProjectDictionaryState implements PersistentStateComponent<Pr
|
||||
}
|
||||
|
||||
public void addProjectDictListener(DictionaryStateListener listener) {
|
||||
myDictListenerEventDispatcher.addListener(listener);
|
||||
dictListenerEventDispatcher.addListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user