[FIR] Update FIR schema to add opt-in to FirExpression.coneTypeOrNull
#KT-61367
This commit is contained in:
committed by
Space Team
parent
b3cb8870e0
commit
6ec419edb7
+9
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.expressions
|
||||||
|
|
||||||
|
@RequiresOptIn("Accessing `coneTypeOrNull` hides potential bugs if at the given point all expression and their types should be resolved. Consider using `resolvedType` instead.")
|
||||||
|
annotation class UnresolvedExpressionTypeAccess
|
||||||
+3
-1
@@ -132,7 +132,9 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
|||||||
}
|
}
|
||||||
|
|
||||||
expression.configure {
|
expression.configure {
|
||||||
+field("coneTypeOrNull", coneKotlinTypeType, nullable = true, withReplace = true)
|
+field("coneTypeOrNull", coneKotlinTypeType, nullable = true, withReplace = true).apply {
|
||||||
|
optInAnnotation = unresolvedExpressionTypeAccessImport
|
||||||
|
}
|
||||||
+annotations
|
+annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -20,3 +20,5 @@ val coneTypeOrNullImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types",
|
|||||||
|
|
||||||
val fakeSourceElementKindImport = ArbitraryImportable("org.jetbrains.kotlin", "KtFakeSourceElementKind")
|
val fakeSourceElementKindImport = ArbitraryImportable("org.jetbrains.kotlin", "KtFakeSourceElementKind")
|
||||||
val fakeElementImport = ArbitraryImportable("org.jetbrains.kotlin", "fakeElement")
|
val fakeElementImport = ArbitraryImportable("org.jetbrains.kotlin", "fakeElement")
|
||||||
|
|
||||||
|
val unresolvedExpressionTypeAccessImport = ArbitraryImportable("org.jetbrains.kotlin.fir.expressions","UnresolvedExpressionTypeAccess")
|
||||||
|
|||||||
+4
-2
@@ -280,9 +280,11 @@ private fun SmartPrinter.printDslBuildFunction(
|
|||||||
|
|
||||||
private fun SmartPrinter.printDslBuildCopyFunction(
|
private fun SmartPrinter.printDslBuildCopyFunction(
|
||||||
builder: LeafBuilder,
|
builder: LeafBuilder,
|
||||||
hasRequiredFields: Boolean
|
hasRequiredFields: Boolean,
|
||||||
) {
|
) {
|
||||||
println("@OptIn(ExperimentalContracts::class)")
|
val optIns =
|
||||||
|
builder.allFields.filter { !it.invisibleField }.mapNotNullTo(mutableSetOf("ExperimentalContracts")) { it.optInAnnotation?.type }
|
||||||
|
println("@OptIn(${optIns.joinToString { "$it::class" }})")
|
||||||
print("inline ")
|
print("inline ")
|
||||||
print("fun ")
|
print("fun ")
|
||||||
builder.implementation.element.typeArguments.takeIf { it.isNotEmpty() }?.let {
|
builder.implementation.element.typeArguments.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
|||||||
+4
-3
@@ -79,10 +79,11 @@ fun SmartPrinter.printElement(element: Element) {
|
|||||||
withIndent {
|
withIndent {
|
||||||
allFields.forEach { field ->
|
allFields.forEach { field ->
|
||||||
if (field.isFinal && field.fromParent || field.isParameter) return@forEach
|
if (field.isFinal && field.fromParent || field.isParameter) return@forEach
|
||||||
if (!field.isFinal) {
|
printField(field, isImplementation = false, override = field.fromParent) {
|
||||||
abstract()
|
if (!field.isFinal) {
|
||||||
|
abstract()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printField(field, isImplementation = false, override = field.fromParent, end = "")
|
|
||||||
}
|
}
|
||||||
if (allFields.isNotEmpty()) {
|
if (allFields.isNotEmpty()) {
|
||||||
println()
|
println()
|
||||||
|
|||||||
+10
-3
@@ -9,15 +9,17 @@ import org.jetbrains.kotlin.fir.tree.generator.model.Field
|
|||||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||||
|
|
||||||
|
|
||||||
fun SmartPrinter.printField(field: Field, isImplementation: Boolean, override: Boolean, end: String, notNull: Boolean = false) {
|
fun SmartPrinter.printField(field: Field, isImplementation: Boolean, override: Boolean, inConstructor: Boolean = false, notNull: Boolean = false, modifiers: SmartPrinter.() -> Unit = {}) {
|
||||||
if (!field.isVal && field.isVolatile) {
|
if (!field.isVal && field.isVolatile) {
|
||||||
println("@Volatile")
|
println("@Volatile")
|
||||||
}
|
}
|
||||||
|
|
||||||
field.optInAnnotation?.let {
|
field.optInAnnotation?.let {
|
||||||
println("@${it.type}")
|
println(if (inConstructor) "@property:${it.type}" else "@${it.type}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifiers()
|
||||||
|
|
||||||
if (override) {
|
if (override) {
|
||||||
print("override ")
|
print("override ")
|
||||||
}
|
}
|
||||||
@@ -30,13 +32,18 @@ fun SmartPrinter.printField(field: Field, isImplementation: Boolean, override: B
|
|||||||
print("val")
|
print("val")
|
||||||
}
|
}
|
||||||
val type = if (isImplementation) field.getMutableType(notNull = notNull) else field.getTypeWithArguments(notNull = notNull)
|
val type = if (isImplementation) field.getMutableType(notNull = notNull) else field.getTypeWithArguments(notNull = notNull)
|
||||||
println(" ${field.name}: $type$end")
|
print(" ${field.name}: $type")
|
||||||
|
if (inConstructor) print(",")
|
||||||
|
println()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SmartPrinter.printFieldWithDefaultInImplementation(field: Field) {
|
fun SmartPrinter.printFieldWithDefaultInImplementation(field: Field) {
|
||||||
if (!field.isVal && field.isVolatile) {
|
if (!field.isVal && field.isVolatile) {
|
||||||
println("@Volatile")
|
println("@Volatile")
|
||||||
}
|
}
|
||||||
|
field.optInAnnotation?.let {
|
||||||
|
println("@OptIn(${it.type}::class)")
|
||||||
|
}
|
||||||
val defaultValue = field.defaultValueInImplementation
|
val defaultValue = field.defaultValueInImplementation
|
||||||
print("override ")
|
print("override ")
|
||||||
if (field.isVal) {
|
if (field.isVal) {
|
||||||
|
|||||||
+14
-8
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.tree.generator.model.*
|
|||||||
import org.jetbrains.kotlin.fir.tree.generator.model.Implementation.Kind
|
import org.jetbrains.kotlin.fir.tree.generator.model.Implementation.Kind
|
||||||
import org.jetbrains.kotlin.fir.tree.generator.pureAbstractElementType
|
import org.jetbrains.kotlin.fir.tree.generator.pureAbstractElementType
|
||||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
||||||
import org.jetbrains.kotlin.utils.withIndent
|
import org.jetbrains.kotlin.utils.withIndent
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -50,9 +51,18 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
with(implementation) {
|
with(implementation) {
|
||||||
if (requiresOptIn) {
|
buildSet {
|
||||||
println("@OptIn(FirImplementationDetail::class)")
|
if (requiresOptIn) {
|
||||||
|
add("FirImplementationDetail")
|
||||||
|
}
|
||||||
|
|
||||||
|
for (field in fieldsWithoutDefault) {
|
||||||
|
field.optInAnnotation?.let { add(it.type) }
|
||||||
|
}
|
||||||
|
}.ifNotEmpty {
|
||||||
|
println("@OptIn(${joinToString { "$it::class" }})")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPublic) {
|
if (!isPublic) {
|
||||||
print("internal ")
|
print("internal ")
|
||||||
}
|
}
|
||||||
@@ -78,7 +88,7 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
if (field.isParameter) {
|
if (field.isParameter) {
|
||||||
println("${field.name}: ${field.typeWithArguments},")
|
println("${field.name}: ${field.typeWithArguments},")
|
||||||
} else if (!field.isFinal) {
|
} else if (!field.isFinal) {
|
||||||
printField(field, isImplementation = true, override = true, end = ",", notNull = field.notNull)
|
printField(field, isImplementation = true, override = true, inConstructor = true, notNull = field.notNull)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,7 +106,7 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
allFields.forEach {
|
allFields.forEach {
|
||||||
|
|
||||||
abstract()
|
abstract()
|
||||||
printField(it, isImplementation = true, override = true, end = "", notNull = it.notNull)
|
printField(it, isImplementation = true, override = true, notNull = it.notNull)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fieldsWithDefault.forEach {
|
fieldsWithDefault.forEach {
|
||||||
@@ -127,10 +137,6 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (customCall in customCalls) {
|
for (customCall in customCalls) {
|
||||||
customCall.optInAnnotation?.let {
|
|
||||||
println("@OptIn(${it.type}::class)")
|
|
||||||
}
|
|
||||||
|
|
||||||
println("${customCall.name} = ${customCall.customInitializationCall}")
|
println("${customCall.name} = ${customCall.customInitializationCall}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user