diff --git a/plugins/devkit/src/actions/ShowSerializedXmlAction.java b/plugins/devkit/src/actions/ShowSerializedXmlAction.java index e7b1aeba3eda..47beab3b262a 100644 --- a/plugins/devkit/src/actions/ShowSerializedXmlAction.java +++ b/plugins/devkit/src/actions/ShowSerializedXmlAction.java @@ -45,6 +45,7 @@ import com.intellij.util.xmlb.MutableAccessor; import com.intellij.util.xmlb.XmlSerializationException; import com.intellij.util.xmlb.XmlSerializer; import com.intellij.util.xmlb.XmlSerializerUtil; +import com.intellij.util.xmlb.annotations.AbstractCollection; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -153,6 +154,11 @@ public class ShowSerializedXmlAction extends DumbAwareAction { @Nullable public Object createValue(Type type, final FList types) throws Exception { + return createValue(type, types, Collections.emptyList()); + } + + @Nullable + public Object createValue(Type type, final FList types, List elementTypes) throws Exception { if (types.contains(type)) return null; FList processedTypes = types.prepend(type); final Class valueClass = type instanceof Class ? (Class)type : (Class)((ParameterizedType)type).getRawType(); @@ -177,13 +183,13 @@ public class ShowSerializedXmlAction extends DumbAwareAction { return constants[(myNum++) % constants.length]; } else if (Collection.class.isAssignableFrom(valueClass) && type instanceof ParameterizedType) { - return createCollection(valueClass, (ParameterizedType)type, processedTypes); + return createCollection(valueClass, (ParameterizedType)type, processedTypes, elementTypes); } else if (Map.class.isAssignableFrom(valueClass) && type instanceof ParameterizedType) { return createMap((ParameterizedType)type, processedTypes); } else if (valueClass.isArray()) { - return createArray(valueClass, processedTypes); + return createArray(valueClass, processedTypes, elementTypes); } else if (Element.class.isAssignableFrom(valueClass)) { return new Element("customElement" + (myNum++)).setAttribute("attribute", "value" + (myNum++)).addContent(new Element("child" + (myNum++))); @@ -197,7 +203,9 @@ public class ShowSerializedXmlAction extends DumbAwareAction { public Object createObject(@NotNull Class aClass, FList processedTypes) throws Exception { Object o = ReflectionUtil.newInstance(aClass); for (MutableAccessor accessor : XmlSerializerUtil.getAccessors(aClass)) { - Object value = createValue(accessor.getGenericType(), processedTypes); + AbstractCollection abstractCollection = accessor.getAnnotation(AbstractCollection.class); + List elementTypes = abstractCollection != null ? Arrays.asList(abstractCollection.elementTypes()) : Collections.emptyList(); + Object value = createValue(accessor.getGenericType(), processedTypes, elementTypes); if (value != null) { accessor.set(o, value); } @@ -206,10 +214,11 @@ public class ShowSerializedXmlAction extends DumbAwareAction { } @Nullable - private Object createArray(Class valueClass, FList processedTypes) throws Exception { - final Object[] array = (Object[])Array.newInstance(valueClass.getComponentType(), 2); + private Object createArray(Class valueClass, FList processedTypes, List elementTypes) throws Exception { + final Object[] array = (Object[])Array.newInstance(valueClass.getComponentType(), Math.max(elementTypes.size(), 2)); for (int i = 0; i < array.length; i++) { - array[i] = createValue(valueClass.getComponentType(), processedTypes); + Type type = elementTypes.isEmpty() ? valueClass.getComponentType() : elementTypes.get(i % elementTypes.size()); + array[i] = createValue(type, processedTypes); } return array; } @@ -229,8 +238,7 @@ public class ShowSerializedXmlAction extends DumbAwareAction { } @Nullable - private Object createCollection(Class aClass, ParameterizedType genericType, FList processedTypes) throws Exception { - final Type elementClass = genericType.getActualTypeArguments()[0]; + private Object createCollection(Class aClass, ParameterizedType genericType, FList processedTypes, List elementTypes) throws Exception { Collection o; if (List.class.isAssignableFrom(aClass)) { o = new ArrayList(); @@ -241,8 +249,10 @@ public class ShowSerializedXmlAction extends DumbAwareAction { else { return null; } - for (int i = 0; i < 2; i++) { - final Object item = createValue(elementClass, processedTypes); + final Type elementClass = genericType.getActualTypeArguments()[0]; + for (int i = 0; i < Math.max(elementTypes.size(), 2); i++) { + Type type = elementTypes.isEmpty() ? elementClass : elementTypes.get(i % elementTypes.size()); + final Object item = createValue(type, processedTypes); if (item != null) { o.add(item); }