mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move use.loaded.state.as.existing check to correct place
This commit is contained in:
@@ -33,7 +33,6 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util
|
||||
import com.intellij.openapi.util.*
|
||||
import com.intellij.openapi.util.Pair
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
|
||||
import com.intellij.util.ArrayUtilRt
|
||||
@@ -249,7 +248,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
}
|
||||
|
||||
val storage = storageManager.getStateStorage(storageSpec)
|
||||
var stateGetter = if (Registry.`is`("use.loaded.state.as.existing", false)) (storage as? StorageBaseEx<*>)?.createGetSession(component, name, stateClass) else null
|
||||
var stateGetter = (storage as? StorageBaseEx<*>)?.createGetSession(component, name, stateClass)
|
||||
var state = if (stateGetter == null) storage.getState(component, name, stateClass, defaultState, reloadData) else stateGetter.getState(defaultState)
|
||||
if (state == null) {
|
||||
if (changedStorages != null && changedStorages.contains(storage)) {
|
||||
@@ -262,12 +261,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
component.loadState(state)
|
||||
}
|
||||
finally {
|
||||
stateGetter?.close()
|
||||
}
|
||||
stateGetter?.use { component.loadState(state) }
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.impl.stores.StateStorageBase
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import org.jdom.Element
|
||||
import java.io.Closeable
|
||||
|
||||
abstract class StorageBaseEx<T : Any> : StateStorageBase<T>() {
|
||||
fun <S : Any> createGetSession(component: PersistentStateComponent<S>, componentName: String, stateClass: Class<S>, reload: Boolean = false) = StateGetter(component, componentName, getStorageData(reload), stateClass, this)
|
||||
@@ -28,7 +31,7 @@ abstract class StorageBaseEx<T : Any> : StateStorageBase<T>() {
|
||||
abstract fun archiveState(storageData: T, componentName: String, serializedState: Element?)
|
||||
}
|
||||
|
||||
class StateGetter<S : Any, T : Any>(private val component: PersistentStateComponent<S>, private val componentName: String, private val storageData: T, private val stateClass: Class<S>, private val storage: StorageBaseEx<T>) {
|
||||
class StateGetter<S : Any, T : Any>(private val component: PersistentStateComponent<S>, private val componentName: String, private val storageData: T, private val stateClass: Class<S>, private val storage: StorageBaseEx<T>) : Closeable {
|
||||
var serializedState: Element? = null
|
||||
|
||||
fun getState(mergeInto: S? = null): S? {
|
||||
@@ -41,10 +44,7 @@ class StateGetter<S : Any, T : Any>(private val component: PersistentStateCompon
|
||||
return storage.deserializeState(serializedState, stateClass, mergeInto)
|
||||
}
|
||||
|
||||
/**
|
||||
* nullable - because PersistentStateComponent can return nullable state
|
||||
*/
|
||||
fun close() {
|
||||
override fun close() {
|
||||
if (serializedState == null) {
|
||||
return
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class StateGetter<S : Any, T : Any>(private val component: PersistentStateCompon
|
||||
|
||||
val stateAfterLoad: S?
|
||||
try {
|
||||
stateAfterLoad = component.getState()
|
||||
stateAfterLoad = if (ApplicationManager.getApplication().isUnitTestMode() || Registry.`is`("use.loaded.state.as.existing", false)) component.getState() else null
|
||||
}
|
||||
catch(e: Throwable) {
|
||||
LOG.error("Cannot get state after load", e)
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.components.StateStorage
|
||||
import com.intellij.openapi.components.TrackingPathMacroSubstitutor
|
||||
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.SmartHashSet
|
||||
import gnu.trove.THashMap
|
||||
@@ -38,9 +37,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
|
||||
protected abstract fun loadLocalData(): Element?
|
||||
|
||||
override final fun getState(storageData: StateMap, component: Any?, componentName: String): Element? {
|
||||
return if (Registry.`is`("use.loaded.state.as.existing", false)) storageData.getState(componentName) else storageData.getStateAndArchive(componentName)
|
||||
}
|
||||
override final fun getState(storageData: StateMap, component: Any?, componentName: String) = storageData.getState(componentName)
|
||||
|
||||
override fun archiveState(storageData: StateMap, componentName: String, serializedState: Element?) {
|
||||
storageData.archive(componentName, serializedState)
|
||||
|
||||
Reference in New Issue
Block a user