Skip to content

Commit

Permalink
SONARKT-405 Upgrade Kotlin compiler to 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Nov 30, 2024
1 parent f44acf4 commit 0d61566
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 130 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
246 changes: 133 additions & 113 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sonar-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -87,15 +86,15 @@ 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"

override fun registerApplicationServices(application: MockApplication) {
PluginStructureProvider.registerApplicationServices(application, PLUGIN_RELATIVE_PATH)
application.registerService(
KtFe10ReferenceResolutionHelper::class.java,
DummyKtFe10ReferenceResolutionHelper,
K1internals.dummyKtFe10ReferenceResolutionHelper(),
)
val applicationArea = application.extensionArea
if (!applicationArea.hasExtensionPoint(ClassTypePointerFactory.EP_NAME)) {
Expand All @@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 0d61566

Please sign in to comment.