From d6d6cef10dec57aafb909e6dba763ca599a930ec Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 28 Nov 2017 12:08:14 +0300 Subject: [PATCH] Gradle: Use copyable user data to retain intermediate model #KT-21418 Fixed --- .../KotlinGradleProjectResolverExtension.kt | 16 ++++----- .../kotlin/idea/util/userDataUtil.kt | 35 +++++++++++++++++++ ...droidExtensionsProjectResolverExtension.kt | 12 +++---- 3 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/util/userDataUtil.kt diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt index a96dd1facc3..9e7790aeda5 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt @@ -30,8 +30,8 @@ import org.jetbrains.kotlin.gradle.CompilerArgumentsBySourceSet import org.jetbrains.kotlin.gradle.KotlinGradleModel import org.jetbrains.kotlin.gradle.KotlinGradleModelBuilder import org.jetbrains.kotlin.idea.inspections.gradle.getDependencyModules -import org.jetbrains.kotlin.psi.NotNullableUserDataProperty -import org.jetbrains.kotlin.psi.UserDataProperty +import org.jetbrains.kotlin.idea.util.CopyableDataNodeUserDataProperty +import org.jetbrains.kotlin.idea.util.NotNullableCopyableDataNodeUserDataProperty import org.jetbrains.plugins.gradle.model.ExternalProjectDependency import org.jetbrains.plugins.gradle.model.FileCollectionDependency import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData @@ -40,17 +40,17 @@ import org.jetbrains.plugins.gradle.service.project.GradleProjectResolver import java.util.* var DataNode.isResolved - by NotNullableUserDataProperty(Key.create("IS_RESOLVED"), false) + by NotNullableCopyableDataNodeUserDataProperty(Key.create("IS_RESOLVED"), false) var DataNode.hasKotlinPlugin - by NotNullableUserDataProperty(Key.create("HAS_KOTLIN_PLUGIN"), false) + by NotNullableCopyableDataNodeUserDataProperty(Key.create("HAS_KOTLIN_PLUGIN"), false) var DataNode.compilerArgumentsBySourceSet - by UserDataProperty(Key.create("CURRENT_COMPILER_ARGUMENTS")) + by CopyableDataNodeUserDataProperty(Key.create("CURRENT_COMPILER_ARGUMENTS")) var DataNode.coroutines - by UserDataProperty(Key.create("KOTLIN_COROUTINES")) + by CopyableDataNodeUserDataProperty(Key.create("KOTLIN_COROUTINES")) var DataNode.platformPluginId - by UserDataProperty(Key.create("PLATFORM_PLUGIN_ID")) + by CopyableDataNodeUserDataProperty(Key.create("PLATFORM_PLUGIN_ID")) var DataNode.implementedModuleName - by UserDataProperty(Key.create("IMPLEMENTED_MODULE_NAME")) + by CopyableDataNodeUserDataProperty(Key.create("IMPLEMENTED_MODULE_NAME")) class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() { override fun getToolingExtensionsClasses(): Set> { diff --git a/idea/src/org/jetbrains/kotlin/idea/util/userDataUtil.kt b/idea/src/org/jetbrains/kotlin/idea/util/userDataUtil.kt new file mode 100644 index 00000000000..8fccbbd840a --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/util/userDataUtil.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-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 org.jetbrains.kotlin.idea.util + +import com.intellij.openapi.externalSystem.model.DataNode +import com.intellij.openapi.util.Key +import kotlin.reflect.KProperty + +class CopyableDataNodeUserDataProperty, T : Any>(val key: Key) { + operator fun getValue(thisRef: R, property: KProperty<*>) = thisRef.getCopyableUserData(key) + + operator fun setValue(thisRef: R, property: KProperty<*>, value: T?) = thisRef.putCopyableUserData(key, value) +} + +class NotNullableCopyableDataNodeUserDataProperty, T : Any>(val key: Key, val defaultValue: T) { + operator fun getValue(thisRef: R, property: KProperty<*>) = thisRef.getCopyableUserData(key) ?: defaultValue + + operator fun setValue(thisRef: R, property: KProperty<*>, value: T) { + thisRef.putCopyableUserData(key, if (value != defaultValue) value else null) + } +} \ No newline at end of file diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidExtensionsProjectResolverExtension.kt b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidExtensionsProjectResolverExtension.kt index 4c68b3b3311..4b6a9a9fb34 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidExtensionsProjectResolverExtension.kt +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidExtensionsProjectResolverExtension.kt @@ -25,12 +25,12 @@ import org.gradle.api.Project import org.gradle.tooling.model.idea.IdeaModule import org.jetbrains.kotlin.android.synthetic.AndroidCommandLineProcessor.Companion.ANDROID_COMPILER_PLUGIN_ID import org.jetbrains.kotlin.android.synthetic.AndroidCommandLineProcessor.Companion.DEFAULT_CACHE_IMPL_OPTION -import org.jetbrains.kotlin.android.synthetic.AndroidCommandLineProcessor.Companion.EXPERIMENTAL_OPTION import org.jetbrains.kotlin.android.synthetic.AndroidCommandLineProcessor.Companion.ENABLED_OPTION +import org.jetbrains.kotlin.android.synthetic.AndroidCommandLineProcessor.Companion.EXPERIMENTAL_OPTION import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.idea.configuration.GradleProjectImportHandler import org.jetbrains.kotlin.idea.facet.KotlinFacet -import org.jetbrains.kotlin.psi.NotNullableUserDataProperty +import org.jetbrains.kotlin.idea.util.NotNullableCopyableDataNodeUserDataProperty import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder @@ -39,16 +39,16 @@ import java.io.Serializable import java.lang.Exception var DataNode.hasAndroidExtensionsPlugin: Boolean - by NotNullableUserDataProperty(Key.create("HAS_ANDROID_EXTENSIONS_PLUGIN"), false) + by NotNullableCopyableDataNodeUserDataProperty(Key.create("HAS_ANDROID_EXTENSIONS_PLUGIN"), false) var DataNode.isExperimental: Boolean - by NotNullableUserDataProperty(Key.create("ANDROID_EXTENSIONS_IS_EXPERIMENTAL"), false) + by NotNullableCopyableDataNodeUserDataProperty(Key.create("ANDROID_EXTENSIONS_IS_EXPERIMENTAL"), false) private const val DEFAULT_CACHE_IMPLEMENTATION_DEFAULT_VALUE = "hashMap" var DataNode.defaultCacheImplementation: String - by NotNullableUserDataProperty(Key.create("ANDROID_EXTENSIONS_DEFAULT_CACHE_IMPL"), - DEFAULT_CACHE_IMPLEMENTATION_DEFAULT_VALUE) + by NotNullableCopyableDataNodeUserDataProperty(Key.create("ANDROID_EXTENSIONS_DEFAULT_CACHE_IMPL"), + DEFAULT_CACHE_IMPLEMENTATION_DEFAULT_VALUE) interface AndroidExtensionsGradleModel : Serializable { val hasAndroidExtensionsPlugin: Boolean