diff --git a/java/execution/impl/src/com/intellij/execution/application/ApplicationConfigurationOptions.kt b/java/execution/impl/src/com/intellij/execution/application/ApplicationConfigurationOptions.kt index b2c07ef9af09..7c04a872a5c6 100644 --- a/java/execution/impl/src/com/intellij/execution/application/ApplicationConfigurationOptions.kt +++ b/java/execution/impl/src/com/intellij/execution/application/ApplicationConfigurationOptions.kt @@ -24,7 +24,6 @@ open class ApplicationConfigurationOptions : JvmConfigurationOptions() { @get:OptionTag("PASS_PARENT_ENVS") var isPassParentEnv by property(true) - @get:OptionTag(tag = "envs", nameAttribute = "") - @get:MapAnnotation(surroundWithTag = false, entryTagName = "env", keyAttributeName = "name", sortBeforeSave = false) + @get:MapAnnotation(propertyElementName = "envs", entryTagName = "env", keyAttributeName = "name", sortBeforeSave = false) var env by property(LinkedHashMap()) } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/wm/WindowInfoTest.kt b/platform/platform-tests/testSrc/com/intellij/wm/WindowInfoTest.kt index b3ad9168669e..c73750d08327 100644 --- a/platform/platform-tests/testSrc/com/intellij/wm/WindowInfoTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/wm/WindowInfoTest.kt @@ -3,16 +3,10 @@ */ package com.intellij.wm -import com.intellij.configurationStore.deserialize -import com.intellij.configurationStore.serialize -import com.intellij.openapi.components.BaseState -import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.wm.ToolWindowAnchor import com.intellij.openapi.wm.impl.WindowInfoImpl import com.intellij.testFramework.ProjectRule -import com.intellij.testFramework.assertions.Assertions.assertThat -import org.intellij.lang.annotations.Language -import org.jdom.Element +import com.intellij.testFramework.assertions.doSerializerTest import org.junit.ClassRule import org.junit.Test import java.awt.Rectangle @@ -53,21 +47,4 @@ internal class WindowInfoTest { a.floatingBounds = Rectangle(1, 42, 23, 4) doSerializerTest("""""", a) } -} - -private fun doSerializerTest(@Language("XML") expectedText: String, bean: T): T { - // test deserializer - val expectedTrimmed = expectedText.trimIndent() - val element = assertSerializer(bean, expectedTrimmed) - - // test deserializer - val o = (element ?: Element("state")).deserialize(bean.javaClass) - assertSerializer(o, expectedTrimmed, "Deserialization failure") - return o -} - -private fun assertSerializer(bean: Any, expected: String, description: String = "Serialization failure"): Element? { - val element = bean.serialize() - assertThat(element?.let { JDOMUtil.writeElement(element).trim() }).`as`(description).isEqualTo(expected) - return element } \ No newline at end of file diff --git a/platform/testFramework/extensions/src/com/intellij/testFramework/assertions/JdomAssert.kt b/platform/testFramework/extensions/src/com/intellij/testFramework/assertions/JdomAssert.kt index 71949ee4e138..ecd33a51875f 100644 --- a/platform/testFramework/extensions/src/com/intellij/testFramework/assertions/JdomAssert.kt +++ b/platform/testFramework/extensions/src/com/intellij/testFramework/assertions/JdomAssert.kt @@ -3,6 +3,8 @@ */ package com.intellij.testFramework.assertions +import com.intellij.configurationStore.deserialize +import com.intellij.configurationStore.serialize import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.text.StringUtilRt import com.intellij.rt.execution.junit.FileComparisonFailure @@ -11,6 +13,7 @@ import com.intellij.util.isEmpty import com.intellij.util.loadElement import org.assertj.core.api.AbstractAssert import org.assertj.core.internal.Objects +import org.intellij.lang.annotations.Language import org.jdom.Element import java.io.File import java.nio.file.Path @@ -62,4 +65,21 @@ class JdomAssert(actual: Element?) : AbstractAssert(actual return this } +} + +fun doSerializerTest(@Language("XML") expectedText: String, bean: T): T { + // test deserializer + val expectedTrimmed = expectedText.trimIndent() + val element = assertSerializer(bean, expectedTrimmed) + + // test deserializer + val o = (element ?: Element("state")).deserialize(bean.javaClass) + assertSerializer(o, expectedTrimmed, "Deserialization failure") + return o +} + +private fun assertSerializer(bean: Any, expected: String, description: String = "Serialization failure"): Element? { + val element = bean.serialize() + Assertions.assertThat(element?.let { JDOMUtil.writeElement(element).trim() }).`as`(description).isEqualTo(expected) + return element } \ No newline at end of file diff --git a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java index 03e9eebc8950..46b5c7b6ceaf 100644 --- a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java @@ -464,10 +464,15 @@ public class BeanBinding extends NotNullDeserializeBinding { } XCollection xCollection = accessor.getAnnotation(XCollection.class); - if (xCollection != null && (xCollection.propertyElementName().length() != 0 || xCollection.style() == XCollection.Style.v2)) { + if (xCollection != null && (!xCollection.propertyElementName().isEmpty() || xCollection.style() == XCollection.Style.v2)) { return new TagBinding(accessor, xCollection.propertyElementName()); } + MapAnnotation xMap = accessor.getAnnotation(MapAnnotation.class); + if (xMap != null && (!xMap.propertyElementName().isEmpty())) { + return new TagBinding(accessor, xMap.propertyElementName()); + } + if (propertyStyle == Property.Style.ATTRIBUTE) { return new AttributeBinding(accessor, null); } diff --git a/platform/util/src/com/intellij/util/xmlb/MapBinding.java b/platform/util/src/com/intellij/util/xmlb/MapBinding.java index cd1db88b1492..cfd6de33fde8 100644 --- a/platform/util/src/com/intellij/util/xmlb/MapBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/MapBinding.java @@ -1,16 +1,6 @@ -// 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. -// 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. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.util.xmlb; import com.intellij.util.ArrayUtil; @@ -76,7 +66,7 @@ class MapBinding extends Binding implements MultiNodeBinding { @Nullable @Override public Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) { - Element serialized = myMapAnnotation == null || myMapAnnotation.surroundWithTag() ? new Element(MAP) : (Element)context; + Element serialized = isSurroundWithTag() ? new Element(MAP) : (Element)context; assert serialized != null; Map map = (Map)o; @@ -96,6 +86,10 @@ class MapBinding extends Binding implements MultiNodeBinding { return serialized == context ? null : serialized; } + protected boolean isSurroundWithTag() { + return myMapAnnotation == null || (myMapAnnotation.surroundWithTag() && myMapAnnotation.propertyElementName().isEmpty()); + } + private String getEntryAttributeName() { return myMapAnnotation == null ? ENTRY : myMapAnnotation.entryTagName(); } @@ -112,7 +106,7 @@ class MapBinding extends Binding implements MultiNodeBinding { @Override public Object deserializeList(@Nullable Object context, @NotNull List elements) { List childNodes; - if (myMapAnnotation == null || myMapAnnotation.surroundWithTag()) { + if (isSurroundWithTag()) { assert elements.size() == 1; childNodes = elements.get(0).getChildren(); } @@ -129,7 +123,7 @@ class MapBinding extends Binding implements MultiNodeBinding { @Nullable public Object deserialize(@Nullable Object context, @NotNull Element element) { - if (myMapAnnotation == null || myMapAnnotation.surroundWithTag()) { + if (isSurroundWithTag()) { return deserialize(context, element.getChildren()); } else { diff --git a/platform/util/src/com/intellij/util/xmlb/annotations/MapAnnotation.java b/platform/util/src/com/intellij/util/xmlb/annotations/MapAnnotation.java index 7c11c28b19c0..b4fe017e6942 100644 --- a/platform/util/src/com/intellij/util/xmlb/annotations/MapAnnotation.java +++ b/platform/util/src/com/intellij/util/xmlb/annotations/MapAnnotation.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2009 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.util.xmlb.annotations; @@ -36,4 +24,6 @@ public @interface MapAnnotation { boolean surroundValueWithTag() default true; boolean sortBeforeSave() default true; + + String propertyElementName() default ""; }