From 9d72c1c370eeec6cc09cd935dd57e9680bdf430c Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Tue, 21 Nov 2023 15:21:13 +0100 Subject: [PATCH] [FIR] builder: drop unused forcedElementSourceKind There was only one usage by withDefaultSourceElementKind that was dropped in the previous commit ^KT-63042 --- .../converter/AbstractLightTreeRawFirBuilder.kt | 4 ++-- .../converter/LightTreeRawFirExpressionBuilder.kt | 4 ++-- .../jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt | 4 ++-- .../kotlin/fir/builder/AbstractRawFirBuilder.kt | 12 +----------- .../src/org/jetbrains/kotlin/fir/builder/Context.kt | 6 ++---- .../jetbrains/kotlin/fir/builder/ConversionUtils.kt | 10 +--------- 6 files changed, 10 insertions(+), 30 deletions(-) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/AbstractLightTreeRawFirBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/AbstractLightTreeRawFirBuilder.kt index 007b85f80a8..59bc141fbe7 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/AbstractLightTreeRawFirBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/AbstractLightTreeRawFirBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -31,7 +31,7 @@ abstract class AbstractLightTreeRawFirBuilder( override fun LighterASTNode.toFirSourceElement(kind: KtFakeSourceElementKind?): KtLightSourceElement { val startOffset = tree.getStartOffset(this) val endOffset = tree.getEndOffset(this) - return toKtLightSourceElement(tree, kind ?: context.forcedElementSourceKind ?: KtRealSourceElementKind, startOffset, endOffset) + return toKtLightSourceElement(tree, kind ?: KtRealSourceElementKind, startOffset, endOffset) } override val LighterASTNode.elementType: IElementType diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt index 3829e9aa6cf..dbc7cadd633 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -78,7 +78,7 @@ class LightTreeRawFirExpressionBuilder( ) } else -> buildErrorExpression( - converted?.source?.withForcedKindFrom(context) ?: expression?.toFirSourceElement(), + converted?.source?.realElement() ?: expression?.toFirSourceElement(), if (expression == null) ConeSyntaxDiagnostic(errorReason) else ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected), converted, diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt index 49693f26788..8d82281ed4d 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt @@ -85,7 +85,7 @@ open class PsiRawFirBuilder( } override fun PsiElement.toFirSourceElement(kind: KtFakeSourceElementKind?): KtPsiSourceElement { - val actualKind = kind ?: this@PsiRawFirBuilder.context.forcedElementSourceKind ?: KtRealSourceElementKind + val actualKind = kind ?: KtRealSourceElementKind return this.toKtPsiSourceElement(actualKind) } @@ -317,7 +317,7 @@ open class PsiRawFirBuilder( else -> buildErrorExpression { nonExpressionElement = fir diagnostic = diagnosticFn() - source = fir?.source?.withForcedKindFrom(this@PsiRawFirBuilder.context) ?: toFirSourceElement() + source = fir?.source?.realElement() ?: toFirSourceElement() } } } diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt index c0d6aa8a917..dc81b8ff667 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -1003,16 +1003,6 @@ abstract class AbstractRawFirBuilder(val baseSession: FirSession, val context initContainingClassAttr(context) } - protected inline fun withDefaultSourceElementKind(newDefault: KtSourceElementKind, action: () -> R): R { - val currentForced = context.forcedElementSourceKind - context.forcedElementSourceKind = newDefault - try { - return action() - } finally { - context.forcedElementSourceKind = currentForced - } - } - protected fun buildLabelAndErrorSource(rawName: String, source: KtSourceElement): Pair { val firLabel = buildLabel { name = KtPsiUtil.unquoteIdentifier(rawName) diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/Context.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/Context.kt index e34388c66a7..b425ced6efc 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/Context.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/Context.kt @@ -1,15 +1,13 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.builder -import org.jetbrains.kotlin.KtSourceElementKind import org.jetbrains.kotlin.fir.FirFunctionTarget import org.jetbrains.kotlin.fir.FirLabel import org.jetbrains.kotlin.fir.FirLoopTarget -import org.jetbrains.kotlin.util.PrivateForInline import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef import org.jetbrains.kotlin.fir.declarations.builder.buildOuterClassTypeParameterRef import org.jetbrains.kotlin.fir.expressions.FirExpression @@ -19,6 +17,7 @@ import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.util.PrivateForInline class Context { lateinit var packageFqName: FqName @@ -51,7 +50,6 @@ class Context { val capturedTypeParameters = mutableListOf() val arraySetArgument = mutableMapOf() - var forcedElementSourceKind: KtSourceElementKind? = null val dispatchReceiverTypesStack = mutableListOf() var containerIsExpect: Boolean = false diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index f1dcf84c0b9..20f2c5be633 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -6,10 +6,10 @@ package org.jetbrains.kotlin.fir.builder import com.intellij.psi.tree.IElementType +import org.jetbrains.kotlin.* import org.jetbrains.kotlin.KtFakeSourceElementKind import org.jetbrains.kotlin.KtRealSourceElementKind import org.jetbrains.kotlin.KtSourceElement -import org.jetbrains.kotlin.* import org.jetbrains.kotlin.contracts.description.LogicOperationKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities @@ -707,14 +707,6 @@ fun AnnotationUseSiteTarget?.appliesToPrimaryConstructorParameter() = this == nu this == AnnotationUseSiteTarget.RECEIVER || this == AnnotationUseSiteTarget.FILE -fun KtSourceElement.withForcedKindFrom(context: Context<*>): KtSourceElement { - return when (val forcedKind = context.forcedElementSourceKind) { - kind -> this - is KtFakeSourceElementKind -> fakeElement(forcedKind) - else -> this.realElement() - } -} - fun FirErrorTypeRef.wrapIntoArray(): FirResolvedTypeRef { val typeRef = this return buildResolvedTypeRef {