diff --git a/build.gradle.kts b/build.gradle.kts index 68bff8e640a..b51c85396ad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -258,6 +258,7 @@ extra["compilerModules"] = arrayOf( ":compiler:fir:psi2fir", ":compiler:fir:lightTree", ":compiler:fir:fir2ir", + ":compiler:fir:fir2ir:jvm-backend", ":compiler:fir:java", ":compiler:fir:jvm", ":compiler:fir:checkers", diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmBackendClassResolver.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmBackendClassResolver.kt index 5a710a943cc..504a80e2d95 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmBackendClassResolver.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmBackendClassResolver.kt @@ -40,13 +40,18 @@ class JvmBackendClassResolverForModuleWithDependencies( override fun resolveToClassDescriptors(type: Type): List { if (type.sort != Type.OBJECT) return emptyList() - val className = type.className - val lastDotIndex = className.lastIndexOf('.') - val packageFQN = if (lastDotIndex >= 0) FqName(className.substring(0, lastDotIndex)) else FqName.ROOT - val classRelativeNameWithDollars = if (lastDotIndex >= 0) className.substring(lastDotIndex + 1) else className - val classFQN = FqName(classRelativeNameWithDollars.replace('$', '.')) - val platformClass = moduleDescriptor.findClassAcrossModuleDependencies(ClassId(packageFQN, classFQN, false)) ?: return emptyList() + val platformClass = moduleDescriptor.findClassAcrossModuleDependencies(type.classId) ?: return emptyList() return JavaToKotlinClassMap.mapPlatformClass(platformClass) + platformClass } } + +val Type.classId: ClassId + get() { + val className = this.className + val lastDotIndex = className.lastIndexOf('.') + val packageFQN = if (lastDotIndex >= 0) FqName(className.substring(0, lastDotIndex)) else FqName.ROOT + val classRelativeNameWithDollars = if (lastDotIndex >= 0) className.substring(lastDotIndex + 1) else className + val classFQN = FqName(classRelativeNameWithDollars.replace('$', '.')) + return ClassId(packageFQN, classFQN, false) + } \ No newline at end of file diff --git a/compiler/fir/fir2ir/jvm-backend/build.gradle.kts b/compiler/fir/fir2ir/jvm-backend/build.gradle.kts new file mode 100644 index 00000000000..963d216ffd8 --- /dev/null +++ b/compiler/fir/fir2ir/jvm-backend/build.gradle.kts @@ -0,0 +1,28 @@ +/* + * 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. + */ + +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + compileOnly(project(":core:descriptors")) + compileOnly(project(":compiler:fir:cones")) + compileOnly(project(":compiler:fir:resolve")) + compileOnly(project(":compiler:fir:tree")) + compileOnly(project(":compiler:fir:fir2ir")) + compileOnly(project(":compiler:ir.tree")) + compileOnly(project(":compiler:ir.psi2ir")) + compileOnly(project(":compiler:ir.backend.common")) + compileOnly(project(":compiler:backend")) + + compileOnly(intellijCoreDep()) { includeJars("intellij-core", "asm-all", rootProject = rootProject) } + +} + +sourceSets { + "main" { projectDefault() } +} diff --git a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmBackendClassResolver.kt b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmBackendClassResolver.kt new file mode 100644 index 00000000000..9130ee5187d --- /dev/null +++ b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmBackendClassResolver.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2020 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.fir.backend.jvm + +import org.jetbrains.kotlin.codegen.JvmBackendClassResolver +import org.jetbrains.kotlin.codegen.classId +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.fir.backend.Fir2IrComponents +import org.jetbrains.kotlin.fir.resolve.firSymbolProvider +import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol +import org.jetbrains.org.objectweb.asm.Type + +class FirJvmBackendClassResolver(val components: Fir2IrComponents) : JvmBackendClassResolver { + override fun resolveToClassDescriptors(type: Type): List { + if (type.sort != Type.OBJECT) return emptyList() + + val symbol = components.session.firSymbolProvider.getClassLikeSymbolByFqName(type.classId) ?: return emptyList() + require(symbol is FirClassSymbol<*>) + return listOf(components.classifierStorage.getIrClassSymbol(symbol).descriptor) + } + +} \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index 9b29af78099..614bda628c6 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -204,7 +204,7 @@ class Fir2IrConverter( } externalDependenciesGenerator.generateUnboundSymbolsAsDependencies() - return Fir2IrResult(irModuleFragment, symbolTable, sourceManager) + return Fir2IrResult(irModuleFragment, symbolTable, sourceManager, components) } } } \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt index 6f1ba565835..c3be8c9e0fe 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt @@ -9,4 +9,4 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi2ir.PsiSourceManager -data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val sourceManager: PsiSourceManager) \ No newline at end of file +data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val sourceManager: PsiSourceManager, val components: Fir2IrComponents) \ No newline at end of file diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index b5bacb6992f..a77262a5b35 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -15,6 +15,8 @@ dependencies { testCompile(project(":compiler:fir:psi2fir")) testCompile(project(":compiler:fir:lightTree")) testCompile(project(":compiler:fir:fir2ir")) + testCompile(project(":compiler:fir:jvm")) + testCompile(project(":compiler:fir:fir2ir:jvm-backend")) testCompile(project(":compiler:fir:cones")) testCompile(project(":compiler:fir:resolve")) testCompile(project(":compiler:fir:checkers")) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt index 37cfb28c17e..51c9cf0a518 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt @@ -39,6 +39,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.JVMConfigurationKeys import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.fir.backend.Fir2IrConverter +import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendClassResolver import org.jetbrains.kotlin.fir.builder.RawFirBuilder import org.jetbrains.kotlin.fir.createSession import org.jetbrains.kotlin.fir.resolve.firProvider @@ -131,7 +132,7 @@ object GenerationUtils { throw e } } - val (moduleFragment, symbolTable, sourceManager) = + val (moduleFragment, symbolTable, sourceManager, components) = Fir2IrConverter.createModuleFragment(session, firFiles, configuration.languageVersionSettings, signaturer = IdSignatureDescriptor( JvmManglerDesc())) val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext @@ -143,6 +144,8 @@ object GenerationUtils { codegenFactory ).isIrBackend( true + ).jvmBackendClassResolver( + FirJvmBackendClassResolver(components) ).build() generationState.beforeCompile() diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index ee0ffa47a85..69a6eaabbf0 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -51,6 +51,7 @@ val projectsToShadow by extra(listOf( ":compiler:fir:jvm", ":compiler:fir:psi2fir", ":compiler:fir:fir2ir", + ":compiler:fir:fir2ir:jvm-backend", ":compiler:frontend", ":compiler:frontend.common", ":compiler:frontend.java", diff --git a/settings.gradle b/settings.gradle index 979a2c7965f..a77804552a4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -83,6 +83,7 @@ include ":kotlin-build-common", ":compiler:fir:psi2fir", ":compiler:fir:lightTree", ":compiler:fir:fir2ir", + ":compiler:fir:fir2ir:jvm-backend", ":compiler:fir:resolve", ":compiler:fir:java", ":compiler:fir:modularized-tests",