mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify — inline CompoundExternalizationSession
This commit is contained in:
+2
-1
@@ -279,7 +279,8 @@ public abstract class ComponentStoreImpl implements IComponentStore {
|
||||
return (Class<T>)ReflectionUtil.getRawType(type);
|
||||
}
|
||||
|
||||
public static String getComponentName(@NotNull final PersistentStateComponent<?> persistentStateComponent) {
|
||||
@NotNull
|
||||
public static String getComponentName(@NotNull PersistentStateComponent<?> persistentStateComponent) {
|
||||
return getStateSpec(persistentStateComponent).name();
|
||||
}
|
||||
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.components.impl.stores;
|
||||
|
||||
import com.intellij.openapi.components.StateStorage;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author mike
|
||||
*/
|
||||
public class CompoundExternalizationSession {
|
||||
private final Map<StateStorage, StateStorage.ExternalizationSession> mySessions = new THashMap<StateStorage, StateStorage.ExternalizationSession>(1);
|
||||
|
||||
@NotNull
|
||||
public StateStorage.ExternalizationSession getExternalizationSession(@NotNull StateStorage stateStore) {
|
||||
StateStorage.ExternalizationSession session = mySessions.get(stateStore);
|
||||
if (session == null) {
|
||||
mySessions.put(stateStore, session = stateStore.startExternalization());
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public Collection<StateStorage> getStateStorages() {
|
||||
return mySessions.keySet();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -87,7 +87,7 @@ public interface StateStorageManager {
|
||||
void reset();
|
||||
|
||||
interface ExternalizationSession {
|
||||
void setState(@NotNull Storage[] storageSpecs, @NotNull Object component, String componentName, @NotNull Object state);
|
||||
void setState(@NotNull Storage[] storageSpecs, @NotNull Object component, @NotNull String componentName, @NotNull Object state);
|
||||
|
||||
void setStateInOldStorage(@NotNull Object component, @NotNull String componentName, @NotNull Object state);
|
||||
}
|
||||
|
||||
+20
-16
@@ -400,18 +400,13 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SaveSession startSave(@NotNull final ExternalizationSession externalizationSession) {
|
||||
public SaveSession startSave(@NotNull ExternalizationSession externalizationSession) {
|
||||
assert mySession == externalizationSession;
|
||||
SaveSession session = createSaveSession(externalizationSession);
|
||||
SaveSession session = new MySaveSession((MyExternalizationSession)externalizationSession);
|
||||
mySession = session;
|
||||
return session;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MySaveSession createSaveSession(final ExternalizationSession externalizationSession) {
|
||||
return new MySaveSession((MyExternalizationSession)externalizationSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishSave(@NotNull final SaveSession saveSession) {
|
||||
try {
|
||||
@@ -430,19 +425,19 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
}
|
||||
|
||||
protected class MyExternalizationSession implements ExternalizationSession {
|
||||
CompoundExternalizationSession myCompoundExternalizationSession = new CompoundExternalizationSession();
|
||||
final Map<StateStorage, StateStorage.ExternalizationSession> mySessions = new SmartHashMap<StateStorage, StateStorage.ExternalizationSession>();
|
||||
|
||||
@Override
|
||||
public void setState(@NotNull final Storage[] storageSpecs, @NotNull final Object component, final String componentName, @NotNull final Object state)
|
||||
throws StateStorageException {
|
||||
public void setState(@NotNull Storage[] storageSpecs, @NotNull Object component, @NotNull String componentName, @NotNull Object state) {
|
||||
assert mySession == this;
|
||||
|
||||
for (Storage storageSpec : storageSpecs) {
|
||||
StateStorage stateStorage = getStateStorage(storageSpec);
|
||||
if (stateStorage == null) continue;
|
||||
if (stateStorage == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final StateStorage.ExternalizationSession extSession = myCompoundExternalizationSession.getExternalizationSession(stateStorage);
|
||||
extSession.setState(component, componentName, state, storageSpec);
|
||||
getExternalizationSession(stateStorage).setState(component, componentName, state, storageSpec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,9 +446,18 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
assert mySession == this;
|
||||
StateStorage stateStorage = getOldStorage(component, componentName, StateStorageOperation.WRITE);
|
||||
if (stateStorage != null) {
|
||||
myCompoundExternalizationSession.getExternalizationSession(stateStorage).setState(component, componentName, state, null);
|
||||
getExternalizationSession(stateStorage).setState(component, componentName, state, null);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private StateStorage.ExternalizationSession getExternalizationSession(@NotNull StateStorage stateStore) {
|
||||
StateStorage.ExternalizationSession session = mySessions.get(stateStore);
|
||||
if (session == null) {
|
||||
mySessions.put(stateStore, session = stateStore.startExternalization());
|
||||
}
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,8 +475,8 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
private final Map<StateStorage, StateStorage.SaveSession> mySaveSessions = new SmartHashMap<StateStorage, StateStorage.SaveSession>();
|
||||
|
||||
public MySaveSession(@NotNull MyExternalizationSession externalizationSession) {
|
||||
for (StateStorage stateStorage : externalizationSession.myCompoundExternalizationSession.getStateStorages()) {
|
||||
mySaveSessions.put(stateStorage, stateStorage.startSave(externalizationSession.myCompoundExternalizationSession.getExternalizationSession(stateStorage)));
|
||||
for (StateStorage stateStorage : externalizationSession.mySessions.keySet()) {
|
||||
mySaveSessions.put(stateStorage, stateStorage.startSave(externalizationSession.getExternalizationSession(stateStorage)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user