181: Reimplement constant search in JPS
The API in Intellij have been changed after the PR was merged (see https://github.com/JetBrains/intellij-community/commit/8227d8e2dd4d98d2ff248a1b193ba31831ddef50) This commit implements new API. Also mocked Kotlin constant search is removed from JPS tests. Mocked Java search is in place, but now it is does not use hardcoded file and constant names. #KT-16091 fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
5ed66c3998
commit
39f7ecc9a3
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.jps.build.KotlinJavaBuilderExtension
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 org.jetbrains.jps.api.BasicFuture
|
||||
import org.jetbrains.jps.builders.java.JavaBuilderExtension
|
||||
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.withLookupStorage
|
||||
import java.io.File
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.Future
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class KotlinJavaBuilderExtension : JavaBuilderExtension() {
|
||||
override fun getConstantSearch(context: CompileContext): Callbacks.ConstantAffectionResolver {
|
||||
return KotlinLookupConstantSearch(context)
|
||||
}
|
||||
}
|
||||
|
||||
private class KotlinLookupConstantSearch(context: CompileContext) : Callbacks.ConstantAffectionResolver {
|
||||
private val pool = Executors.newSingleThreadExecutor()
|
||||
private val dataManager = context.projectDescriptor.dataManager
|
||||
|
||||
override fun request(
|
||||
ownerClassName: String,
|
||||
fieldName: String,
|
||||
accessFlags: Int,
|
||||
fieldRemoved: Boolean,
|
||||
accessChanged: Boolean
|
||||
): Future<Callbacks.ConstantAffection> {
|
||||
val future = object : BasicFuture<Callbacks.ConstantAffection>() {
|
||||
@Volatile
|
||||
private var result: Callbacks.ConstantAffection = Callbacks.ConstantAffection.EMPTY
|
||||
|
||||
fun result(files: Collection<File>) {
|
||||
result = Callbacks.ConstantAffection(files)
|
||||
setDone()
|
||||
}
|
||||
|
||||
override fun get(): Callbacks.ConstantAffection {
|
||||
super.get()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun get(timeout: Long, unit: TimeUnit): Callbacks.ConstantAffection {
|
||||
super.get(timeout, unit)
|
||||
return result
|
||||
}
|
||||
}
|
||||
pool.submit {
|
||||
if (!future.isCancelled) {
|
||||
dataManager.withLookupStorage { storage ->
|
||||
val paths = storage.get(LookupSymbol(name = fieldName, scope = ownerClassName))
|
||||
future.result(paths.map { File(it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
return future
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user