From 967b4644a121727b703f5e9fad869a54db625cbe Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 3 May 2017 09:49:59 +0200 Subject: [PATCH] revert kotlin 1.1 usages because kotlin 1.1.0 doesn't support facets correctly --- .../configuration-store-impl.iml | 13 --- .../src/ProjectStoreImpl.kt | 2 +- .../testSrc/StoredPropertyStateTest.kt | 6 -- .../configuration-store-impl/testSrc/foo.kt | 30 ------ .../projectModel-api/projectModel-api.iml | 13 --- .../openapi/components/StoredProperty.kt | 97 +++++++++++++------ .../openapi/components/StoredPropertyBase.kt | 38 -------- .../projectModel-impl/projectModel-impl.iml | 13 --- .../configurationStore/xmlSerializer.kt | 2 +- 9 files changed, 71 insertions(+), 143 deletions(-) delete mode 100644 platform/configuration-store-impl/testSrc/foo.kt delete mode 100644 platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt diff --git a/platform/configuration-store-impl/configuration-store-impl.iml b/platform/configuration-store-impl/configuration-store-impl.iml index ba6c8becb220..560f011ecfe3 100644 --- a/platform/configuration-store-impl/configuration-store-impl.iml +++ b/platform/configuration-store-impl/configuration-store-impl.iml @@ -1,18 +1,5 @@ - - - - - - - - - diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 46eb84694fb1..51e0669c5f8c 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -432,7 +432,7 @@ private fun removeWorkspaceComponentConfiguration(defaultProject: Project, eleme } } - ServiceManagerImpl.processAllImplementationClasses(defaultProject as ProjectImpl) { aClass, _ -> + ServiceManagerImpl.processAllImplementationClasses(defaultProject as ProjectImpl) { aClass, pluginDescriptor -> getNameIfWorkspaceStorage(aClass)?.let { workspaceComponentNames.add(it) } diff --git a/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt b/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt index 0a93ba85e5fa..0513b79320de 100644 --- a/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt +++ b/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt @@ -10,8 +10,6 @@ internal class AState : BaseState() { @get:Attribute("customName") var languageLevel by storedProperty() - var bar by string() - var property2 by storedProperty(0) var floatProperty by storedProperty(0.3) @@ -39,10 +37,6 @@ class StoredPropertyStateTest { assertThat(state).isNotEqualTo(AState()) - val newEqualState = AState() - newEqualState.languageLevel = String("foo".toCharArray()) - assertThat(state).isEqualTo(newEqualState) - assertThat(state.serialize()).isEqualTo("""""") assertThat(loadElement("""""").deserialize(AState::class.java).languageLevel).isEqualTo("foo") } diff --git a/platform/configuration-store-impl/testSrc/foo.kt b/platform/configuration-store-impl/testSrc/foo.kt deleted file mode 100644 index a52f2d2279bd..000000000000 --- a/platform/configuration-store-impl/testSrc/foo.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.intellij.configurationStore - -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -class ResourceLoader(id: String) : ReadOnlyProperty { - operator fun provideDelegate(thisRef: MyUI, prop: KProperty<*>): ReadOnlyProperty { - checkProperty(thisRef, prop.name) - return this - } - - override fun getValue(thisRef: MyUI, property: KProperty<*>): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - private fun checkProperty(thisRef: MyUI, name: String) {} -} - -fun bindResource(id: String): ResourceLoader { - return ResourceLoader(id) -} - -class MyUI { - val image by bindResource("f") - val text by bindResource("d") -} - -fun main(a: Array) { - MyUI() -} \ No newline at end of file diff --git a/platform/projectModel-api/projectModel-api.iml b/platform/projectModel-api/projectModel-api.iml index f628f20bddfd..ecbad134ebbe 100644 --- a/platform/projectModel-api/projectModel-api.iml +++ b/platform/projectModel-api/projectModel-api.iml @@ -1,18 +1,5 @@ - - - - - - - - - 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 1db9e111d381..c6fb2f2dd884 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt @@ -20,6 +20,7 @@ import com.intellij.util.SmartList import com.intellij.util.xmlb.Accessor import com.intellij.util.xmlb.SerializationFilter import com.intellij.util.xmlb.annotations.Transient +import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty abstract class BaseState : SerializationFilter, ModificationTracker { @@ -38,7 +39,16 @@ abstract class BaseState : SerializationFilter, ModificationTracker { modificationCount++ } - fun storedProperty(defaultValue: T? = null): StoredPropertyBase { + override fun accepts(accessor: Accessor, bean: Any): Boolean { + for (property in properties) { + if (property.name == accessor.name) { + return property.value != property.defaultValue + } + } + return false + } + + fun storedProperty(defaultValue: T? = null): ReadWriteProperty { val result = ObjectStoredProperty(defaultValue) properties.add(result) return result @@ -47,39 +57,30 @@ abstract class BaseState : SerializationFilter, ModificationTracker { /** * Empty string is always normalized to null. */ - fun string(defaultValue: String? = null): StoredPropertyBase { - val result = NormalizedStringStoredProperty(defaultValue) + fun string(defaultValue: String? = null): ReadWriteProperty { + val result = StringStoredProperty(defaultValue) properties.add(result) return result } - fun storedProperty(defaultValue: Int = 0): StoredPropertyBase { + fun storedProperty(defaultValue: Int = 0): ReadWriteProperty { val result = IntStoredProperty(defaultValue) properties.add(result) return result } - fun storedProperty(defaultValue: Float = 0f): StoredPropertyBase { + fun storedProperty(defaultValue: Float = 0f): ReadWriteProperty { val result = FloatStoredProperty(defaultValue) properties.add(result) return result } - fun storedProperty(defaultValue: Boolean = false): StoredPropertyBase { + fun storedProperty(defaultValue: Boolean = false): ReadWriteProperty { val result = ObjectStoredProperty(defaultValue) properties.add(result) return result } - override fun accepts(accessor: Accessor, bean: Any): Boolean { - for (property in properties) { - if (property.name == accessor.name) { - return property.value != property.defaultValue - } - } - return false - } - @Transient override fun getModificationCount(): Long { var result = modificationCount @@ -113,19 +114,41 @@ abstract class BaseState : SerializationFilter, ModificationTracker { assert(state.properties.size == properties.size) for ((index, property) in properties.withIndex()) { val otherProperty = state.properties.get(index) - assert(otherProperty.name == property.name) + if (property.name != null) { + if (otherProperty.name == null) { + otherProperty.name = property.name + } + else { + assert(otherProperty.name == property.name) + } + } property.setValue(otherProperty) } } } -private class ObjectStoredProperty(override val defaultValue: T) : StoredPropertyBase() { - override var value = defaultValue +internal interface StoredProperty { + val defaultValue: Any? + val value: Any? - override operator fun getValue(thisRef: BaseState, property: KProperty<*>) = value + var name: String? + + fun setValue(other: StoredProperty) +} + +private class ObjectStoredProperty(override val defaultValue: T) : ReadWriteProperty, StoredProperty { + override var value = defaultValue + override var name: String? = null + + override operator fun getValue(thisRef: BaseState, property: KProperty<*>): T { + name = property.name + return value + } @Suppress("UNCHECKED_CAST") override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") newValue: T) { + name = property.name + if (value != newValue) { thisRef.modificationCount++ @@ -137,7 +160,7 @@ private class ObjectStoredProperty(override val defaultValue: T) : StoredProp override fun hashCode() = value?.hashCode() ?: 0 - override fun toString() = if (value == defaultValue) "" else value?.toString() ?: super.toString() + override fun toString() = if (value === defaultValue) "" else value?.toString() ?: super.toString() override fun setValue(other: StoredProperty) { @Suppress("UNCHECKED_CAST") @@ -145,13 +168,19 @@ private class ObjectStoredProperty(override val defaultValue: T) : StoredProp } } -private class NormalizedStringStoredProperty(override val defaultValue: String?) : StoredPropertyBase() { +private class StringStoredProperty(override val defaultValue: String?) : ReadWriteProperty, StoredProperty { override var value = defaultValue + override var name: String? = null - override operator fun getValue(thisRef: BaseState, property: KProperty<*>) = value + override operator fun getValue(thisRef: BaseState, property: KProperty<*>): String? { + name = property.name + return value + } @Suppress("UNCHECKED_CAST") override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") _newValue: String?) { + name = property.name + var newValue = _newValue if (newValue != null && newValue.isEmpty()) { newValue = null @@ -163,24 +192,30 @@ private class NormalizedStringStoredProperty(override val defaultValue: String?) } } - override fun equals(other: Any?) = this === other || (other is NormalizedStringStoredProperty && value == other.value) + override fun equals(other: Any?) = this === other || (other is ObjectStoredProperty<*> && value == other.value) override fun hashCode() = value?.hashCode() ?: 0 override fun toString() = if (value == defaultValue) "" else value ?: super.toString() override fun setValue(other: StoredProperty) { - value = (other as NormalizedStringStoredProperty).value + value = (other as StringStoredProperty).value } } -private class IntStoredProperty(override val defaultValue: Int) : StoredPropertyBase() { +private class IntStoredProperty(override val defaultValue: Int) : ReadWriteProperty, StoredProperty { override var value = defaultValue + override var name: String? = null - override operator fun getValue(thisRef: BaseState, property: KProperty<*>) = value + override operator fun getValue(thisRef: BaseState, property: KProperty<*>): Int { + name = property.name + return value + } @Suppress("UNCHECKED_CAST") override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") newValue: Int) { + name = property.name + if (value != newValue) { thisRef.modificationCount++ @@ -199,13 +234,19 @@ private class IntStoredProperty(override val defaultValue: Int) : StoredProperty } } -private class FloatStoredProperty(override val defaultValue: Float) : StoredPropertyBase() { +private class FloatStoredProperty(override val defaultValue: Float) : ReadWriteProperty, StoredProperty { override var value = defaultValue + override var name: String? = null - override operator fun getValue(thisRef: BaseState, property: KProperty<*>) = value + override operator fun getValue(thisRef: BaseState, property: KProperty<*>): Float { + name = property.name + return value + } @Suppress("UNCHECKED_CAST") override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") newValue: Float) { + name = property.name + if (value != newValue) { thisRef.modificationCount++ diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt b/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt deleted file mode 100644 index d12a95a54f18..000000000000 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredPropertyBase.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package com.intellij.openapi.components - -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty - -internal interface StoredProperty { - val defaultValue: Any? - val value: Any? - - var name: String? - - fun setValue(other: StoredProperty) -} - -// type must be exposed otherwise `provideDelegate` doesn't work -abstract class StoredPropertyBase : ReadWriteProperty, StoredProperty { - override final var name: String? = null - - operator fun provideDelegate(thisRef: Any, property: KProperty<*>): ReadWriteProperty { - name = property.name - return this - } -} \ No newline at end of file diff --git a/platform/projectModel-impl/projectModel-impl.iml b/platform/projectModel-impl/projectModel-impl.iml index c1e3cba9ac0f..30368b2eb8a0 100644 --- a/platform/projectModel-impl/projectModel-impl.iml +++ b/platform/projectModel-impl/projectModel-impl.iml @@ -1,18 +1,5 @@ - - - - - - - - - diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt b/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt index 1b9c196500a1..548313d0f907 100644 --- a/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt +++ b/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt @@ -31,8 +31,8 @@ import java.net.URL import java.util.concurrent.locks.ReentrantReadWriteLock import kotlin.concurrent.read import kotlin.concurrent.write -import kotlin.reflect.full.primaryConstructor import kotlin.reflect.jvm.isAccessible +import kotlin.reflect.primaryConstructor @JvmOverloads fun T.serialize(filter: SerializationFilter? = SkipDefaultsSerializationFilter()): Element {