mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull
This commit is contained in:
@@ -136,7 +136,7 @@ public class JDOMUtil {
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@NotNull
|
||||
public static Object[] getChildNodesWithAttrs(final Element e) {
|
||||
public static Object[] getChildNodesWithAttrs(@NotNull Element e) {
|
||||
ArrayList<Object> result = new ArrayList<Object>();
|
||||
result.addAll(e.getContent());
|
||||
result.addAll(e.getAttributes());
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
@@ -130,7 +131,7 @@ abstract class AbstractCollectionBinding implements Binding {
|
||||
}
|
||||
}
|
||||
|
||||
public Object deserialize(Object o, Object... nodes) {
|
||||
public Object deserialize(Object o, @NotNull Object... nodes) {
|
||||
Collection result;
|
||||
|
||||
if (getTagName(o) != null) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.util.xmlb;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class AccessorBindingWrapper implements Binding {
|
||||
@@ -33,7 +34,7 @@ class AccessorBindingWrapper implements Binding {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object deserialize(Object context, Object... nodes) {
|
||||
public Object deserialize(Object context, @NotNull Object... nodes) {
|
||||
myAccessor.write(context, myBinding.deserialize(myAccessor.read(context), nodes));
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.util.xmlb;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AttributeBinding implements Binding {
|
||||
@@ -39,7 +40,7 @@ public class AttributeBinding implements Binding {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object deserialize(Object context, Object... nodes) {
|
||||
public Object deserialize(Object context, @NotNull Object... nodes) {
|
||||
assert nodes.length == 1;
|
||||
Object node = nodes[0];
|
||||
assert isBoundTo(node);
|
||||
|
||||
@@ -60,6 +60,7 @@ class BeanBinding implements Binding {
|
||||
assert !StringUtil.isEmptyOrSpaces(myTagName) : "Bean name is empty: " + beanClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
initPropertyBindings(myBeanClass);
|
||||
}
|
||||
@@ -72,6 +73,7 @@ class BeanBinding implements Binding {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(Object o, Object context, SerializationFilter filter) {
|
||||
Element element = new Element(myTagName);
|
||||
|
||||
@@ -112,15 +114,16 @@ class BeanBinding implements Binding {
|
||||
}
|
||||
}
|
||||
|
||||
public void deserializeInto(final Object bean, final Element element) {
|
||||
public void deserializeInto(final Object bean, @NotNull Element element) {
|
||||
_deserializeInto(bean, element);
|
||||
}
|
||||
|
||||
public Object deserialize(Object o, Object... nodes) {
|
||||
@Override
|
||||
public Object deserialize(Object o, @NotNull Object... nodes) {
|
||||
return _deserializeInto(instantiateBean(), nodes);
|
||||
}
|
||||
|
||||
private Object _deserializeInto(final Object result, final Object... aNodes) {
|
||||
private Object _deserializeInto(final Object result, @NotNull Object... aNodes) {
|
||||
List<Object> nodes = new ArrayList<Object>();
|
||||
for (Object aNode : aNodes) {
|
||||
if (XmlSerializerImpl.isIgnoredNode(aNode)) continue;
|
||||
@@ -181,10 +184,12 @@ class BeanBinding implements Binding {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoundTo(Object node) {
|
||||
return node instanceof Element && ((Element)node).getName().equals(myTagName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getBoundNodeType() {
|
||||
return Element.class;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
*/
|
||||
package com.intellij.util.xmlb;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
interface Binding {
|
||||
Object serialize(Object o, @Nullable Object context, SerializationFilter filter);
|
||||
|
||||
@Nullable
|
||||
Object deserialize(Object context, Object... nodes);
|
||||
Object deserialize(Object context, @NotNull Object... nodes);
|
||||
|
||||
boolean isBoundTo(Object node);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.util.xmlb;
|
||||
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -57,7 +58,7 @@ class JDOMElementBinding implements Binding {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object deserialize(Object context, Object... nodes) {
|
||||
public Object deserialize(Object context, @NotNull Object... nodes) {
|
||||
Element[] result = new Element[nodes.length];
|
||||
|
||||
System.arraycopy(nodes, 0, result, 0, nodes.length);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jdom.Attribute;
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -134,7 +135,7 @@ class MapBinding implements Binding {
|
||||
return myMapAnnotation == null ? KEY : myMapAnnotation.keyAttributeName();
|
||||
}
|
||||
|
||||
public Object deserialize(Object o, Object... nodes) {
|
||||
public Object deserialize(Object o, @NotNull Object... nodes) {
|
||||
Map map = (Map)o;
|
||||
map.clear();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jdom.Content;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -80,7 +81,7 @@ class OptionTagBinding implements Binding {
|
||||
return targetElement;
|
||||
}
|
||||
|
||||
public Object deserialize(Object o, Object... nodes) {
|
||||
public Object deserialize(Object o, @NotNull Object... nodes) {
|
||||
if (nodes.length > 1) {
|
||||
LOG.info("Duplicate options for " + o + " will be ignored");
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.util.xmlb;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class PrimitiveValueBinding implements Binding {
|
||||
@@ -33,7 +34,7 @@ class PrimitiveValueBinding implements Binding {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object deserialize(Object o, Object... nodes) {
|
||||
public Object deserialize(Object o, @NotNull Object... nodes) {
|
||||
assert nodes != null;
|
||||
|
||||
if (nodes.length == 0) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -53,7 +54,7 @@ class TagBinding implements Binding {
|
||||
return v;
|
||||
}
|
||||
|
||||
public Object deserialize(Object o, Object... nodes) {
|
||||
public Object deserialize(Object o, @NotNull Object... nodes) {
|
||||
assert nodes.length > 0;
|
||||
Object[] children;
|
||||
if (nodes.length == 1) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
//todo: merge with option tag binding
|
||||
class TagBindingWrapper implements Binding {
|
||||
@@ -51,7 +52,7 @@ class TagBindingWrapper implements Binding {
|
||||
return e;
|
||||
}
|
||||
|
||||
public Object deserialize(Object context, Object... nodes) {
|
||||
public Object deserialize(Object context, @NotNull Object... nodes) {
|
||||
assert nodes.length == 1;
|
||||
|
||||
Element e = (Element)nodes[0];
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.util.xmlb;
|
||||
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TextBinding implements Binding {
|
||||
@@ -36,7 +37,7 @@ public class TextBinding implements Binding {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object deserialize(Object context, Object... nodes) {
|
||||
public Object deserialize(Object context, @NotNull Object... nodes) {
|
||||
assert nodes.length == 1;
|
||||
Object node = nodes[0];
|
||||
assert isBoundTo(node);
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -28,6 +29,7 @@ import java.net.URL;
|
||||
|
||||
public class XmlSerializer {
|
||||
private static final SerializationFilter TRUE_FILTER = new SerializationFilter() {
|
||||
@Override
|
||||
public boolean accepts(Accessor accessor, Object bean) {
|
||||
return true;
|
||||
}
|
||||
@@ -54,8 +56,7 @@ public class XmlSerializer {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> T deserialize(Element element, Class<T> aClass) throws XmlSerializationException {
|
||||
try {
|
||||
XmlSerializerImpl serializer = new XmlSerializerImpl(TRUE_FILTER);
|
||||
return (T)serializer.getBinding(aClass).deserialize(null, element);
|
||||
return (T)XmlSerializerImpl.getBinding(aClass).deserialize(null, element);
|
||||
}
|
||||
catch (XmlSerializationException e) {
|
||||
throw e;
|
||||
@@ -91,10 +92,9 @@ public class XmlSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deserializeInto(final Object bean, final Element element) {
|
||||
public static void deserializeInto(@NotNull Object bean, @NotNull Element element) {
|
||||
try {
|
||||
XmlSerializerImpl serializer = new XmlSerializerImpl(TRUE_FILTER);
|
||||
final Binding binding = serializer.getBinding(bean.getClass());
|
||||
final Binding binding = XmlSerializerImpl.getBinding(bean.getClass());
|
||||
assert binding instanceof BeanBinding;
|
||||
|
||||
((BeanBinding)binding).deserializeInto(bean, element);
|
||||
@@ -116,8 +116,7 @@ public class XmlSerializer {
|
||||
filter = TRUE_FILTER;
|
||||
}
|
||||
try {
|
||||
XmlSerializerImpl serializer = new XmlSerializerImpl(filter);
|
||||
final Binding binding = serializer.getBinding(bean.getClass());
|
||||
final Binding binding = XmlSerializerImpl.getBinding(bean.getClass());
|
||||
assert binding instanceof BeanBinding;
|
||||
|
||||
((BeanBinding)binding).serializeInto(bean, element, filter);
|
||||
|
||||
Reference in New Issue
Block a user