mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup before use new kotlin-friendly xml deserializer
This commit is contained in:
@@ -24,10 +24,10 @@ import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.components.StateStorage.SaveSession
|
||||
import com.intellij.openapi.components.StateStorageChooserEx.Resolution
|
||||
import com.intellij.openapi.components.impl.ComponentManagerImpl
|
||||
import com.intellij.openapi.components.impl.stores.DefaultStateSerializer
|
||||
import com.intellij.openapi.components.impl.stores.IComponentStore
|
||||
import com.intellij.openapi.components.impl.stores.StoreUtil
|
||||
import com.intellij.openapi.components.impl.stores.UnknownMacroNotification
|
||||
import com.intellij.openapi.components.impl.stores.deserializeState
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
@@ -319,7 +319,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
if (changedStorages != null && changedStorages.contains(storage)) {
|
||||
// state will be null if file deleted
|
||||
// we must create empty (initial) state to reinit component
|
||||
state = DefaultStateSerializer.deserializeState(Element("state"), stateClass, null)!!
|
||||
state = deserializeState(Element("state"), stateClass, null)!!
|
||||
}
|
||||
else {
|
||||
continue
|
||||
@@ -368,7 +368,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
try {
|
||||
val documentElement = JDOMXIncluder.resolve(JDOMUtil.loadDocument(url), url.toExternalForm()).detachRootElement()
|
||||
getPathMacroManagerForDefaults()?.expandPaths(documentElement)
|
||||
return DefaultStateSerializer.deserializeState(documentElement, stateClass, null)
|
||||
return deserializeState(documentElement, stateClass, null)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw IOException("Error loading default state from $url", e)
|
||||
@@ -500,14 +500,7 @@ internal fun executeSave(session: SaveSession, readonlyFiles: MutableList<JBPair
|
||||
return errors
|
||||
}
|
||||
|
||||
private fun findNonDeprecated(storages: Array<Storage>): Storage {
|
||||
for (storage in storages) {
|
||||
if (!storage.deprecated) {
|
||||
return storage
|
||||
}
|
||||
}
|
||||
throw AssertionError("All storages are deprecated")
|
||||
}
|
||||
private fun findNonDeprecated(storages: Array<Storage>) = storages.firstOrNull { !it.deprecated } ?: throw AssertionError("All storages are deprecated")
|
||||
|
||||
enum class StateLoadPolicy {
|
||||
LOAD, LOAD_ONLY_DEFAULT, NOT_LOAD
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -17,7 +17,6 @@ package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.StateStorage
|
||||
import com.intellij.openapi.components.impl.stores.BatchUpdateListener
|
||||
import com.intellij.openapi.components.impl.stores.DefaultStateSerializer
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.util.messages.MessageBus
|
||||
@@ -40,7 +39,7 @@ abstract class StateStorageBase<T : Any> : StateStorage {
|
||||
}
|
||||
|
||||
open fun <S: Any> deserializeState(serializedState: Element?, stateClass: Class<S>, mergeInto: S?): S? {
|
||||
return DefaultStateSerializer.deserializeState(serializedState, stateClass, mergeInto)
|
||||
return com.intellij.openapi.components.impl.stores.deserializeState(serializedState, stateClass, mergeInto)
|
||||
}
|
||||
|
||||
abstract fun getSerializedState(storageData: T, component: Any?, componentName: String, archive: Boolean = true): Element?
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.intellij.core;
|
||||
import com.intellij.mock.MockProject;
|
||||
import com.intellij.openapi.components.ComponentManager;
|
||||
import com.intellij.openapi.components.PathMacroManager;
|
||||
import com.intellij.openapi.components.impl.stores.DefaultStateSerializer;
|
||||
import com.intellij.openapi.components.impl.stores.DefaultStateSerializerKt;
|
||||
import com.intellij.openapi.components.impl.stores.DirectoryStorageUtil;
|
||||
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -81,7 +81,7 @@ public class CoreProjectLoader {
|
||||
VirtualFile libraries = dotIdea.findChild("libraries");
|
||||
if (libraries != null) {
|
||||
Map<String, Element> data = DirectoryStorageUtil.loadFrom(libraries, PathMacroManager.getInstance(project));
|
||||
Element libraryTable = DefaultStateSerializer.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
|
||||
Element libraryTable = DefaultStateSerializerKt.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
|
||||
((LibraryTableBase) ProjectLibraryTable.getInstance(project)).loadState(libraryTable);
|
||||
}
|
||||
|
||||
|
||||
+27
-27
@@ -22,32 +22,32 @@ import com.intellij.util.ReflectionUtil
|
||||
import com.intellij.util.xmlb.XmlSerializer
|
||||
import org.jdom.Element
|
||||
|
||||
object DefaultStateSerializer {
|
||||
private val LOG = Logger.getInstance(DefaultStateSerializer::class.java)
|
||||
private val LOG = Logger.getInstance("#com.intellij.openapi.components.impl.stores.DefaultStateSerializer")
|
||||
|
||||
fun <T> deserializeState(stateElement: Element?, stateClass: Class<T>, mergeInto: T?): T? {
|
||||
if (stateElement == null) {
|
||||
return mergeInto
|
||||
}
|
||||
else if (stateClass == Element::class.java) {
|
||||
return stateElement as T?
|
||||
}
|
||||
else if (JDOMExternalizable::class.java.isAssignableFrom(stateClass)) {
|
||||
if (mergeInto != null) {
|
||||
val elementText = JDOMUtil.writeElement(stateElement)
|
||||
LOG.error("State is " + stateClass.name + ", merge into is " + mergeInto.toString() + ", state element text is " + elementText)
|
||||
}
|
||||
|
||||
val t = ReflectionUtil.newInstance(stateClass)
|
||||
(t as JDOMExternalizable).readExternal(stateElement)
|
||||
return t
|
||||
}
|
||||
else if (mergeInto == null) {
|
||||
return XmlSerializer.deserialize(stateElement, stateClass)
|
||||
}
|
||||
else {
|
||||
XmlSerializer.deserializeInto(mergeInto, stateElement)
|
||||
return mergeInto
|
||||
}
|
||||
fun <T> deserializeState(stateElement: Element?, stateClass: Class<T>, mergeInto: T?): T? {
|
||||
@Suppress("DEPRECATION")
|
||||
if (stateElement == null) {
|
||||
return mergeInto
|
||||
}
|
||||
}
|
||||
else if (stateClass == Element::class.java) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return stateElement as T?
|
||||
}
|
||||
else if (JDOMExternalizable::class.java.isAssignableFrom(stateClass)) {
|
||||
if (mergeInto != null) {
|
||||
val elementText = JDOMUtil.writeElement(stateElement)
|
||||
LOG.error("State is ${stateClass.name}, merge into is ${mergeInto.toString()}, state element text is $elementText")
|
||||
}
|
||||
|
||||
val t = ReflectionUtil.newInstance(stateClass)
|
||||
(t as JDOMExternalizable).readExternal(stateElement)
|
||||
return t
|
||||
}
|
||||
else if (mergeInto == null) {
|
||||
return XmlSerializer.deserialize(stateElement, stateClass)
|
||||
}
|
||||
else {
|
||||
XmlSerializer.deserializeInto(mergeInto, stateElement)
|
||||
return mergeInto
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user