diff --git a/platform/util/src/com/intellij/util/xmlb/Binding.java b/platform/util/src/com/intellij/util/xmlb/Binding.java index bac5dcf702b8..2a91831bc61c 100644 --- a/platform/util/src/com/intellij/util/xmlb/Binding.java +++ b/platform/util/src/com/intellij/util/xmlb/Binding.java @@ -38,6 +38,10 @@ abstract class Binding { @Nullable public abstract Object deserialize(Object context, @NotNull Object node); + public Object deserializeEmpty(Object context) { + return null; + } + public abstract boolean isBoundTo(Object node); public abstract Class getBoundNodeType(); @@ -52,8 +56,15 @@ abstract class Binding { return ((MultiNodeBinding)binding).deserializeList(context, nodes); } else { - assert nodes.size() == 1; - return binding.deserialize(context, nodes.get(0)); + if (nodes.size() == 1) { + return binding.deserialize(context, nodes.get(0)); + } + else if (nodes.isEmpty()) { + return binding.deserializeEmpty(context); + } + else { + throw new AssertionError("Duplicate data for " + binding + " will be ignored"); + } } } } diff --git a/platform/util/src/com/intellij/util/xmlb/DateBinding.java b/platform/util/src/com/intellij/util/xmlb/DateBinding.java index bc431c1d2f9e..571d4f78fc6e 100644 --- a/platform/util/src/com/intellij/util/xmlb/DateBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/DateBinding.java @@ -37,16 +37,10 @@ public class DateBinding extends PrimitiveValueBinding { @Override protected Object convertString(String value) { try { - long l = Long.parseLong(value); - return new Date(l); + return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { return new Date(0); } } - - @Override - public boolean isMulti() { - return false; - } } diff --git a/platform/util/src/com/intellij/util/xmlb/JDOMElementBinding.java b/platform/util/src/com/intellij/util/xmlb/JDOMElementBinding.java index ef33959f1e01..7208da0bff3f 100644 --- a/platform/util/src/com/intellij/util/xmlb/JDOMElementBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/JDOMElementBinding.java @@ -71,15 +71,7 @@ class JDOMElementBinding extends Binding implements MultiNodeBinding { myAccessor.write(context, nodes.toArray(new Element[nodes.size()])); } else { - Element element = null; - for (Object aNode : nodes) { - if (!XmlSerializerImpl.isIgnoredNode(aNode)) { - element = (Element)aNode; - break; - } - } - assert element != null; - myAccessor.write(context, element); + myAccessor.write(context, nodes.get(0)); } return context; } diff --git a/platform/util/src/com/intellij/util/xmlb/PrimitiveValueBinding.java b/platform/util/src/com/intellij/util/xmlb/PrimitiveValueBinding.java index cc103bd2c55e..effff09d5130 100644 --- a/platform/util/src/com/intellij/util/xmlb/PrimitiveValueBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/PrimitiveValueBinding.java @@ -21,9 +21,7 @@ import org.jdom.Text; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; - -class PrimitiveValueBinding extends Binding implements MultiNodeBinding { +class PrimitiveValueBinding extends Binding { private final Class myType; public PrimitiveValueBinding(@NotNull Class myType, @Nullable Accessor accessor) { @@ -37,35 +35,17 @@ class PrimitiveValueBinding extends Binding implements MultiNodeBinding { return new Text(String.valueOf(o)); } - @Nullable - @Override - public Object deserializeList(Object context, @NotNull List nodes) { - if (nodes.isEmpty()) { - return convertString(""); - } - else if (nodes.size() > 1) { - StringBuilder result = new StringBuilder(); - for (Object node : nodes) { - result.append(node instanceof Attribute ? ((Attribute)node).getValue() : ((Content)node).getValue()); - } - return convertString(result.toString()); - } - else { - return deserialize(context, nodes.get(0)); - } - } - - @Override - public boolean isMulti() { - return true; - } - @Override @Nullable public Object deserialize(Object o, @NotNull Object node) { return convertString(node instanceof Attribute ? ((Attribute)node).getValue() : ((Content)node).getValue()); } + @Override + public Object deserializeEmpty(Object context) { + return convertString(""); + } + @Nullable protected Object convertString(String value) { return XmlSerializerImpl.convert(value, myType);