From 1a7737494b5cfbf9fccd94ae266abd3f905df044 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 21 Feb 2018 00:55:34 +0300 Subject: [PATCH] Provide custom ConstantAffectionResolver in JPS #KT-16091 fixed Original commit: 772a935de6efd17576fe7b9aac8a8296b44d90d9 --- jps/jps-plugin/build.gradle.kts | 1 + .../build.gradle.kts | 21 +++++++++++ .../builders/java/ConstantSearchProvider.java | 23 ++++++++++++ ...s.jps.builders.java.ConstantSearchProvider | 1 + .../jps/build/KotlinConstantSearchProvider.kt | 37 +++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 jps/jps-plugin/jps-services-declarations/build.gradle.kts create mode 100644 jps/jps-plugin/jps-services-declarations/src/org/jetbrains/jps/builders/java/ConstantSearchProvider.java create mode 100644 jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.builders.java.ConstantSearchProvider create mode 100644 jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinConstantSearchProvider.kt diff --git a/jps/jps-plugin/build.gradle.kts b/jps/jps-plugin/build.gradle.kts index a68f3175d16..e472eb53902 100644 --- a/jps/jps-plugin/build.gradle.kts +++ b/jps/jps-plugin/build.gradle.kts @@ -3,6 +3,7 @@ apply { plugin("kotlin") } val compilerModules: Array by rootProject.extra dependencies { + compileOnly(project(":jps-plugin:jps-services-declarations")) compile(project(":kotlin-build-common")) compile(project(":core:descriptors")) compile(project(":core:descriptors.jvm")) diff --git a/jps/jps-plugin/jps-services-declarations/build.gradle.kts b/jps/jps-plugin/jps-services-declarations/build.gradle.kts new file mode 100644 index 00000000000..fc51a1b40bc --- /dev/null +++ b/jps/jps-plugin/jps-services-declarations/build.gradle.kts @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +/** + * A hacky module to provide Intellij services declarations, + * so Kotlin plugin can be compiled even when service API + * is not present in all Intellij builds we support. + */ + +plugins { java } + +dependencies { + compileOnly(intellijDep()) { includeJars("annotations", "util") } + compileOnly(intellijDep("jps-standalone")) { includeJars("jps-builders") } +} + +sourceSets { + "main" { projectDefault() } +} diff --git a/jps/jps-plugin/jps-services-declarations/src/org/jetbrains/jps/builders/java/ConstantSearchProvider.java b/jps/jps-plugin/jps-services-declarations/src/org/jetbrains/jps/builders/java/ConstantSearchProvider.java new file mode 100644 index 00000000000..f09105ad5cd --- /dev/null +++ b/jps/jps-plugin/jps-services-declarations/src/org/jetbrains/jps/builders/java/ConstantSearchProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.jps.builders.java; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.builders.java.dependencyView.Callbacks; +import org.jetbrains.jps.incremental.CompileContext; + +/** + * A "copy" of Intellij service unavailable in current builds, + * so our plugin can be compiled against it (API is not yet merged in Intellij, + * even then it would be available only in 182.* builds). + * + * // todo: remove when compatibility layers will be finished + */ +@SuppressWarnings("unused") +public interface ConstantSearchProvider { + @NotNull + Callbacks.ConstantAffectionResolver getConstantSearch(@NotNull CompileContext context); +} diff --git a/jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.builders.java.ConstantSearchProvider b/jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.builders.java.ConstantSearchProvider new file mode 100644 index 00000000000..2c3c50a7060 --- /dev/null +++ b/jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.builders.java.ConstantSearchProvider @@ -0,0 +1 @@ +org.jetbrains.kotlin.jps.build.KotlinConstantSearchProvider \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinConstantSearchProvider.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinConstantSearchProvider.kt new file mode 100644 index 00000000000..beff6961bf5 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinConstantSearchProvider.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.jps.build + +import com.intellij.util.concurrency.FixedFuture +import org.jetbrains.jps.builders.java.ConstantSearchProvider +import org.jetbrains.jps.builders.java.dependencyView.Callbacks +import org.jetbrains.jps.incremental.CompileContext +import org.jetbrains.kotlin.incremental.LookupSymbol +import org.jetbrains.kotlin.jps.incremental.JpsLookupStorageProvider +import org.jetbrains.kotlin.jps.incremental.KotlinDataContainerTarget +import java.io.File +import java.util.concurrent.Future + +class KotlinConstantSearchProvider : ConstantSearchProvider { + override fun getConstantSearch(context: CompileContext): Callbacks.ConstantAffectionResolver = + KotlinLookupConstantSearch(context) +} + +class KotlinLookupConstantSearch(context: CompileContext) : Callbacks.ConstantAffectionResolver { + private val dataManager = context.projectDescriptor.dataManager + + override fun request( + ownerClassName: String, + fieldName: String, + accessFlags: Int, + fieldRemoved: Boolean, + accessChanged: Boolean + ): Future { + val storage = dataManager.getStorage(KotlinDataContainerTarget, JpsLookupStorageProvider) + val paths = storage.get(LookupSymbol(name = fieldName, scope = ownerClassName)) + return FixedFuture(Callbacks.ConstantAffection(paths.map(::File))) + } +} \ No newline at end of file