From 0d61566de628fbcf4a9432a98d15df2c10654737 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Sat, 30 Nov 2024 09:31:58 +0100 Subject: [PATCH] SONARKT-405 Upgrade Kotlin compiler to 2.1.0 --- gradle.properties | 2 +- gradle/verification-metadata.xml | 246 ++++++++++-------- sonar-kotlin-api/build.gradle.kts | 1 + .../org/sonarsource/kotlin/api/frontend/K1.kt | 23 +- .../kotlin/api/frontend/K1internals.java | 36 +++ .../api/frontend/KotlinLanguageVersionTest.kt | 6 +- .../linking/WorkaroundForJarMinimization.java | 1 + .../WorkaroundForJarMinimizationTest.kt | 2 +- 8 files changed, 187 insertions(+), 130 deletions(-) create mode 100644 sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1internals.java diff --git a/gradle.properties b/gradle.properties index 1fd81b5da..c1efbd4c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,5 +2,5 @@ group=org.sonarsource.kotlin version=2.21.1-SNAPSHOT description=Code Analyzer for Kotlin projectTitle=Kotlin -kotlinVersion=2.0.21 +kotlinVersion=2.1.0 org.gradle.jvmargs=-Xmx4096M diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 2ee32e075..b7a62446c 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -135,6 +135,11 @@ + + + + + @@ -180,6 +185,11 @@ + + + + + @@ -700,6 +710,11 @@ + + + + + @@ -805,34 +820,34 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -875,14 +890,14 @@ - - - + + + - - - + + + @@ -895,9 +910,9 @@ - - - + + + @@ -910,14 +925,14 @@ - - - + + + - - - + + + @@ -940,9 +955,9 @@ - - - + + + @@ -955,9 +970,9 @@ - - - + + + @@ -970,9 +985,9 @@ - - - + + + @@ -995,9 +1010,9 @@ - - - + + + @@ -1010,9 +1025,9 @@ - - - + + + @@ -1025,9 +1040,9 @@ - - - + + + @@ -1046,9 +1061,9 @@ - - - + + + @@ -1061,9 +1076,9 @@ - - - + + + @@ -1076,9 +1091,9 @@ - - - + + + @@ -1091,9 +1106,9 @@ - - - + + + @@ -1106,9 +1121,9 @@ - - - + + + @@ -1121,9 +1136,9 @@ - - - + + + @@ -1136,9 +1151,9 @@ - - - + + + @@ -1226,9 +1241,9 @@ - - - + + + @@ -1241,9 +1256,9 @@ - - - + + + @@ -1256,9 +1271,9 @@ - - - + + + @@ -1271,9 +1286,9 @@ - - - + + + @@ -1286,9 +1301,9 @@ - - - + + + @@ -1322,12 +1337,12 @@ - - - + + + - - + + @@ -1365,9 +1380,9 @@ - - - + + + @@ -1390,9 +1405,9 @@ - - - + + + @@ -1425,9 +1440,9 @@ - - - + + + @@ -1440,9 +1455,9 @@ - - - + + + @@ -1455,19 +1470,24 @@ - - - + + + + + + + + - - - + + + - - - + + + diff --git a/sonar-kotlin-api/build.gradle.kts b/sonar-kotlin-api/build.gradle.kts index 8830878b5..961b530ab 100644 --- a/sonar-kotlin-api/build.gradle.kts +++ b/sonar-kotlin-api/build.gradle.kts @@ -23,6 +23,7 @@ dependencies { isTransitive = false } } + implementation("com.github.ben-manes.caffeine:caffeine:2.9.3") compileOnly(libs.sonar.plugin.api) compileOnly(libs.slf4j.api) diff --git a/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1.kt b/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1.kt index e20daa070..f5055f2b4 100644 --- a/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1.kt +++ b/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1.kt @@ -22,12 +22,11 @@ import com.intellij.mock.MockProject import com.intellij.openapi.Disposable import com.intellij.psi.ClassTypePointerFactory import com.intellij.psi.impl.smartPointers.PsiClassReferenceTypePointerFactory -import org.jetbrains.kotlin.analysis.api.KaAnalysisNonPublicApi -import org.jetbrains.kotlin.analysis.api.descriptors.CliFe10AnalysisFacade +import org.jetbrains.kotlin.analysis.api.KaImplementationDetail +import org.jetbrains.kotlin.analysis.api.KaPlatformInterface import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade -import org.jetbrains.kotlin.analysis.api.descriptors.KaFe10AnalysisHandlerExtension -import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeTokenProvider -import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinLifetimeTokenProvider +import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeTokenFactory +import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinLifetimeTokenFactory import org.jetbrains.kotlin.analysis.api.platform.modification.KotlinGlobalModificationService import org.jetbrains.kotlin.analysis.api.platform.modification.KotlinModificationTrackerFactory import org.jetbrains.kotlin.analysis.api.platform.projectStructure.KotlinByModulesResolutionScopeProvider @@ -38,7 +37,6 @@ import org.jetbrains.kotlin.analysis.api.standalone.base.modification.KotlinStan import org.jetbrains.kotlin.analysis.api.standalone.base.projectStructure.AnalysisApiSimpleServiceRegistrar import org.jetbrains.kotlin.analysis.api.standalone.base.projectStructure.PluginStructureProvider import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.references.fe10.base.DummyKtFe10ReferenceResolutionHelper import org.jetbrains.kotlin.references.fe10.base.KtFe10ReferenceResolutionHelper import org.jetbrains.kotlin.resolve.extensions.AnalysisHandlerExtension @@ -49,6 +47,7 @@ import org.jetbrains.kotlin.resolve.extensions.AnalysisHandlerExtension */ annotation class K1only +@OptIn(KaPlatformInterface::class) internal fun configureK1AnalysisApiServices(env: KotlinCoreEnvironment) { val application = env.projectEnvironment.environment.application if (application.getServiceIfCreated(KtFe10ReferenceResolutionHelper::class.java) == null) { @@ -70,8 +69,8 @@ internal fun configureK1AnalysisApiServices(env: KotlinCoreEnvironment) { KotlinStandaloneGlobalModificationService::class.java, ) project.registerService( - KotlinLifetimeTokenProvider::class.java, - KotlinAlwaysAccessibleLifetimeTokenProvider::class.java, + KotlinLifetimeTokenFactory::class.java, + KotlinAlwaysAccessibleLifetimeTokenFactory::class.java, ) project.registerService( KotlinResolutionScopeProvider::class.java, @@ -87,7 +86,7 @@ internal fun configureK1AnalysisApiServices(env: KotlinCoreEnvironment) { ) } -@OptIn(KaAnalysisNonPublicApi::class) +@OptIn(KaImplementationDetail::class, KaPlatformInterface::class) private object AnalysisApiFe10ServiceRegistrar : AnalysisApiSimpleServiceRegistrar() { private const val PLUGIN_RELATIVE_PATH = "/META-INF/analysis-api/analysis-api-fe10.xml" @@ -95,7 +94,7 @@ private object AnalysisApiFe10ServiceRegistrar : AnalysisApiSimpleServiceRegistr PluginStructureProvider.registerApplicationServices(application, PLUGIN_RELATIVE_PATH) application.registerService( KtFe10ReferenceResolutionHelper::class.java, - DummyKtFe10ReferenceResolutionHelper, + K1internals.dummyKtFe10ReferenceResolutionHelper(), ) val applicationArea = application.extensionArea if (!applicationArea.hasExtensionPoint(ClassTypePointerFactory.EP_NAME)) { @@ -120,7 +119,7 @@ private object AnalysisApiFe10ServiceRegistrar : AnalysisApiSimpleServiceRegistr } override fun registerProjectModelServices(project: MockProject, disposable: Disposable) { - project.apply { registerService(Fe10AnalysisFacade::class.java, CliFe10AnalysisFacade()) } - AnalysisHandlerExtension.registerExtension(project, KaFe10AnalysisHandlerExtension()) + project.apply { registerService(Fe10AnalysisFacade::class.java, K1internals.createCliFe10AnalysisFacade()) } + AnalysisHandlerExtension.registerExtension(project, K1internals.createKaFe10AnalysisHandlerExtension()) } } diff --git a/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1internals.java b/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1internals.java new file mode 100644 index 000000000..ef9cb1cdb --- /dev/null +++ b/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/K1internals.java @@ -0,0 +1,36 @@ +/* + * SonarSource Kotlin + * Copyright (C) 2018-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonarsource.kotlin.api.frontend; + +@SuppressWarnings("KotlinInternalInJava") +final class K1internals { + private K1internals() { + } + + static org.jetbrains.kotlin.analysis.api.descriptors.CliFe10AnalysisFacade createCliFe10AnalysisFacade() { + return new org.jetbrains.kotlin.analysis.api.descriptors.CliFe10AnalysisFacade(); + } + + static org.jetbrains.kotlin.analysis.api.descriptors.KaFe10AnalysisHandlerExtension createKaFe10AnalysisHandlerExtension() { + return new org.jetbrains.kotlin.analysis.api.descriptors.KaFe10AnalysisHandlerExtension(); + } + + static org.jetbrains.kotlin.references.fe10.base.DummyKtFe10ReferenceResolutionHelper dummyKtFe10ReferenceResolutionHelper() { + return org.jetbrains.kotlin.references.fe10.base.DummyKtFe10ReferenceResolutionHelper.INSTANCE; + } + +} diff --git a/sonar-kotlin-api/src/test/java/org/sonarsource/kotlin/api/frontend/KotlinLanguageVersionTest.kt b/sonar-kotlin-api/src/test/java/org/sonarsource/kotlin/api/frontend/KotlinLanguageVersionTest.kt index 8bdd8dd4f..3345d3af3 100644 --- a/sonar-kotlin-api/src/test/java/org/sonarsource/kotlin/api/frontend/KotlinLanguageVersionTest.kt +++ b/sonar-kotlin-api/src/test/java/org/sonarsource/kotlin/api/frontend/KotlinLanguageVersionTest.kt @@ -27,17 +27,17 @@ class KotlinLanguageVersionTest { @Test fun first_supported() { - assertThat(LanguageVersion.FIRST_SUPPORTED).isEqualTo(LanguageVersion.KOTLIN_1_4) + assertThat(LanguageVersion.FIRST_SUPPORTED).isEqualTo(LanguageVersion.KOTLIN_1_6) } @Test fun first_non_deprecated() { - assertThat(LanguageVersion.FIRST_NON_DEPRECATED).isEqualTo(LanguageVersion.KOTLIN_1_7) + assertThat(LanguageVersion.FIRST_NON_DEPRECATED).isEqualTo(LanguageVersion.KOTLIN_1_8) } @Test fun latest_stable() { - assertThat(LanguageVersion.LATEST_STABLE).isEqualTo(LanguageVersion.KOTLIN_2_0) + assertThat(LanguageVersion.LATEST_STABLE).isEqualTo(LanguageVersion.KOTLIN_2_1) } } diff --git a/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimization.java b/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimization.java index ed9bfb37f..8e94a3f86 100644 --- a/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimization.java +++ b/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimization.java @@ -44,6 +44,7 @@ public class WorkaroundForJarMinimization { org.jetbrains.kotlin.analysis.api.impl.base.lifetime.KaBaseLifetimeTracker.class, // META-INF/analysis-api/analysis-api-fe10.xml org.jetbrains.kotlin.analysis.api.descriptors.KaFe10SessionProvider.class, + org.jetbrains.kotlin.analysis.api.descriptors.modification.KaFe10SourceModificationService.class, org.jetbrains.kotlin.references.fe10.base.KtFe10KotlinReferenceProviderContributor.class, org.jetbrains.kotlin.analysis.api.descriptors.references.ReadWriteAccessCheckerDescriptorsImpl.class, diff --git a/sonar-kotlin-plugin/src/test/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimizationTest.kt b/sonar-kotlin-plugin/src/test/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimizationTest.kt index 95b77e262..bbc83ec45 100644 --- a/sonar-kotlin-plugin/src/test/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimizationTest.kt +++ b/sonar-kotlin-plugin/src/test/java/org/sonarsource/kotlin/plugin/linking/WorkaroundForJarMinimizationTest.kt @@ -22,6 +22,6 @@ import org.junit.jupiter.api.Test internal class WorkaroundForJarMinimizationTest { @Test fun minimizing_class_count() { - assertThat(WorkaroundForJarMinimization.CLASSES_TO_KEEP_WHEN_MINIMIZING_JAR).hasSize(16) + assertThat(WorkaroundForJarMinimization.CLASSES_TO_KEEP_WHEN_MINIMIZING_JAR).hasSize(17) } }