[FIR] Generate IR for generated FIR declarations
This commit is contained in:
committed by
TeamCityServer
parent
e3579389ee
commit
233b9f1242
@@ -13,7 +13,9 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.backend.generators.FakeOverrideGenerator
|
||||
import org.jetbrains.kotlin.fir.builder.buildPackageDirective
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildFile
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJava
|
||||
@@ -21,6 +23,8 @@ import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||
import org.jetbrains.kotlin.fir.extensions.declarationGenerators
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
@@ -569,3 +573,28 @@ fun FirRegularClass.getIrSymbolsForSealedSubclasses(components: Fir2IrComponents
|
||||
symbolProvider.getClassLikeSymbolByClassId(it)?.toSymbol(session, components.classifierStorage)
|
||||
}.filterIsInstance<IrClassSymbol>()
|
||||
}
|
||||
|
||||
fun FirSession.createFilesWithGeneratedDeclarations(): List<FirFile> {
|
||||
val symbolProvider = symbolProvider
|
||||
val declarationGenerators = extensionService.declarationGenerators
|
||||
val topLevelClasses = declarationGenerators.flatMap { it.getTopLevelClassIds() }.groupBy { it.packageFqName }
|
||||
val topLevelCallables = declarationGenerators.flatMap { it.getTopLevelCallableIds() }.groupBy { it.packageName }
|
||||
|
||||
return buildList {
|
||||
for (packageFqName in (topLevelClasses.keys + topLevelCallables.keys)) {
|
||||
this += buildFile {
|
||||
origin = FirDeclarationOrigin.Synthetic
|
||||
moduleData = this@createFilesWithGeneratedDeclarations.moduleData
|
||||
packageDirective = buildPackageDirective {
|
||||
this.packageFqName = packageFqName
|
||||
}
|
||||
name = "__GENERATED DECLARATIONS__.kt"
|
||||
declarations += topLevelCallables.getOrDefault(packageFqName, emptyList())
|
||||
.flatMap { symbolProvider.getTopLevelCallableSymbols(packageFqName, it.callableName) }
|
||||
.map { it.fir }
|
||||
declarations += topLevelClasses.getOrDefault(packageFqName, emptyList())
|
||||
.mapNotNull { symbolProvider.getClassLikeSymbolByClassId(it)?.fir }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,16 @@ import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isSynthetic
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.primaryConstructor
|
||||
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
||||
import org.jetbrains.kotlin.fir.extensions.declarationGenerators
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedMembers
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedNestedClassifiers
|
||||
import org.jetbrains.kotlin.fir.packageFqName
|
||||
import org.jetbrains.kotlin.fir.psi
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.signaturer.FirBasedSignatureComposer
|
||||
import org.jetbrains.kotlin.fir.signaturer.FirMangler
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.PsiIrFileEntry
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
@@ -40,6 +43,8 @@ class Fir2IrConverter(
|
||||
private val components: Fir2IrComponents
|
||||
) : Fir2IrComponents by components {
|
||||
|
||||
private val generatorExtensions = session.extensionService.declarationGenerators
|
||||
|
||||
fun processLocalClassAndNestedClasses(regularClass: FirRegularClass, parent: IrDeclarationParent) {
|
||||
val irClass = registerClassAndNestedClasses(regularClass, parent)
|
||||
processClassAndNestedClassHeaders(regularClass)
|
||||
@@ -57,8 +62,30 @@ class Fir2IrConverter(
|
||||
}
|
||||
|
||||
fun registerFileAndClasses(file: FirFile, moduleFragment: IrModuleFragment) {
|
||||
val fileEntry = when (file.origin) {
|
||||
FirDeclarationOrigin.Source -> PsiIrFileEntry(file.psi as KtFile)
|
||||
FirDeclarationOrigin.Synthetic -> object : IrFileEntry {
|
||||
override val name = file.name
|
||||
override val maxOffset = UNDEFINED_OFFSET
|
||||
|
||||
override fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo =
|
||||
SourceRangeInfo(
|
||||
"",
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET
|
||||
)
|
||||
|
||||
override fun getLineNumber(offset: Int) = UNDEFINED_OFFSET
|
||||
override fun getColumnNumber(offset: Int) = UNDEFINED_OFFSET
|
||||
}
|
||||
else -> error("Unsupported file origin: ${file.origin}")
|
||||
}
|
||||
val irFile = IrFileImpl(
|
||||
PsiIrFileEntry(file.psi as KtFile),
|
||||
fileEntry,
|
||||
moduleDescriptor.getPackage(file.packageFqName).fragments.first(),
|
||||
moduleFragment
|
||||
)
|
||||
@@ -130,14 +157,20 @@ class Fir2IrConverter(
|
||||
regularClass: FirRegularClass,
|
||||
irClass: IrClass = classifierStorage.getCachedIrClass(regularClass)!!
|
||||
): IrClass {
|
||||
val irConstructor = regularClass.primaryConstructor?.let {
|
||||
declarationStorage.getOrCreateIrConstructor(it, irClass, isLocal = regularClass.isLocal)
|
||||
val allDeclarations = mutableListOf<FirDeclaration>().apply {
|
||||
addAll(regularClass.declarations.toMutableList())
|
||||
if (generatorExtensions.isNotEmpty()) {
|
||||
addAll(regularClass.generatedMembers(session))
|
||||
addAll(regularClass.generatedNestedClassifiers(session))
|
||||
}
|
||||
}
|
||||
val irConstructor = (allDeclarations.firstOrNull { it is FirConstructor && it.isPrimary })?.let {
|
||||
declarationStorage.getOrCreateIrConstructor(it as FirConstructor, irClass, isLocal = regularClass.isLocal)
|
||||
}
|
||||
if (irConstructor != null) {
|
||||
irClass.declarations += irConstructor
|
||||
}
|
||||
val allDeclarations = regularClass.declarations.toMutableList()
|
||||
for (declaration in syntheticPropertiesLast(regularClass.declarations)) {
|
||||
for (declaration in syntheticPropertiesLast(allDeclarations)) {
|
||||
val irDeclaration = processMemberDeclaration(declaration, regularClass, irClass) ?: continue
|
||||
irClass.declarations += irDeclaration
|
||||
}
|
||||
@@ -186,6 +219,13 @@ class Fir2IrConverter(
|
||||
registerClassAndNestedClasses(it, irClass)
|
||||
}
|
||||
}
|
||||
if (generatorExtensions.isNotEmpty()) {
|
||||
regularClass.generatedNestedClassifiers(session).forEach {
|
||||
if (it is FirRegularClass) {
|
||||
registerClassAndNestedClasses(it, irClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
return irClass
|
||||
}
|
||||
|
||||
@@ -196,6 +236,13 @@ class Fir2IrConverter(
|
||||
processClassAndNestedClassHeaders(it)
|
||||
}
|
||||
}
|
||||
if (generatorExtensions.isNotEmpty()) {
|
||||
regularClass.generatedNestedClassifiers(session).forEach {
|
||||
if (it is FirRegularClass) {
|
||||
processClassAndNestedClassHeaders(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun processMemberDeclaration(
|
||||
@@ -294,7 +341,12 @@ class Fir2IrConverter(
|
||||
components.callGenerator = callGenerator
|
||||
|
||||
val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, irBuiltIns)
|
||||
for (firFile in firFiles) {
|
||||
|
||||
val allFirFiles = buildList {
|
||||
addAll(firFiles)
|
||||
addAll(session.createFilesWithGeneratedDeclarations())
|
||||
}
|
||||
for (firFile in allFirFiles) {
|
||||
converter.registerFileAndClasses(firFile, irModuleFragment)
|
||||
}
|
||||
val irProviders =
|
||||
@@ -306,14 +358,14 @@ class Fir2IrConverter(
|
||||
// Necessary call to generate built-in IR classes
|
||||
externalDependenciesGenerator.generateUnboundSymbolsAsDependencies()
|
||||
classifierStorage.preCacheBuiltinClasses()
|
||||
for (firFile in firFiles) {
|
||||
for (firFile in allFirFiles) {
|
||||
converter.processClassHeaders(firFile)
|
||||
}
|
||||
for (firFile in firFiles) {
|
||||
for (firFile in allFirFiles) {
|
||||
converter.processFileAndClassMembers(firFile)
|
||||
}
|
||||
|
||||
for (firFile in firFiles) {
|
||||
for (firFile in allFirFiles) {
|
||||
firFile.accept(fir2irVisitor, null)
|
||||
}
|
||||
|
||||
|
||||
+14
-3
@@ -12,12 +12,15 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFromEnumClass
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.primaryConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.dispatchReceiverClassOrNull
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||
import org.jetbrains.kotlin.fir.extensions.declarationGenerators
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedMembers
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedNestedClassifiers
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
@@ -48,7 +51,15 @@ internal class ClassMemberGenerator(
|
||||
fun convertClassContent(irClass: IrClass, klass: FirClass) {
|
||||
declarationStorage.enterScope(irClass)
|
||||
conversionScope.withClass(irClass) {
|
||||
val primaryConstructor = klass.primaryConstructor
|
||||
val allDeclarations = buildList {
|
||||
addAll(klass.declarations)
|
||||
if (session.extensionService.declarationGenerators.isNotEmpty()) {
|
||||
addAll(klass.generatedMembers(session))
|
||||
addAll(klass.generatedNestedClassifiers(session))
|
||||
}
|
||||
}
|
||||
|
||||
val primaryConstructor = allDeclarations.firstOrNull { it is FirConstructor && it.isPrimary } as FirConstructor?
|
||||
val irPrimaryConstructor = primaryConstructor?.let { declarationStorage.getCachedIrConstructor(it)!! }
|
||||
if (irPrimaryConstructor != null) {
|
||||
with(declarationStorage) {
|
||||
@@ -60,7 +71,7 @@ internal class ClassMemberGenerator(
|
||||
fakeOverrideGenerator.bindOverriddenSymbols(irClass.declarations)
|
||||
components.delegatedMemberGenerator.bindDelegatedMembersOverriddenSymbols(irClass)
|
||||
|
||||
klass.declarations.forEach { declaration ->
|
||||
allDeclarations.forEach { declaration ->
|
||||
when {
|
||||
declaration is FirTypeAlias -> {
|
||||
}
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.extensions
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.scopes.processClassifiersByName
|
||||
|
||||
fun FirClass.generatedNestedClassifiers(session: FirSession): List<FirDeclaration> {
|
||||
val scope = session.declaredMemberScope(this)
|
||||
val result = mutableListOf<FirDeclaration>()
|
||||
for (name in scope.getClassifierNames()) {
|
||||
scope.processClassifiersByName(name) {
|
||||
if (it.fir.origin.generated) {
|
||||
result += it.fir
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun FirClass.generatedMembers(session: FirSession): List<FirDeclaration> {
|
||||
val scope = session.declaredMemberScope(this)
|
||||
val result = mutableListOf<FirDeclaration>()
|
||||
for (name in scope.getCallableNames()) {
|
||||
scope.processFunctionsByName(name) {
|
||||
if (it.fir.origin.generated) {
|
||||
result += it.fir
|
||||
}
|
||||
}
|
||||
scope.processPropertiesByName(name) {
|
||||
if (it.fir.origin.generated) {
|
||||
result += it.fir
|
||||
}
|
||||
}
|
||||
}
|
||||
scope.processDeclaredConstructors {
|
||||
if (it.fir.origin.generated) {
|
||||
result += it.fir
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
+2
-2
@@ -38,8 +38,8 @@ class IrPrettyKotlinDumpHandler(testServices: TestServices) : AbstractIrHandler(
|
||||
|
||||
val irFiles = info.backendInput.irModuleFragment.files
|
||||
val builder = dumper.builderForModule(module)
|
||||
val filteredIrFiles = irFiles.groupWithTestFiles(module).filter {
|
||||
EXTERNAL_FILE !in it.first.directives
|
||||
val filteredIrFiles = irFiles.groupWithTestFiles(module).filterNot {
|
||||
it.first?.directives?.contains(EXTERNAL_FILE) == true
|
||||
}.map { it.second }
|
||||
val printFileName = filteredIrFiles.size > 1 || testServices.moduleStructure.modules.size > 1
|
||||
for (irFile in filteredIrFiles) {
|
||||
|
||||
+8
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.backend.handlers
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
@@ -46,9 +47,9 @@ class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServ
|
||||
defaultExtension else "fir.$defaultExtension"
|
||||
}
|
||||
|
||||
fun List<IrFile>.groupWithTestFiles(module: TestModule): List<Pair<TestFile, IrFile>> = mapNotNull { irFile ->
|
||||
fun List<IrFile>.groupWithTestFiles(module: TestModule): List<Pair<TestFile?, IrFile>> = mapNotNull { irFile ->
|
||||
val name = irFile.fileEntry.name.removePrefix("/")
|
||||
val testFile = module.files.firstOrNull { it.name == name } ?: return@mapNotNull null
|
||||
val testFile = module.files.firstOrNull { it.name == name }
|
||||
testFile to irFile
|
||||
}
|
||||
}
|
||||
@@ -66,8 +67,11 @@ class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServ
|
||||
val testFileToIrFile = irFiles.groupWithTestFiles(module)
|
||||
val builder = baseDumper.builderForModule(module)
|
||||
for ((testFile, irFile) in testFileToIrFile) {
|
||||
if (EXTERNAL_FILE in testFile.directives) continue
|
||||
val actualDump = irFile.dumpTreesFromLineNumber(lineNumber = 0, normalizeNames = true)
|
||||
if (testFile?.directives?.contains(EXTERNAL_FILE) == true) continue
|
||||
var actualDump = irFile.dumpTreesFromLineNumber(lineNumber = 0, normalizeNames = true)
|
||||
if (actualDump.isEmpty()) {
|
||||
actualDump = irFile.dumpTreesFromLineNumber(lineNumber = UNDEFINED_OFFSET, normalizeNames = true)
|
||||
}
|
||||
builder.append(actualDump)
|
||||
}
|
||||
compareDumpsOfExternalClasses(module, info)
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.util.dumpTreesFromLineNumber
|
||||
import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler.Companion.groupWithTestFiles
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.EXTERNAL_FILE
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
@@ -24,7 +25,7 @@ class IrTreeVerifierHandler(testServices: TestServices) : AbstractIrHandler(test
|
||||
val irFiles = info.backendInput.irModuleFragment.files
|
||||
val testFileToIrFile = irFiles.groupWithTestFiles(module)
|
||||
for ((testFile, irFile) in testFileToIrFile) {
|
||||
if (CodegenTestDirectives.EXTERNAL_FILE in testFile.directives) continue
|
||||
if (testFile?.directives?.contains(EXTERNAL_FILE) == true) continue
|
||||
|
||||
IrVerifier(assertions).verifyWithAssert(irFile)
|
||||
|
||||
|
||||
+6
-44
@@ -7,12 +7,15 @@ package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.backend.createFilesWithGeneratedDeclarations
|
||||
import org.jetbrains.kotlin.fir.builder.buildPackageDirective
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildFile
|
||||
import org.jetbrains.kotlin.fir.extensions.declarationGenerators
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedMembers
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedNestedClassifiers
|
||||
import org.jetbrains.kotlin.fir.moduleData
|
||||
import org.jetbrains.kotlin.fir.resolve.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
||||
@@ -42,28 +45,9 @@ class FirDumpHandler(
|
||||
val builderForModule = dumper.builderForModule(module)
|
||||
val firFiles = info.firFiles
|
||||
|
||||
val symbolProvider = info.session.symbolProvider
|
||||
val declarationGenerators = info.session.extensionService.declarationGenerators
|
||||
val topLevelClasses = declarationGenerators.flatMap { it.getTopLevelClassIds() }.groupBy { it.packageFqName }
|
||||
val topLevelCallables = declarationGenerators.flatMap { it.getTopLevelCallableIds() }.groupBy { it.packageName }
|
||||
|
||||
val allFiles = buildList {
|
||||
addAll(firFiles.values)
|
||||
for (packageFqName in (topLevelClasses.keys + topLevelCallables.keys)) {
|
||||
this += buildFile {
|
||||
origin = FirDeclarationOrigin.Synthetic
|
||||
moduleData = info.session.moduleData
|
||||
packageDirective = buildPackageDirective {
|
||||
this.packageFqName = packageFqName
|
||||
}
|
||||
name = "### GENERATED DECLARATIONS ###"
|
||||
declarations += topLevelCallables.getOrDefault(packageFqName, emptyList())
|
||||
.flatMap { symbolProvider.getTopLevelCallableSymbols(packageFqName, it.callableName) }
|
||||
.map { it.fir }
|
||||
declarations += topLevelClasses.getOrDefault(packageFqName, emptyList())
|
||||
.mapNotNull { symbolProvider.getClassLikeSymbolByClassId(it)?.fir }
|
||||
}
|
||||
}
|
||||
addAll(info.session.createFilesWithGeneratedDeclarations())
|
||||
}
|
||||
|
||||
val renderer = FirRendererWithGeneratedDeclarations(info.session, builderForModule)
|
||||
@@ -92,30 +76,8 @@ class FirDumpHandler(
|
||||
override fun renderClassDeclarations(regularClass: FirRegularClass) {
|
||||
val allDeclarations = buildList {
|
||||
addAll(regularClass.declarations)
|
||||
|
||||
@OptIn(SymbolInternals::class)
|
||||
fun addGeneratedDeclaration(symbol: FirBasedSymbol<*>) {
|
||||
val declaration = symbol.fir
|
||||
if (declaration.origin.generated) {
|
||||
add(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
val scope = session.declaredMemberScope(regularClass)
|
||||
for (callableName in scope.getCallableNames()) {
|
||||
scope.processFunctionsByName(callableName) {
|
||||
addGeneratedDeclaration(it)
|
||||
}
|
||||
scope.processPropertiesByName(callableName) {
|
||||
addGeneratedDeclaration(it)
|
||||
}
|
||||
}
|
||||
|
||||
for (classifierName in scope.getClassifierNames()) {
|
||||
scope.processClassifiersByName(classifierName) {
|
||||
addGeneratedDeclaration(it)
|
||||
}
|
||||
}
|
||||
addAll(regularClass.generatedMembers(session))
|
||||
addAll(regularClass.generatedNestedClassifiers(session))
|
||||
}
|
||||
allDeclarations.renderDeclarations()
|
||||
}
|
||||
|
||||
+6
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildPrimaryConstructor
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
@OptIn(SymbolInternals::class)
|
||||
fun FirDeclarationGenerationExtension.buildMaterializeFunction(
|
||||
matchedClassSymbol: FirClassLikeSymbol<*>,
|
||||
callableId: CallableId
|
||||
@@ -50,6 +52,10 @@ fun FirDeclarationGenerationExtension.buildMaterializeFunction(
|
||||
}
|
||||
name = callableId.callableName
|
||||
symbol = FirNamedFunctionSymbol(callableId)
|
||||
dispatchReceiverType = callableId.classId?.let {
|
||||
val firClass = session.symbolProvider.getClassLikeSymbolByClassId(it)?.fir as? FirClass
|
||||
firClass?.defaultType()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-2
@@ -26,7 +26,24 @@ FILE fqName:<root> fileName:/classWithGeneratedMembersAndNestedClass.kt
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:materialize visibility:public modality:FINAL <> () returnType:<root>.Foo [fake_override]
|
||||
FUN name:materialize visibility:public modality:FINAL <> ($this:<root>.Foo) returnType:<root>.Foo
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Foo
|
||||
CLASS CLASS name:Nested modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo.Nested
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Foo.Nested [primary]
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
@@ -63,6 +80,7 @@ FILE fqName:<root> fileName:/classWithGeneratedMembersAndNestedClass.kt
|
||||
VALUE_PARAMETER name:foo index:0 type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
VAR name:foo2 type:<root>.Foo [val]
|
||||
CALL 'public final fun materialize (): <root>.Foo declared in <root>' type=<root>.Foo origin=null
|
||||
CALL 'public final fun materialize (): <root>.Foo declared in <root>.Foo' type=<root>.Foo origin=null
|
||||
$this: GET_VAR 'foo: <root>.Foo declared in <root>.test_1' type=<root>.Foo origin=null
|
||||
VAR name:nested type:<root>.Foo.Nested [val]
|
||||
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Foo.Nested' type=<root>.Foo.Nested origin=null
|
||||
|
||||
+2
@@ -14,6 +14,8 @@ FILE: classWithGeneratedMembersAndNestedClass.kt
|
||||
public final fun materialize(): R|Foo|
|
||||
|
||||
public final class Nested : R|kotlin/Any| {
|
||||
public constructor(): R|Foo.Nested|
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+54
-2
@@ -56,8 +56,60 @@ FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt
|
||||
VAR name:nestedFoo type:foo.AllOpenGenerated.NestedFoo [val]
|
||||
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in foo.AllOpenGenerated.NestedFoo' type=foo.AllOpenGenerated.NestedFoo origin=null
|
||||
CALL 'public final fun foo (): kotlin.Unit declared in bar.Foo' type=kotlin.Unit origin=null
|
||||
$this: CALL 'public final fun materialize (): bar.Foo declared in foo' type=bar.Foo origin=null
|
||||
$this: CALL 'public final fun materialize (): bar.Foo declared in foo.AllOpenGenerated.NestedFoo' type=bar.Foo origin=null
|
||||
$this: GET_VAR 'val nestedFoo: foo.AllOpenGenerated.NestedFoo [val] declared in bar.testNestedClasses' type=foo.AllOpenGenerated.NestedFoo origin=null
|
||||
VAR name:nestedBar type:foo.AllOpenGenerated.NestedBar [val]
|
||||
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in foo.AllOpenGenerated.NestedBar' type=foo.AllOpenGenerated.NestedBar origin=null
|
||||
CALL 'public final fun bar (): kotlin.Unit declared in bar.Bar' type=kotlin.Unit origin=null
|
||||
$this: CALL 'public final fun materialize (): bar.Foo declared in foo' type=bar.Bar origin=null
|
||||
$this: CALL 'public final fun materialize (): bar.Bar declared in foo.AllOpenGenerated.NestedBar' type=bar.Bar origin=null
|
||||
$this: GET_VAR 'val nestedBar: foo.AllOpenGenerated.NestedBar [val] declared in bar.testNestedClasses' type=foo.AllOpenGenerated.NestedBar origin=null
|
||||
FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt
|
||||
CLASS CLASS name:AllOpenGenerated modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.AllOpenGenerated
|
||||
CLASS CLASS name:NestedFoo modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.AllOpenGenerated.NestedFoo
|
||||
FUN name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedFoo) returnType:bar.Foo
|
||||
$this: VALUE_PARAMETER name:<this> type:foo.AllOpenGenerated.NestedFoo
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS CLASS name:NestedBar modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.AllOpenGenerated.NestedBar
|
||||
FUN name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedBar) returnType:bar.Bar
|
||||
$this: VALUE_PARAMETER name:<this> type:foo.AllOpenGenerated.NestedBar
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
|
||||
+7
-1
@@ -28,18 +28,24 @@ FILE: generatedClassWithMembersAndNestedClasses.kt
|
||||
lval nestedBar: R|foo/AllOpenGenerated.NestedBar| = Q|foo/AllOpenGenerated|.R|foo/AllOpenGenerated.NestedBar|()
|
||||
R|<local>/nestedBar|.R|foo/AllOpenGenerated.NestedBar.materialize|().R|bar/Bar.bar|()
|
||||
}
|
||||
FILE: ### GENERATED DECLARATIONS ###
|
||||
FILE: __GENERATED DECLARATIONS__.kt
|
||||
package foo
|
||||
|
||||
public final class AllOpenGenerated : R|kotlin/Any| {
|
||||
public constructor(): R|foo/AllOpenGenerated|
|
||||
|
||||
public final class NestedFoo : R|kotlin/Any| {
|
||||
public final fun materialize(): R|bar/Foo|
|
||||
|
||||
public constructor(): R|foo/AllOpenGenerated.NestedFoo|
|
||||
|
||||
}
|
||||
|
||||
public final class NestedBar : R|kotlin/Any| {
|
||||
public final fun materialize(): R|bar/Bar|
|
||||
|
||||
public constructor(): R|foo/AllOpenGenerated.NestedBar|
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -31,3 +31,6 @@ FILE fqName:foo fileName:/topLevelCallables.kt
|
||||
FUN name:takeString visibility:public modality:FINAL <> (s:kotlin.String) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:s index:0 type:kotlin.String
|
||||
BLOCK_BODY
|
||||
FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt
|
||||
FUN name:dummyMySuperClass visibility:public modality:FINAL <> (value:foo.MySuperClass) returnType:kotlin.String
|
||||
VALUE_PARAMETER name:value index:0 type:foo.MySuperClass
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ FILE: topLevelCallables.kt
|
||||
}
|
||||
public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| {
|
||||
}
|
||||
FILE: ### GENERATED DECLARATIONS ###
|
||||
FILE: __GENERATED DECLARATIONS__.kt
|
||||
package foo
|
||||
|
||||
public final fun dummyMySuperClass(value: R|foo/MySuperClass|): R|kotlin/String|
|
||||
|
||||
Reference in New Issue
Block a user