From e1804568bcd8a386fc2adec44ef02cd88885cf1b Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sat, 21 Sep 2013 17:59:56 +0200 Subject: [PATCH] cleanup --- .../impl/stores/DirectoryBasedStorage.java | 11 ++++----- .../dictionary/ProjectDictionary.java | 11 ++++----- .../state/ProjectDictionarySplitter.java | 13 ++++------ .../state/ProjectDictionaryState.java | 24 ++++--------------- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java index 827896f46ae8..7ee3a54d7a13 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java @@ -140,7 +140,7 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { LOG.error(e); } } - final ExternalizationSession session = new MyExternalizationSession(myPathMacroSubstitutor, myStorageData.clone()); + final ExternalizationSession session = new MyExternalizationSession(myStorageData.clone()); mySession = session; return session; @@ -330,7 +330,7 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { private class MyExternalizationSession implements ExternalizationSession { private final DirectoryStorageData myStorageData; - private MyExternalizationSession(final TrackingPathMacroSubstitutor pathMacroSubstitutor, final DirectoryStorageData storageData) { + private MyExternalizationSession(final DirectoryStorageData storageData) { myStorageData = storageData; } @@ -344,16 +344,13 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { private void setState(final String componentName, @NotNull Object state, final Storage storageSpec) throws StateStorageException { try { final Element element = DefaultStateSerializer.serializeState(state, storageSpec); - - final List> states = mySplitter.splitState(element); - for (Pair pair : states) { + for (Pair pair : mySplitter.splitState(element)) { Element e = pair.first; String name = pair.second; Element statePart = new Element(StorageData.COMPONENT); statePart.setAttribute(StorageData.NAME, componentName); - e.detach(); - statePart.addContent(e); + statePart.addContent(e.detach()); myStorageData.put(componentName, myDir.getChild(name), statePart, false); } diff --git a/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java b/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java index b72c8f45928a..dd8c11c6bfe1 100644 --- a/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java +++ b/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java @@ -31,7 +31,6 @@ public class ProjectDictionary implements EditableDictionary { private String activeName; private Set dictionaries; - public ProjectDictionary() { } @@ -50,10 +49,6 @@ public class ProjectDictionary implements EditableDictionary { return DEFAULT_PROJECT_DICTIONARY_NAME; } - public String getActiveName() { - return activeName; - } - public void setActiveName(String name) { activeName = name; } @@ -124,7 +119,6 @@ public class ProjectDictionary implements EditableDictionary { return result; } - @Override public void replaceAll(@Nullable Collection words) { getActiveDictionary().replaceAll(words); @@ -144,7 +138,10 @@ public class ProjectDictionary implements EditableDictionary { } Set words = new HashSet(); for (Dictionary dictionary : dictionaries) { - words.addAll(dictionary.getWords()); + Set otherWords = dictionary.getWords(); + if (otherWords != null) { + words.addAll(otherWords); + } } return words; } diff --git a/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionarySplitter.java b/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionarySplitter.java index 247ae439c808..998732f41c4e 100644 --- a/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionarySplitter.java +++ b/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionarySplitter.java @@ -16,7 +16,6 @@ package com.intellij.spellchecker.state; import com.intellij.openapi.components.StateSplitter; -import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.text.UniqueNameGenerator; @@ -31,22 +30,20 @@ import java.util.List; * @author shkate@jetbrains.com */ public class ProjectDictionarySplitter implements StateSplitter { - + @Override public List> splitState(Element e) { final UniqueNameGenerator generator = new UniqueNameGenerator(); - List> result = new ArrayList>(); - for (Element element : JDOMUtil.getElements(e)) { - final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(DictionaryState.NAME_ATTRIBUTE))) + ".xml"; - - result.add(new Pair(element, name)); + for (Element element : e.getChildren()) { + result.add(Pair.create(element, generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(DictionaryState.NAME_ATTRIBUTE))) + ".xml")); } return result; } + @Override public void mergeStatesInto(Element target, Element[] elements) { for (Element e : elements) { target.addContent(e); } } -} +} \ No newline at end of file diff --git a/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionaryState.java b/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionaryState.java index 717af47285cd..4237d8880013 100644 --- a/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionaryState.java +++ b/spellchecker/src/com/intellij/spellchecker/state/ProjectDictionaryState.java @@ -16,7 +16,6 @@ package com.intellij.spellchecker.state; import com.intellij.openapi.components.*; -import com.intellij.openapi.project.Project; import com.intellij.spellchecker.dictionary.EditableDictionary; import com.intellij.spellchecker.dictionary.ProjectDictionary; import com.intellij.util.xmlb.annotations.AbstractCollection; @@ -36,31 +35,17 @@ import java.util.Set; scheme = StorageScheme.DIRECTORY_BASED, stateSplitter = ProjectDictionarySplitter.class) } ) -public class ProjectDictionaryState implements PersistentStateComponent{ - +public class ProjectDictionaryState implements PersistentStateComponent { @Property(surroundWithTag = false) @AbstractCollection(surroundWithTag = false, elementTypes = DictionaryState.class) public List dictionaryStates = new ArrayList(); - private ProjectDictionary projectDictionary; - private String currentUser; - private Project project; public ProjectDictionaryState() { } - public void setProject(Project project) { - this.project = project; - } - - public void setCurrentUser(String currentUser) { - this.currentUser = currentUser; - } - - @Transient public void setProjectDictionary(ProjectDictionary projectDictionary) { - currentUser = projectDictionary.getActiveName(); dictionaryStates.clear(); Set projectDictionaries = projectDictionary.getDictionaries(); if (projectDictionaries != null) { @@ -72,21 +57,22 @@ public class ProjectDictionaryState implements PersistentStateComponent