mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
+4
-7
@@ -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<Pair<Element, String>> states = mySplitter.splitState(element);
|
||||
for (Pair<Element, String> pair : states) {
|
||||
for (Pair<Element, String> 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);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ public class ProjectDictionary implements EditableDictionary {
|
||||
private String activeName;
|
||||
private Set<EditableDictionary> 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<String> words) {
|
||||
getActiveDictionary().replaceAll(words);
|
||||
@@ -144,7 +138,10 @@ public class ProjectDictionary implements EditableDictionary {
|
||||
}
|
||||
Set<String> words = new HashSet<String>();
|
||||
for (Dictionary dictionary : dictionaries) {
|
||||
words.addAll(dictionary.getWords());
|
||||
Set<String> otherWords = dictionary.getWords();
|
||||
if (otherWords != null) {
|
||||
words.addAll(otherWords);
|
||||
}
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
@@ -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<Pair<Element, String>> splitState(Element e) {
|
||||
final UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
|
||||
List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>();
|
||||
for (Element element : JDOMUtil.getElements(e)) {
|
||||
final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(DictionaryState.NAME_ATTRIBUTE))) + ".xml";
|
||||
|
||||
result.add(new Pair<Element, String>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ProjectDictionaryState>{
|
||||
|
||||
public class ProjectDictionaryState implements PersistentStateComponent<ProjectDictionaryState> {
|
||||
@Property(surroundWithTag = false) @AbstractCollection(surroundWithTag = false, elementTypes = DictionaryState.class)
|
||||
public List<DictionaryState> dictionaryStates = new ArrayList<DictionaryState>();
|
||||
|
||||
|
||||
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<EditableDictionary> projectDictionaries = projectDictionary.getDictionaries();
|
||||
if (projectDictionaries != null) {
|
||||
@@ -72,21 +57,22 @@ public class ProjectDictionaryState implements PersistentStateComponent<ProjectD
|
||||
|
||||
@Transient
|
||||
public ProjectDictionary getProjectDictionary() {
|
||||
if (projectDictionary==null){
|
||||
if (projectDictionary == null) {
|
||||
projectDictionary = new ProjectDictionary();
|
||||
}
|
||||
return projectDictionary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectDictionaryState getState() {
|
||||
if (projectDictionary!=null){
|
||||
if (projectDictionary != null) {
|
||||
//ensure all dictionaries within project dictionary will be stored
|
||||
setProjectDictionary(projectDictionary);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadState(ProjectDictionaryState state) {
|
||||
if (state != null) {
|
||||
this.dictionaryStates = state.dictionaryStates;
|
||||
|
||||
Reference in New Issue
Block a user