From fcbe4c6949892aee308066aba980996e0dfd5bde Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 6 Dec 2017 12:58:36 +0100 Subject: [PATCH] =?UTF-8?q?migrate=20AppletConfiguration=20and=20BndRunCon?= =?UTF-8?q?figuration=20to=20BaseState=20=E2=80=94=20part=205,=20fix=20Cop?= =?UTF-8?q?yrightManagerTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellij/openapi/components/StoredProperty.kt | 11 +++++++++-- .../openapi/components/StoredPropertyBase.kt | 6 +++++- .../maddyhome/idea/copyright/CopyrightProfile.kt | 15 +++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt index 8d3a6b437eac..31574e2572e7 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt @@ -1,4 +1,6 @@ -// 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. +/* + * 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.openapi.components import com.intellij.openapi.diagnostic.logger @@ -66,9 +68,10 @@ abstract class BaseState : SerializationFilter, ModificationTracker { val getterName = (accessor as? PropertyAccessor)?.getterName for (property in properties) { if (property.name == accessor.name || property.name == getterName) { - return property.value != property.defaultValue + return !property.isEqualToDefault(property.defaultValue) } } + LOG.debug("Cannot find property by name: ${accessor.name}") // do not return false - maybe accessor delegates actual set to our property // default value in this case will be filtered by common filter (instance will be created in this case, as for non-smart state classes) @@ -183,6 +186,10 @@ private class NormalizedStringStoredProperty(override val defaultValue: String?) value = newValue return true } + + override fun isEqualToDefault(newValue: Any?): Boolean { + return value == newValue || (value == null && newValue != null && newValue is String && newValue.isEmpty()) + } } private class IntStoredProperty(override val defaultValue: Int) : StoredPropertyBase() { diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt b/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt index 167385e0a700..59c4a79af2a8 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt @@ -1,4 +1,6 @@ -// 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. +/* + * 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.openapi.components import kotlin.properties.ReadWriteProperty @@ -12,6 +14,8 @@ internal interface StoredProperty { // true if changed fun setValue(other: StoredProperty): Boolean + + fun isEqualToDefault(newValue: Any?): Boolean = value == newValue } // type must be exposed otherwise `provideDelegate` doesn't work diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt index de1c2c013992..af274135d7e0 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt @@ -1,6 +1,6 @@ -// 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. +/* + * 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.maddyhome.idea.copyright import com.intellij.configurationStore.SerializableScheme @@ -8,6 +8,7 @@ import com.intellij.configurationStore.serializeObjectInto import com.intellij.openapi.components.BaseState import com.intellij.openapi.options.ExternalizableScheme import com.intellij.util.xmlb.annotations.OptionTag +import com.intellij.util.xmlb.annotations.Transient import com.maddyhome.idea.copyright.pattern.EntityUtil import org.jdom.Element @@ -18,9 +19,11 @@ val DEFAULT_COPYRIGHT_NOTICE: String = EntityUtil.encode( "Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. \n" + "Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. \n" + "Vestibulum commodo. Ut rhoncus gravida arcu. ") - class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) : ExternalizableScheme, BaseState(), SerializableScheme { - private var profileName by string() + // ugly name to preserve compatibility + // must be not private because otherwise binding is not created for private accessor + @get:OptionTag("myName") + var profileName by string() var notice by string(DEFAULT_COPYRIGHT_NOTICE) var keyword by string(EntityUtil.encode("Copyright")) @@ -35,7 +38,7 @@ class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) : } // ugly name to preserve compatibility - @OptionTag("myName") + @Transient override fun getName() = profileName ?: "" override fun setName(value: String) {