mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
IJPL-136 convert Binding to modern language (part 2)
GitOrigin-RevId: 7fd14f87d5010c9901eb83a7cc49f4816b0f06f2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
04ecf61d3b
commit
3c3021230d
@@ -444,8 +444,8 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
}
|
||||
}
|
||||
|
||||
// method is not called if storage is deprecated or clear was requested
|
||||
// (state in these cases is null), but called if state is null if returned so from a component
|
||||
// method is not called if storage is deprecated or clear was requested (state in these cases is null),
|
||||
// but called if state is null if returned so from a component
|
||||
protected open fun setStateToSaveSessionProducer(
|
||||
state: Any?,
|
||||
info: ComponentInfo,
|
||||
|
||||
@@ -52,11 +52,11 @@ internal fun serializeState(state: Any, componentName: String): Element? {
|
||||
val binding = __platformSerializer().getRootBinding(state.javaClass)
|
||||
if (binding is BeanBinding) {
|
||||
// top level expects not null (null indicates error, an empty element will be omitted)
|
||||
return binding.serializeInto(host = state, preCreatedElement = null, filter = filter)
|
||||
return binding.serializeInto(bean = state, preCreatedElement = null, filter = filter)
|
||||
}
|
||||
else {
|
||||
// maybe ArrayBinding
|
||||
return binding.serialize(state, null, filter) as Element
|
||||
return binding.serialize(bean = state, context = null, filter = filter) as Element
|
||||
}
|
||||
}
|
||||
catch (e: SerializationException) {
|
||||
|
||||
@@ -159,7 +159,7 @@ internal fun serializeForController(obj: Any): Element? {
|
||||
val serializer = __platformSerializer()
|
||||
val binding = serializer.getRootBinding(obj.javaClass)
|
||||
if (binding is BeanBinding) {
|
||||
return binding.serializeInto(host = obj, preCreatedElement = null, filter = jdomSerializer.getDefaultSerializationFilter())
|
||||
return binding.serializeInto(bean = obj, preCreatedElement = null, filter = jdomSerializer.getDefaultSerializationFilter())
|
||||
}
|
||||
else {
|
||||
return binding.serialize(obj, null, jdomSerializer.getDefaultSerializationFilter()) as Element
|
||||
|
||||
@@ -37,10 +37,10 @@ class KotlinAwareBeanBinding(beanClass: Class<*>) : BeanBinding(beanClass) {
|
||||
return -1
|
||||
}
|
||||
|
||||
override fun serializeInto(host: Any, preCreatedElement: Element?, filter: SerializationFilter?): Element? {
|
||||
return when (host) {
|
||||
is BaseState -> serializeBaseStateInto(o = host, _element = preCreatedElement, filter = filter)
|
||||
else -> super.serializeInto(host = host, preCreatedElement = preCreatedElement, filter = filter)
|
||||
override fun serializeInto(bean: Any, preCreatedElement: Element?, filter: SerializationFilter?): Element? {
|
||||
return when (bean) {
|
||||
is BaseState -> serializeBaseStateInto(o = bean, _element = preCreatedElement, filter = filter)
|
||||
else -> super.serializeInto(bean = bean, preCreatedElement = preCreatedElement, filter = filter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class KotlinAwareBeanBinding(beanClass: Class<*>) : BeanBinding(beanClass) {
|
||||
for (i in 0 until bindingIndices.size) {
|
||||
element = serializePropertyInto(
|
||||
binding = bindings[bindingIndices.getInt(i)],
|
||||
host = o,
|
||||
bean = o,
|
||||
preCreatedElement = element,
|
||||
filter = filter,
|
||||
isFilterPropertyItself = false,
|
||||
|
||||
@@ -38,9 +38,9 @@ class KotlinxSerializationBinding(aClass: Class<*>) : NotNullDeserializeBinding
|
||||
serializer = lookup.findVirtual(companion.javaClass, "serializer", kotlinMethodType).invoke(companion) as KSerializer<Any>
|
||||
}
|
||||
|
||||
override fun serialize(o: Any, context: Any?, filter: SerializationFilter?): Element {
|
||||
override fun serialize(bean: Any, context: Any?, filter: SerializationFilter?): Element {
|
||||
val element = Element("state")
|
||||
val json = encodeToJson(o)
|
||||
val json = encodeToJson(bean)
|
||||
if (!json.isEmpty() && json != "{\n}") {
|
||||
element.addContent(CDATA(json))
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ inline fun <reified T: Any> deserialize(element: Element): T = jdomSerializer.de
|
||||
fun <T> Element.deserialize(clazz: Class<T>): T = jdomSerializer.deserialize(this, clazz)
|
||||
|
||||
fun Element.deserializeInto(bean: Any) {
|
||||
jdomSerializer.deserializeInto(bean, this)
|
||||
jdomSerializer.deserializeInto(obj = bean, element = this)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
|
||||
@@ -211,7 +211,7 @@ private class ControllerBackedSaveSessionProducer(
|
||||
|
||||
val element = beanBinding.serializePropertyInto(
|
||||
binding = binding,
|
||||
host = state,
|
||||
bean = state,
|
||||
preCreatedElement = null,
|
||||
filter = filter,
|
||||
isFilterPropertyItself = true,
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.util.xmlb.NotNullDeserializeBindingKt.LOG;
|
||||
import static com.intellij.util.xmlb.BindingKt.LOG;
|
||||
|
||||
abstract class AbstractCollectionBinding implements MultiNodeBinding, NestedBinding, NotNullDeserializeBinding {
|
||||
private final MutableAccessor accessor;
|
||||
@@ -176,7 +176,7 @@ abstract class AbstractCollectionBinding implements MultiNodeBinding, NestedBind
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NotNull Object deserializeJdomList(@Nullable Object context, @NotNull List<Element> elements) {
|
||||
public final @NotNull Object deserializeJdomList(@Nullable Object context, @NotNull List<? extends Element> elements) {
|
||||
if (!isSurroundWithTag()) {
|
||||
return doDeserializeJdomList(context, elements);
|
||||
}
|
||||
@@ -207,7 +207,7 @@ abstract class AbstractCollectionBinding implements MultiNodeBinding, NestedBind
|
||||
return doDeserializeList(context == null && element.name.equals(Constants.SET) ? new HashSet<>() : context, element.children);
|
||||
}
|
||||
|
||||
protected abstract @NotNull Object doDeserializeJdomList(@Nullable Object context, @NotNull List<Element> elements);
|
||||
protected abstract @NotNull Object doDeserializeJdomList(@Nullable Object context, @NotNull List<? extends Element> elements);
|
||||
|
||||
protected abstract @NotNull Object doDeserializeList(@Nullable Object context, @NotNull List<XmlElement> elements);
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ final class AccessorBindingWrapper implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Object value = accessor.read(o);
|
||||
public @Nullable Object serialize(@NotNull Object bean, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Object value = accessor.read(bean);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -132,13 +132,13 @@ final class AccessorBindingWrapper implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Object deserializeJdomList(@SuppressWarnings("NullableProblems") @NotNull Object context, @NotNull List<Element> elements) {
|
||||
public @NotNull Object deserializeJdomList(@SuppressWarnings("NullableProblems") @NotNull Object context, @NotNull List<? extends Element> elements) {
|
||||
Object currentValue = accessor.read(context);
|
||||
if (binding instanceof BeanBinding && !accessor.isWritable()) {
|
||||
((BeanBinding)binding).deserializeInto(currentValue, elements.get(0));
|
||||
}
|
||||
else {
|
||||
Object deserializedValue = Binding.deserializeJdomList(binding, currentValue, elements);
|
||||
Object deserializedValue = BindingKt.deserializeJdomList(binding, currentValue, elements);
|
||||
if (currentValue != deserializedValue) {
|
||||
accessor.set(context, deserializedValue);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ final class AccessorBindingWrapper implements MultiNodeBinding, NestedBinding {
|
||||
((BeanBinding)binding).deserializeInto(currentValue, elements.get(0));
|
||||
}
|
||||
else {
|
||||
Object deserializedValue = Binding.deserializeList(binding, currentValue, elements);
|
||||
Object deserializedValue = BindingKt.deserializeList(binding, currentValue, elements);
|
||||
if (currentValue != deserializedValue) {
|
||||
accessor.set(context, deserializedValue);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ final class ArrayBinding extends AbstractCollectionBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Object doDeserializeJdomList(@Nullable Object context, @NotNull List<Element> elements) {
|
||||
protected @NotNull Object doDeserializeJdomList(@Nullable Object context, @NotNull List<? extends Element> elements) {
|
||||
int size = elements.size();
|
||||
Object[] result = ArrayUtil.newArray(itemType, size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
@@ -47,8 +47,8 @@ public abstract class BasePrimitiveBinding implements PrimitiveValueBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @Nullable Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
return serialize(o, filter);
|
||||
public final @Nullable Object serialize(@NotNull Object bean, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
return serialize(bean, filter);
|
||||
}
|
||||
|
||||
public abstract @Nullable Object serialize(@NotNull Object o, @Nullable SerializationFilter filter);
|
||||
|
||||
@@ -67,24 +67,24 @@ open class BeanBinding(@JvmField val beanClass: Class<*>) : NotNullDeserializeBi
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(o: Any, context: Any?, filter: SerializationFilter?): Any? {
|
||||
return serializeInto(host = o, preCreatedElement = if (context == null) null else Element(tagName), filter = filter)
|
||||
override fun serialize(bean: Any, context: Any?, filter: SerializationFilter?): Any? {
|
||||
return serializeInto(bean = bean, preCreatedElement = if (context == null) null else Element(tagName), filter = filter)
|
||||
}
|
||||
|
||||
fun serialize(bean: Any, createElementIfEmpty: Boolean, filter: SerializationFilter?): Element? {
|
||||
return serializeInto(host = bean, preCreatedElement = if (createElementIfEmpty) Element(tagName) else null, filter = filter)
|
||||
return serializeInto(bean = bean, preCreatedElement = if (createElementIfEmpty) Element(tagName) else null, filter = filter)
|
||||
}
|
||||
|
||||
open fun serializeInto(host: Any, preCreatedElement: Element?, filter: SerializationFilter?): Element? {
|
||||
open fun serializeInto(bean: Any, preCreatedElement: Element?, filter: SerializationFilter?): Element? {
|
||||
var element = preCreatedElement
|
||||
for (binding in bindings!!) {
|
||||
if (host is SerializationFilter && !host.accepts(binding.accessor, host)) {
|
||||
if (bean is SerializationFilter && !bean.accepts(binding.accessor, bean)) {
|
||||
continue
|
||||
}
|
||||
|
||||
element = serializePropertyInto(
|
||||
binding = binding,
|
||||
host = host,
|
||||
bean = bean,
|
||||
preCreatedElement = element,
|
||||
filter = filter,
|
||||
isFilterPropertyItself = true,
|
||||
@@ -95,7 +95,7 @@ open class BeanBinding(@JvmField val beanClass: Class<*>) : NotNullDeserializeBi
|
||||
|
||||
fun serializePropertyInto(
|
||||
binding: NestedBinding,
|
||||
host: Any,
|
||||
bean: Any,
|
||||
preCreatedElement: Element?,
|
||||
filter: SerializationFilter?,
|
||||
isFilterPropertyItself: Boolean,
|
||||
@@ -106,11 +106,11 @@ open class BeanBinding(@JvmField val beanClass: Class<*>) : NotNullDeserializeBi
|
||||
if (property == null || !property.alwaysWrite) {
|
||||
if (filter != null && isFilterPropertyItself) {
|
||||
if (filter is SkipDefaultsSerializationFilter) {
|
||||
if (filter.equal(binding, host)) {
|
||||
if (filter.equal(binding, bean)) {
|
||||
return element
|
||||
}
|
||||
}
|
||||
else if (!filter.accepts(accessor, host)) {
|
||||
else if (!filter.accepts(accessor, bean)) {
|
||||
return element
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ open class BeanBinding(@JvmField val beanClass: Class<*>) : NotNullDeserializeBi
|
||||
//todo: optimize. Cache it.
|
||||
if (property != null) {
|
||||
val propertyFilter = XmlSerializerUtil.getPropertyFilter(property)
|
||||
if (propertyFilter != null && !propertyFilter.accepts(accessor, host)) {
|
||||
if (propertyFilter != null && !propertyFilter.accepts(accessor, bean)) {
|
||||
return element
|
||||
}
|
||||
}
|
||||
@@ -128,10 +128,10 @@ open class BeanBinding(@JvmField val beanClass: Class<*>) : NotNullDeserializeBi
|
||||
element = Element(tagName)
|
||||
}
|
||||
|
||||
val node = binding.serialize(host, element, filter)
|
||||
val node = binding.serialize(bean = bean, context = element, filter = filter)
|
||||
if (node != null) {
|
||||
if (node is Attribute) {
|
||||
element.setAttribute(node as Attribute?)
|
||||
element.setAttribute(node)
|
||||
}
|
||||
else {
|
||||
BasePrimitiveBinding.addContent(element, node)
|
||||
@@ -261,7 +261,7 @@ fun deserializeBeanInto(
|
||||
return
|
||||
}
|
||||
|
||||
var data: LinkedHashMap<MultiNodeBinding, MutableList<XmlElement?>>? = null
|
||||
var data: LinkedHashMap<MultiNodeBinding, MutableList<XmlElement>>? = null
|
||||
nextNode@ for (child in element.children) {
|
||||
for (i in start until end) {
|
||||
val binding = bindings[i]
|
||||
|
||||
@@ -1,59 +1,81 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.xmlb;
|
||||
@file:Suppress("ReplaceGetOrSet")
|
||||
|
||||
import com.intellij.util.xml.dom.XmlElement;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
package com.intellij.util.xmlb
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.serialization.MutableAccessor
|
||||
import com.intellij.util.xml.dom.XmlElement
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.lang.reflect.Type
|
||||
|
||||
public interface Binding {
|
||||
@Nullable Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter);
|
||||
@JvmField
|
||||
internal val LOG: Logger = logger<Binding>()
|
||||
|
||||
boolean isBoundTo(@NotNull Element element);
|
||||
interface Serializer {
|
||||
fun getRootBinding(aClass: Class<*>, originalType: Type): Binding
|
||||
|
||||
boolean isBoundTo(@NotNull XmlElement element);
|
||||
fun getRootBinding(aClass: Class<*>): Binding = getRootBinding(aClass = aClass, originalType = aClass)
|
||||
|
||||
default void init(@NotNull Type originalType, @NotNull Serializer serializer) {
|
||||
}
|
||||
fun getBinding(accessor: MutableAccessor): Binding?
|
||||
|
||||
static @Nullable Object deserializeJdomList(@NotNull Binding binding, @Nullable Object context, @NotNull List<Element> nodes) {
|
||||
if (binding instanceof MultiNodeBinding) {
|
||||
return ((MultiNodeBinding)binding).deserializeJdomList(context, nodes);
|
||||
}
|
||||
else {
|
||||
if (nodes.size() == 1) {
|
||||
return binding.deserializeUnsafe(context, nodes.get(0));
|
||||
}
|
||||
else if (nodes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("Duplicate data for " + binding + " will be ignored");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static @Nullable Object deserializeList(@NotNull Binding binding, @Nullable Object context, @NotNull List<XmlElement> nodes) {
|
||||
if (binding instanceof MultiNodeBinding) {
|
||||
return ((MultiNodeBinding)binding).deserializeList(context, nodes);
|
||||
}
|
||||
else {
|
||||
if (nodes.size() == 1) {
|
||||
return binding.deserializeUnsafe(context, nodes.get(0));
|
||||
}
|
||||
else if (nodes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("Duplicate data for " + binding + " will be ignored");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object deserializeUnsafe(Object context, @NotNull Element element);
|
||||
|
||||
Object deserializeUnsafe(Object context, @NotNull XmlElement element);
|
||||
fun getBinding(aClass: Class<*>, type: Type): Binding?
|
||||
}
|
||||
|
||||
fun interface SerializationFilter {
|
||||
fun accepts(accessor: Accessor, bean: Any): Boolean
|
||||
}
|
||||
|
||||
interface Binding {
|
||||
fun serialize(bean: Any, context: Any?, filter: SerializationFilter?): Any?
|
||||
|
||||
fun isBoundTo(element: Element): Boolean
|
||||
|
||||
fun isBoundTo(element: XmlElement): Boolean
|
||||
|
||||
fun init(originalType: Type, serializer: Serializer) {
|
||||
}
|
||||
|
||||
fun deserializeUnsafe(context: Any?, element: Element): Any?
|
||||
|
||||
fun deserializeUnsafe(context: Any?, element: XmlElement): Any?
|
||||
}
|
||||
|
||||
internal fun deserializeJdomList(binding: Binding, context: Any?, nodes: List<Element>): Any? {
|
||||
return when {
|
||||
binding is MultiNodeBinding -> binding.deserializeJdomList(context = context, elements = nodes)
|
||||
nodes.size == 1 -> binding.deserializeUnsafe(context, nodes.get(0))
|
||||
nodes.isEmpty() -> null
|
||||
else -> throw AssertionError("Duplicate data for $binding will be ignored")
|
||||
}
|
||||
}
|
||||
|
||||
internal fun deserializeList(binding: Binding, context: Any?, nodes: List<XmlElement>): Any? {
|
||||
return when {
|
||||
binding is MultiNodeBinding -> binding.deserializeList(context = context, elements = nodes)
|
||||
nodes.size == 1 -> binding.deserializeUnsafe(context, nodes[0])
|
||||
nodes.isEmpty() -> null
|
||||
else -> throw AssertionError("Duplicate data for $binding will be ignored")
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
interface MultiNodeBinding : Binding {
|
||||
val isMulti: Boolean
|
||||
|
||||
fun deserializeJdomList(context: Any?, elements: List<Element>): Any?
|
||||
|
||||
fun deserializeList(context: Any?, elements: List<XmlElement>): Any?
|
||||
}
|
||||
|
||||
interface NotNullDeserializeBinding : Binding {
|
||||
fun deserialize(context: Any?, element: Element): Any
|
||||
|
||||
fun deserialize(context: Any?, element: XmlElement): Any
|
||||
|
||||
override fun deserializeUnsafe(context: Any?, element: Element): Any = deserialize(context = context, element = element)
|
||||
|
||||
override fun deserializeUnsafe(context: Any?, element: XmlElement): Any = deserialize(context = context, element = element)
|
||||
}
|
||||
@@ -18,7 +18,7 @@ final class CollectionBinding extends AbstractCollectionBinding {
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
protected @NotNull Object doDeserializeJdomList(@Nullable Object context, @NotNull List<Element> elements) {
|
||||
protected @NotNull Object doDeserializeJdomList(@Nullable Object context, @NotNull List<? extends Element> elements) {
|
||||
Collection<Object> result;
|
||||
boolean isContextMutable = context != null && ClassUtil.isMutableCollection(context);
|
||||
if (isContextMutable) {
|
||||
|
||||
@@ -29,10 +29,10 @@ final class CompactCollectionBinding implements NotNullDeserializeBinding, Neste
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
public @NotNull Object serialize(@NotNull Object bean, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Element result = new Element(name);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> list = (List<String>)o;
|
||||
List<String> list = (List<String>)bean;
|
||||
if (list.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ final class JDOMElementBinding implements MultiNodeBinding, NestedBinding, NotNu
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Object value = accessor.read(o);
|
||||
public Object serialize(@NotNull Object bean, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Object value = accessor.read(bean);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ final class JDOMElementBinding implements MultiNodeBinding, NestedBinding, NotNu
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Object deserializeJdomList(@SuppressWarnings("NullableProblems") @NotNull Object context, @NotNull List<Element> elements) {
|
||||
public @NotNull Object deserializeJdomList(@SuppressWarnings("NullableProblems") @NotNull Object context, @NotNull List<? extends Element> elements) {
|
||||
if (accessor.getValueClass().isArray()) {
|
||||
accessor.set(context, elements.toArray(new Element[0]));
|
||||
}
|
||||
|
||||
@@ -105,12 +105,12 @@ final class MapBinding implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
public @Nullable Object serialize(@NotNull Object bean, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Element serialized = isSurroundWithTag() ? new Element(MAP) : (Element)context;
|
||||
assert serialized != null;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map map = (Map)o;
|
||||
Map map = (Map)bean;
|
||||
Object[] keys = ArrayUtil.toObjectArray(map.keySet());
|
||||
if (isSortMap(map)) {
|
||||
Arrays.sort(keys, KEY_COMPARATOR);
|
||||
@@ -154,7 +154,7 @@ final class MapBinding implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object deserializeJdomList(@Nullable Object context, @NotNull List<Element> elements) {
|
||||
public @Nullable Object deserializeJdomList(@Nullable Object context, @NotNull List<? extends Element> elements) {
|
||||
List<Element> childNodes;
|
||||
if (isSurroundWithTag()) {
|
||||
if (elements.size() == 1) {
|
||||
@@ -168,7 +168,8 @@ final class MapBinding implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
}
|
||||
else {
|
||||
childNodes = elements;
|
||||
//noinspection unchecked
|
||||
childNodes = (List<Element>)elements;
|
||||
}
|
||||
return deserialize(context, childNodes);
|
||||
}
|
||||
@@ -342,7 +343,7 @@ final class MapBinding implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
else {
|
||||
assert binding != null;
|
||||
return Binding.deserializeJdomList(binding, null, children);
|
||||
return BindingKt.deserializeJdomList(binding, null, children);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -373,7 +374,7 @@ final class MapBinding implements MultiNodeBinding, NestedBinding {
|
||||
}
|
||||
else {
|
||||
assert binding != null;
|
||||
return Binding.deserializeList(binding, null, children);
|
||||
return BindingKt.deserializeList(binding, null, children);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.xmlb;
|
||||
|
||||
import com.intellij.util.xml.dom.XmlElement;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public interface MultiNodeBinding extends Binding {
|
||||
@Nullable Object deserializeJdomList(@Nullable Object context, @NotNull List<Element> elements);
|
||||
|
||||
@Nullable Object deserializeList(@Nullable Object context, @NotNull List<XmlElement> elements);
|
||||
|
||||
boolean isMulti();
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.xmlb
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.util.xml.dom.XmlElement
|
||||
import org.jdom.Element
|
||||
|
||||
@JvmField
|
||||
internal val LOG: Logger = logger<Binding>()
|
||||
|
||||
interface NotNullDeserializeBinding : Binding {
|
||||
fun deserialize(context: Any?, element: Element): Any
|
||||
|
||||
fun deserialize(context: Any?, element: XmlElement): Any
|
||||
|
||||
override fun deserializeUnsafe(context: Any?, element: Element): Any = deserialize(context = context, element = element)
|
||||
|
||||
override fun deserializeUnsafe(context: Any?, element: XmlElement): Any = deserialize(context = context, element = element)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class OptionTagBinding internal constructor(accessor: MutableAccessor, optionTag
|
||||
targetElement.setAttribute(valueAttribute!!, JDOMUtil.removeControlChars(XmlSerializerImpl.convertToString(value)))
|
||||
}
|
||||
else if (binding is BeanBinding && valueAttribute == null) {
|
||||
binding.serializeInto(host = value, preCreatedElement = targetElement, filter = filter)
|
||||
binding.serializeInto(bean = value, preCreatedElement = targetElement, filter = filter)
|
||||
}
|
||||
else {
|
||||
val node = binding.serialize(value, targetElement, filter)
|
||||
@@ -105,7 +105,7 @@ class OptionTagBinding internal constructor(accessor: MutableAccessor, optionTag
|
||||
}
|
||||
else {
|
||||
val oldValue = accessor.read(context)
|
||||
val newValue = Binding.deserializeJdomList(binding!!, oldValue, children)
|
||||
val newValue = deserializeJdomList(binding = binding!!, context = oldValue, nodes = children)
|
||||
if (oldValue !== newValue) {
|
||||
accessor.set(context, newValue)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class OptionTagBinding internal constructor(accessor: MutableAccessor, optionTag
|
||||
}
|
||||
else {
|
||||
val oldValue = accessor.read(context)
|
||||
val newValue = Binding.deserializeList(binding!!, oldValue, children)
|
||||
val newValue = deserializeList(binding = binding!!, context = oldValue, nodes = children)
|
||||
if (oldValue !== newValue) {
|
||||
accessor.set(context, newValue)
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.util.xmlb;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface SerializationFilter {
|
||||
boolean accepts(@NotNull Accessor accessor, @NotNull Object bean);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.xmlb;
|
||||
|
||||
import com.intellij.serialization.MutableAccessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public interface Serializer {
|
||||
@NotNull
|
||||
Binding getRootBinding(@NotNull Class<?> aClass, @NotNull Type originalType);
|
||||
|
||||
default Binding getRootBinding(@NotNull Class<?> aClass) {
|
||||
return getRootBinding(aClass, aClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Binding getBinding(@NotNull MutableAccessor accessor);
|
||||
|
||||
@Nullable
|
||||
Binding getBinding(@NotNull Class<?> aClass, @NotNull Type type);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ final class TagBinding extends BasePrimitiveBinding implements MultiNodeBinding
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Object deserializeJdomList(@NotNull Object context, @NotNull List<Element> elements) {
|
||||
public @NotNull Object deserializeJdomList(@NotNull Object context, @NotNull List<? extends Element> elements) {
|
||||
List<Element> children;
|
||||
if (elements.size() == 1) {
|
||||
children = elements.get(0).getChildren();
|
||||
@@ -127,10 +127,10 @@ final class TagBinding extends BasePrimitiveBinding implements MultiNodeBinding
|
||||
((BeanBinding)binding).deserializeInto(context, children.get(0));
|
||||
}
|
||||
else if ((binding instanceof CollectionBinding || binding instanceof MapBinding) && !accessor.isWritable()) {
|
||||
Binding.deserializeJdomList(binding, accessor.read(context), children);
|
||||
BindingKt.deserializeJdomList(binding, accessor.read(context), children);
|
||||
}
|
||||
else {
|
||||
accessor.set(context, Binding.deserializeJdomList(binding, accessor.read(context), children));
|
||||
accessor.set(context, BindingKt.deserializeJdomList(binding, accessor.read(context), children));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,10 +140,10 @@ final class TagBinding extends BasePrimitiveBinding implements MultiNodeBinding
|
||||
((BeanBinding)binding).deserializeInto(context, children.get(0));
|
||||
}
|
||||
else if ((binding instanceof CollectionBinding || binding instanceof MapBinding) && !accessor.isWritable()) {
|
||||
Binding.deserializeList(binding, accessor.read(context), children);
|
||||
BindingKt.deserializeList(binding, accessor.read(context), children);
|
||||
}
|
||||
else {
|
||||
accessor.set(context, Binding.deserializeList(binding, accessor.read(context), children));
|
||||
accessor.set(context, BindingKt.deserializeList(binding, accessor.read(context), children));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ final class TextBinding implements PrimitiveValueBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Object value = accessor.read(o);
|
||||
public @Nullable Object serialize(@NotNull Object bean, @Nullable Object context, @Nullable SerializationFilter filter) {
|
||||
Object value = accessor.read(bean);
|
||||
return value == null ? null : new Text(XmlSerializerImpl.convertToString(value));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user