FIR: add ImplicitTypeRef to the control flow fir element sources

This commit is contained in:
Ilya Kirillov
2020-06-22 15:21:23 +03:00
parent 94967bcd00
commit 1c564e1bd6
19 changed files with 58 additions and 19 deletions
@@ -103,7 +103,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(expression, "FirElseIfTrueCondition") {
default("typeRef", "FirImplicitBooleanTypeRef(source)")
defaultTypeRefWithSource("FirImplicitBooleanTypeRef")
useTypes(implicitBooleanTypeRefType)
publicImplementation()
}
@@ -259,17 +259,17 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(resolvedReifiedParameterReference)
impl(returnExpression) {
default("typeRef", "FirImplicitNothingTypeRef(source)")
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
useTypes(implicitNothingTypeRefType)
}
impl(stringConcatenationCall) {
default("typeRef", "FirImplicitStringTypeRef(source)")
defaultTypeRefWithSource("FirImplicitStringTypeRef")
useTypes(implicitStringTypeRefType)
}
impl(throwExpression) {
default("typeRef", "FirImplicitNothingTypeRef(source)")
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
useTypes(implicitNothingTypeRefType)
}
@@ -279,7 +279,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(expression, "FirUnitExpression") {
default("typeRef", "FirImplicitUnitTypeRef(source)")
defaultTypeRefWithSource("FirImplicitUnitTypeRef")
useTypes(implicitUnitTypeRefType)
publicImplementation()
}
@@ -427,12 +427,12 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(breakExpression) {
default("typeRef", "FirImplicitNothingTypeRef(source)")
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
useTypes(implicitNothingTypeRefType)
}
impl(continueExpression) {
default("typeRef", "FirImplicitNothingTypeRef(source)")
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
useTypes(implicitNothingTypeRefType)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -122,6 +122,12 @@ abstract class AbstractFirTreeImplementationConfigurator {
}
}
fun defaultTypeRefWithSource(typeRefClass: String) {
default("typeRef", "$typeRefClass(source?.withKind(FirFakeSourceElementKind.ImplicitTypeRef))")
implementation.arbitraryImportables += ArbitraryImportable("org.jetbrains.kotlin.fir", "FirFakeSourceElementKind")
implementation.arbitraryImportables += ArbitraryImportable("org.jetbrains.kotlin.fir", "withKind")
}
fun defaultTrue(field: String, withGetter: Boolean = false) {
default(field) {
value = "true"
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -172,4 +172,6 @@ class TypeArgumentWithMultipleUpperBounds(name: String, override val upperBounds
override fun toString(): String {
return name
}
}
}
data class ArbitraryImportable(override val packageName: String, override val type: String) : Importable
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -41,6 +41,7 @@ class Implementation(val element: Element, val name: String?) : FieldContainer,
override val packageName = element.packageName + ".impl"
val usedTypes = mutableListOf<Importable>()
val arbitraryImportables = mutableListOf<ArbitraryImportable>()
var isPublic = false
var requiresOptIn = false
@@ -35,7 +35,9 @@ fun Builder.collectImports(): List<String> {
fun Implementation.collectImports(base: List<String> = emptyList(), kind: ImportKind = ImportKind.Implementation): List<String> {
return element.collectImportsInternal(
base + listOf(element.fullQualifiedName)
+ usedTypes.mapNotNull { it.fullQualifiedName } + parents.mapNotNull { it.fullQualifiedName }
+ usedTypes.mapNotNull { it.fullQualifiedName }
+ arbitraryImportables.mapNotNull { it.fullQualifiedName }
+ parents.mapNotNull { it.fullQualifiedName }
+ listOfNotNull(
pureAbstractElementType.fullQualifiedName?.takeIf { needPureAbstractElement },
firImplementationDetailType.fullQualifiedName?.takeIf { isPublic || requiresOptIn },