Gradle: Use copyable user data to retain intermediate model
#KT-21418 Fixed
This commit is contained in:
+8
-8
@@ -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<ModuleData>.isResolved
|
||||
by NotNullableUserDataProperty(Key.create<Boolean>("IS_RESOLVED"), false)
|
||||
by NotNullableCopyableDataNodeUserDataProperty(Key.create<Boolean>("IS_RESOLVED"), false)
|
||||
var DataNode<ModuleData>.hasKotlinPlugin
|
||||
by NotNullableUserDataProperty(Key.create<Boolean>("HAS_KOTLIN_PLUGIN"), false)
|
||||
by NotNullableCopyableDataNodeUserDataProperty(Key.create<Boolean>("HAS_KOTLIN_PLUGIN"), false)
|
||||
var DataNode<ModuleData>.compilerArgumentsBySourceSet
|
||||
by UserDataProperty(Key.create<CompilerArgumentsBySourceSet>("CURRENT_COMPILER_ARGUMENTS"))
|
||||
by CopyableDataNodeUserDataProperty(Key.create<CompilerArgumentsBySourceSet>("CURRENT_COMPILER_ARGUMENTS"))
|
||||
var DataNode<ModuleData>.coroutines
|
||||
by UserDataProperty(Key.create<String>("KOTLIN_COROUTINES"))
|
||||
by CopyableDataNodeUserDataProperty(Key.create<String>("KOTLIN_COROUTINES"))
|
||||
var DataNode<ModuleData>.platformPluginId
|
||||
by UserDataProperty(Key.create<String>("PLATFORM_PLUGIN_ID"))
|
||||
by CopyableDataNodeUserDataProperty(Key.create<String>("PLATFORM_PLUGIN_ID"))
|
||||
var DataNode<out ModuleData>.implementedModuleName
|
||||
by UserDataProperty(Key.create<String>("IMPLEMENTED_MODULE_NAME"))
|
||||
by CopyableDataNodeUserDataProperty(Key.create<String>("IMPLEMENTED_MODULE_NAME"))
|
||||
|
||||
class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() {
|
||||
override fun getToolingExtensionsClasses(): Set<Class<out Any>> {
|
||||
|
||||
@@ -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<in R : DataNode<*>, T : Any>(val key: Key<T>) {
|
||||
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<in R : DataNode<*>, T : Any>(val key: Key<T>, 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user