From 59abe71f56dd424d5d4ff8999bf4459dac85ae7a Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Thu, 23 Dec 2021 17:38:48 +0100 Subject: [PATCH] Drop all usages of Callbacks.ConstantAffectionResolver This commit fixes deprecation API usage (deprecated in intellij) which is actually an error (because of -Werror) KotlinJavaBuilderExtension implements only one method (getConstantSearch) which is deprecated and the method is actually not called in since 202 IDEA (minimum supported IDEA right now is 203). KotlinJavaBuilderExtension originally appeared in 39f7ecc9a3b885c200e2e65f8de687d09fa78b87 in order to fix KT-16091. The fact that we ignored the depreaction caused the issue regression. Luckily, we already fixes the issue again but this API usage is useless so can be safely droped --- .../jps/build/AbstractIncrementalJpsTest.kt | 6 -- .../jps/build/MockJavaConstantSearch.kt | 49 -------------- ...ins.jps.builders.java.JavaBuilderExtension | 1 - .../jps/build/KotlinJavaBuilderExtension.kt | 64 ------------------- 4 files changed, 120 deletions(-) delete mode 100644 jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MockJavaConstantSearch.kt delete mode 100644 jps/jps-plugin/resources/META-INF/services/org.jetbrains.jps.builders.java.JavaBuilderExtension delete mode 100644 jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinJavaBuilderExtension.kt diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index 759a33d7560..ee8f831d880 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -168,12 +168,6 @@ abstract class AbstractIncrementalJpsTest( } } - // JPS forces rebuild of all files when JVM constant has been changed and Callbacks.ConstantAffectionResolver - // is not provided, so ConstantAffectionResolver is mocked with empty implementation - // Usages in Kotlin files are expected to be found by KotlinLookupConstantSearch - protected open val mockConstantSearch: Callbacks.ConstantAffectionResolver? - get() = MockJavaConstantSearch(workDir) - private fun build( name: String?, scope: CompileScopeTestBuilder = CompileScopeTestBuilder.make().allModules() diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MockJavaConstantSearch.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MockJavaConstantSearch.kt deleted file mode 100644 index 30fdc3f733f..00000000000 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MockJavaConstantSearch.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. - * 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.dependencyView.Callbacks -import org.jetbrains.kotlin.incremental.isJavaFile -import java.io.File -import java.util.concurrent.Future - -/** - * Mocks Intellij Java constant search. - * When JPS is run from Intellij, it sends find usages request to IDE (it only searches for references inside Java files). - * - * We rely on heuristics instead of precise usages search. - * A Java file is considered affected if: - * 1. It contains changed field name as a content substring. - * 2. Its simple file name is not equal to a field's owner class simple name (to avoid recompiling field's declaration again) - */ -class MockJavaConstantSearch(private val workDir: File) : - Callbacks.ConstantAffectionResolver { - override fun request( - ownerClassName: String, - fieldName: String, - accessFlags: Int, - fieldRemoved: Boolean, - accessChanged: Boolean - ): Future { - fun File.isAffected(): Boolean { - if (!isJavaFile()) return false - - if (nameWithoutExtension == ownerClassName.substringAfterLast(".")) return false - - val code = readText() - return code.contains(fieldName) - } - - - val affectedJavaFiles = workDir.walk().filter(File::isAffected).toList() - return FixedFuture( - Callbacks.ConstantAffection( - affectedJavaFiles - ) - ) - } -} \ No newline at end of file diff --git a/jps/jps-plugin/resources/META-INF/services/org.jetbrains.jps.builders.java.JavaBuilderExtension b/jps/jps-plugin/resources/META-INF/services/org.jetbrains.jps.builders.java.JavaBuilderExtension deleted file mode 100644 index 206b2c9a36d..00000000000 --- a/jps/jps-plugin/resources/META-INF/services/org.jetbrains.jps.builders.java.JavaBuilderExtension +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.jps.build.KotlinJavaBuilderExtension \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinJavaBuilderExtension.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinJavaBuilderExtension.kt deleted file mode 100644 index d5ca80f4205..00000000000 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinJavaBuilderExtension.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. - * 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 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 kotlinContext by lazy { context.kotlin } - - override fun request( - ownerClassName: String, - fieldName: String, - accessFlags: Int, - fieldRemoved: Boolean, - accessChanged: Boolean - ): Future { - val future = object : BasicFuture() { - @Volatile - private var result: Callbacks.ConstantAffection = Callbacks.ConstantAffection.EMPTY - - fun result(files: Collection) { - 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) { - kotlinContext.lookupStorageManager.withLookupStorage { storage -> - val paths = storage.get(LookupSymbol(name = fieldName, scope = ownerClassName)) - future.result(paths.map { File(it) }) - } - } - } - return future - } -} \ No newline at end of file