Provide custom ConstantAffectionResolver in JPS

#KT-16091 fixed

Original commit: 772a935de6
This commit is contained in:
Alexey Tsvetkov
2018-02-21 00:55:34 +03:00
parent 2247e501b4
commit 1a7737494b
5 changed files with 83 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@ apply { plugin("kotlin") }
val compilerModules: Array<String> 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"))
@@ -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() }
}
@@ -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);
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.jps.build.KotlinConstantSearchProvider
@@ -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<Callbacks.ConstantAffection> {
val storage = dataManager.getStorage(KotlinDataContainerTarget, JpsLookupStorageProvider)
val paths = storage.get(LookupSymbol(name = fieldName, scope = ownerClassName))
return FixedFuture(Callbacks.ConstantAffection(paths.map(::File)))
}
}