From 16a46fbc0b2cf7d7ca7f276ae43f2a92067b51c3 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 17 Mar 2023 14:38:14 +0200 Subject: [PATCH] [FIR] Reformat RawFirBuilder.kt --- .../kotlin/fir/builder/RawFirBuilder.kt | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index d0862064509..a464635174c 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -32,8 +32,8 @@ import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.* -import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl +import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl import org.jetbrains.kotlin.lexer.KtTokens.* @@ -49,6 +49,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.runIf +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled open class RawFirBuilder( session: FirSession, @@ -1581,7 +1582,8 @@ open class RawFirBuilder( multiParameter } else { val typeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef { - source = valueParameter.toFirSourceElement().fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter) + source = valueParameter.toFirSourceElement() + .fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter) } convertValueParameter(valueParameter, symbol, typeRef, ValueParameterDeclaration.LAMBDA) } @@ -1814,13 +1816,14 @@ open class RawFirBuilder( } if (hasDelegate()) { - fun extractDelegateExpression() = buildOrLazyExpression(this@toFirProperty.toFirSourceElement(KtFakeSourceElementKind.WrappedDelegate)) { - this@toFirProperty.delegate?.expression?.let { expression -> - expression.toFirExpression("Should have delegate") - } ?: buildErrorExpression { - diagnostic = ConeSimpleDiagnostic("Should have delegate", DiagnosticKind.ExpressionExpected) + fun extractDelegateExpression() = + buildOrLazyExpression(this@toFirProperty.toFirSourceElement(KtFakeSourceElementKind.WrappedDelegate)) { + this@toFirProperty.delegate?.expression?.let { expression -> + expression.toFirExpression("Should have delegate") + } ?: buildErrorExpression { + diagnostic = ConeSimpleDiagnostic("Should have delegate", DiagnosticKind.ExpressionExpected) + } } - } val delegateBuilder = FirWrappedDelegateExpressionBuilder().apply { val delegateExpression = extractDelegateExpression() @@ -2023,7 +2026,7 @@ open class RawFirBuilder( KtProjectionKind.IN -> Variance.IN_VARIANCE KtProjectionKind.OUT -> Variance.OUT_VARIANCE KtProjectionKind.NONE -> Variance.INVARIANT - KtProjectionKind.STAR -> throw AssertionError("* should not be here") + KtProjectionKind.STAR -> shouldNotBeCalled() } } } @@ -2546,21 +2549,22 @@ open class RawFirBuilder( val source = expression.toFirSourceElement() val (calleeReference, explicitReceiver, isImplicitInvoke) = splitToCalleeAndReceiver(expression.calleeExpression, source) - val result: FirQualifiedAccessExpressionBuilder = if (expression.valueArgumentList == null && expression.lambdaArguments.isEmpty()) { - FirPropertyAccessExpressionBuilder().apply { - this.source = source - this.calleeReference = calleeReference + val result: FirQualifiedAccessExpressionBuilder = + if (expression.valueArgumentList == null && expression.lambdaArguments.isEmpty()) { + FirPropertyAccessExpressionBuilder().apply { + this.source = source + this.calleeReference = calleeReference + } + } else { + val builder = if (isImplicitInvoke) FirImplicitInvokeCallBuilder() else FirFunctionCallBuilder() + builder.apply { + this.source = source + this.calleeReference = calleeReference + context.calleeNamesForLambda += calleeReference.name + expression.extractArgumentsTo(this) + context.calleeNamesForLambda.removeLast() + } } - } else { - val builder = if (isImplicitInvoke) FirImplicitInvokeCallBuilder() else FirFunctionCallBuilder() - builder.apply { - this.source = source - this.calleeReference = calleeReference - context.calleeNamesForLambda += calleeReference.name - expression.extractArgumentsTo(this) - context.calleeNamesForLambda.removeLast() - } - } return result.apply { this.explicitReceiver = explicitReceiver