[FIR] Add opt-in to replaceIsTrailingLambda
#KT-66553
This commit is contained in:
committed by
Space Team
parent
1876c8a9ee
commit
b74dcb77e3
+2
@@ -1515,6 +1515,8 @@ class LightTreeRawFirExpressionBuilder(
|
|||||||
LABELED_EXPRESSION,
|
LABELED_EXPRESSION,
|
||||||
ANNOTATED_EXPRESSION,
|
ANNOTATED_EXPRESSION,
|
||||||
-> container += getAsFirExpression<FirAnonymousFunctionExpression>(node).apply {
|
-> container += getAsFirExpression<FirAnonymousFunctionExpression>(node).apply {
|
||||||
|
// TODO(KT-66553) remove and set in builder
|
||||||
|
@OptIn(RawFirApi::class)
|
||||||
replaceIsTrailingLambda(newIsTrailingLambda = true)
|
replaceIsTrailingLambda(newIsTrailingLambda = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -905,6 +905,8 @@ open class PsiRawFirBuilder(
|
|||||||
buildOrLazyExpression((argument as? PsiElement)?.toFirSourceElement()) { argument.toFirExpression() }
|
buildOrLazyExpression((argument as? PsiElement)?.toFirSourceElement()) { argument.toFirExpression() }
|
||||||
arguments += when (argument) {
|
arguments += when (argument) {
|
||||||
is KtLambdaArgument -> argumentExpression.apply {
|
is KtLambdaArgument -> argumentExpression.apply {
|
||||||
|
// TODO(KT-66553) remove and set in builder
|
||||||
|
@OptIn(RawFirApi::class)
|
||||||
(this as? FirAnonymousFunctionExpression)?.replaceIsTrailingLambda(true)
|
(this as? FirAnonymousFunctionExpression)?.replaceIsTrailingLambda(true)
|
||||||
}
|
}
|
||||||
else -> argumentExpression
|
else -> argumentExpression
|
||||||
|
|||||||
+1
@@ -37,6 +37,7 @@ abstract class FirAnonymousFunctionExpression : FirExpression() {
|
|||||||
|
|
||||||
abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)
|
abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)
|
||||||
|
|
||||||
|
@RawFirApi
|
||||||
abstract fun replaceIsTrailingLambda(newIsTrailingLambda: Boolean)
|
abstract fun replaceIsTrailingLambda(newIsTrailingLambda: Boolean)
|
||||||
|
|
||||||
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirAnonymousFunctionExpression
|
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirAnonymousFunctionExpression
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2024 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("API is only for raw FIR building.")
|
||||||
|
annotation class RawFirApi
|
||||||
+2
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.KtSourceElement
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousFunctionExpression
|
import org.jetbrains.kotlin.fir.expressions.FirAnonymousFunctionExpression
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.RawFirApi
|
||||||
import org.jetbrains.kotlin.fir.expressions.UnresolvedExpressionTypeAccess
|
import org.jetbrains.kotlin.fir.expressions.UnresolvedExpressionTypeAccess
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
import org.jetbrains.kotlin.fir.types.coneTypeOrNull
|
import org.jetbrains.kotlin.fir.types.coneTypeOrNull
|
||||||
@@ -42,6 +43,7 @@ internal class FirAnonymousFunctionExpressionImpl(
|
|||||||
anonymousFunction.replaceAnnotations(newAnnotations)
|
anonymousFunction.replaceAnnotations(newAnnotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RawFirApi
|
||||||
override fun replaceIsTrailingLambda(newIsTrailingLambda: Boolean) {
|
override fun replaceIsTrailingLambda(newIsTrailingLambda: Boolean) {
|
||||||
isTrailingLambda = newIsTrailingLambda
|
isTrailingLambda = newIsTrailingLambda
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -332,7 +332,9 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
|||||||
|
|
||||||
anonymousFunctionExpression.configure {
|
anonymousFunctionExpression.configure {
|
||||||
+field(anonymousFunction).withTransform()
|
+field(anonymousFunction).withTransform()
|
||||||
+booleanField("isTrailingLambda", withReplace = true)
|
+booleanField("isTrailingLambda", withReplace = true).apply {
|
||||||
|
replaceOptInAnnotation = rawFirApi
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typeParameter.configure {
|
typeParameter.configure {
|
||||||
|
|||||||
@@ -124,4 +124,5 @@ val firTransformerType = generatedType("visitors", "FirTransformer")
|
|||||||
|
|
||||||
val resolveStateAccessAnnotation = type("fir.declarations", "ResolveStateAccess", kind = TypeKind.Class)
|
val resolveStateAccessAnnotation = type("fir.declarations", "ResolveStateAccess", kind = TypeKind.Class)
|
||||||
val unresolvedExpressionTypeAccessAnnotation = type("fir.expressions", "UnresolvedExpressionTypeAccess", kind = TypeKind.Class)
|
val unresolvedExpressionTypeAccessAnnotation = type("fir.expressions", "UnresolvedExpressionTypeAccess", kind = TypeKind.Class)
|
||||||
|
val rawFirApi = type("fir.expressions", "RawFirApi", kind = TypeKind.Class)
|
||||||
val firBuilderDslAnnotation = type("fir.builder", "FirBuilderDsl", kind = TypeKind.Class)
|
val firBuilderDslAnnotation = type("fir.builder", "FirBuilderDsl", kind = TypeKind.Class)
|
||||||
|
|||||||
+4
@@ -103,6 +103,10 @@ class FieldWithDefault(override val origin: Field) : Field(), AbstractFieldWithD
|
|||||||
get() = origin.optInAnnotation
|
get() = origin.optInAnnotation
|
||||||
set(_) {}
|
set(_) {}
|
||||||
|
|
||||||
|
override var replaceOptInAnnotation: ClassRef<*>?
|
||||||
|
get() = origin.replaceOptInAnnotation
|
||||||
|
set(_) {}
|
||||||
|
|
||||||
override var defaultValueInImplementation: String? = origin.defaultValueInImplementation
|
override var defaultValueInImplementation: String? = origin.defaultValueInImplementation
|
||||||
override var defaultValueInBuilder: String? = null
|
override var defaultValueInBuilder: String? = null
|
||||||
override var isMutable: Boolean = origin.isMutable
|
override var isMutable: Boolean = origin.isMutable
|
||||||
|
|||||||
+1
@@ -78,6 +78,7 @@ fun SmartPrinter.replaceFunctionDeclaration(
|
|||||||
implementationKind == ImplementationKind.AbstractClass || implementationKind == ImplementationKind.SealedClass
|
implementationKind == ImplementationKind.AbstractClass || implementationKind == ImplementationKind.SealedClass
|
||||||
},
|
},
|
||||||
override = override,
|
override = override,
|
||||||
|
optInAnnotation = field.replaceOptInAnnotation,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -27,6 +27,7 @@ abstract class AbstractField<Field : AbstractField<Field>> {
|
|||||||
open val arbitraryImportables: MutableList<Importable> = mutableListOf()
|
open val arbitraryImportables: MutableList<Importable> = mutableListOf()
|
||||||
|
|
||||||
open var optInAnnotation: ClassRef<*>? = null
|
open var optInAnnotation: ClassRef<*>? = null
|
||||||
|
open var replaceOptInAnnotation: ClassRef<*>? = null
|
||||||
|
|
||||||
abstract var isMutable: Boolean
|
abstract var isMutable: Boolean
|
||||||
open val withGetter: Boolean get() = false
|
open val withGetter: Boolean get() = false
|
||||||
@@ -102,6 +103,7 @@ abstract class AbstractField<Field : AbstractField<Field>> {
|
|||||||
copy.isLateinit = isLateinit
|
copy.isLateinit = isLateinit
|
||||||
copy.arbitraryImportables += arbitraryImportables
|
copy.arbitraryImportables += arbitraryImportables
|
||||||
copy.optInAnnotation = optInAnnotation
|
copy.optInAnnotation = optInAnnotation
|
||||||
|
copy.replaceOptInAnnotation = replaceOptInAnnotation
|
||||||
copy.isMutable = isMutable
|
copy.isMutable = isMutable
|
||||||
copy.deprecation = deprecation
|
copy.deprecation = deprecation
|
||||||
copy.visibility = visibility
|
copy.visibility = visibility
|
||||||
|
|||||||
+5
@@ -117,7 +117,12 @@ fun SmartPrinter.printFunctionDeclaration(
|
|||||||
override: Boolean = false,
|
override: Boolean = false,
|
||||||
isInline: Boolean = false,
|
isInline: Boolean = false,
|
||||||
allParametersOnSeparateLines: Boolean = false,
|
allParametersOnSeparateLines: Boolean = false,
|
||||||
|
optInAnnotation: ClassRef<*>? = null,
|
||||||
) {
|
) {
|
||||||
|
optInAnnotation?.let {
|
||||||
|
println("@", it.render())
|
||||||
|
}
|
||||||
|
|
||||||
if (visibility != Visibility.PUBLIC) {
|
if (visibility != Visibility.PUBLIC) {
|
||||||
print(visibility.name.toLowerCaseAsciiOnly(), " ")
|
print(visibility.name.toLowerCaseAsciiOnly(), " ")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user