[LL FIR] drop RawFirReplacement as obsolete
This commit is contained in:
committed by
Space Team
parent
ba947fbf04
commit
fd74de6ccf
+9
-88
@@ -19,13 +19,9 @@ import org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.buildDestructuringVariable
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
@@ -43,8 +39,7 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
baseScopeProvider: FirScopeProvider,
|
||||
private val originalDeclaration: FirDeclaration,
|
||||
private val declarationToBuild: KtElement,
|
||||
private val functionsToRebind: Set<FirFunction>? = null,
|
||||
private val replacementApplier: RawFirReplacement.Applier? = null,
|
||||
private val functionsToRebind: Set<FirFunction>,
|
||||
) : PsiRawFirBuilder(session, baseScopeProvider, bodyBuildingMode = BodyBuildingMode.NORMAL) {
|
||||
companion object {
|
||||
fun buildWithFunctionSymbolRebind(
|
||||
@@ -56,10 +51,10 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
val functionsToRebind = when (val originalDeclaration = designation.target) {
|
||||
is FirFunction -> setOf(originalDeclaration)
|
||||
is FirProperty -> setOfNotNull(originalDeclaration.getter, originalDeclaration.setter)
|
||||
else -> null
|
||||
else -> emptySet()
|
||||
}
|
||||
|
||||
return build(session, scopeProvider, designation, rootNonLocalDeclaration, functionsToRebind, rebindContainingSymbol = true)
|
||||
return build(session, scopeProvider, designation, rootNonLocalDeclaration, functionsToRebind)
|
||||
}
|
||||
|
||||
private fun build(
|
||||
@@ -67,9 +62,7 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
scopeProvider: FirScopeProvider,
|
||||
designation: FirDesignation,
|
||||
rootNonLocalDeclaration: KtElement,
|
||||
functionsToRebind: Set<FirFunction>? = null,
|
||||
replacementApplier: RawFirReplacement.Applier? = null,
|
||||
rebindContainingSymbol: Boolean = false,
|
||||
functionsToRebind: Set<FirFunction>,
|
||||
): FirDeclaration {
|
||||
check(rootNonLocalDeclaration is KtDeclaration || rootNonLocalDeclaration is KtCodeFragment)
|
||||
|
||||
@@ -79,14 +72,11 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
originalDeclaration = designation.target as FirDeclaration,
|
||||
declarationToBuild = rootNonLocalDeclaration,
|
||||
functionsToRebind = functionsToRebind,
|
||||
replacementApplier = replacementApplier
|
||||
)
|
||||
|
||||
builder.context.packageFqName = rootNonLocalDeclaration.containingKtFile.packageFqName
|
||||
if (rebindContainingSymbol) {
|
||||
@OptIn(PrivateForInline::class)
|
||||
builder.context.forcedContainerSymbol = designation.target.symbol
|
||||
}
|
||||
@OptIn(PrivateForInline::class)
|
||||
builder.context.forcedContainerSymbol = designation.target.symbol
|
||||
|
||||
return builder.moveNext(designation.path.iterator(), containingDeclaration = null)
|
||||
}
|
||||
@@ -129,21 +119,17 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
|
||||
private inner class VisitorWithReplacement(private val containingClass: FirRegularClass?) : Visitor() {
|
||||
fun convertDestructuringDeclaration(element: KtDestructuringDeclaration, containingDeclaration: FirDeclaration?): FirVariable {
|
||||
val replacementDeclaration = replacementApplier?.tryReplace(element) ?: element
|
||||
requireIsInstance<KtDestructuringDeclaration>(replacementDeclaration)
|
||||
return if (containingDeclaration is FirScript) {
|
||||
withContainerSymbol(containingDeclaration.symbol) {
|
||||
// Annotations from script destructuring declarations are linked to the script itself
|
||||
buildScriptDestructuringDeclaration(replacementDeclaration)
|
||||
buildScriptDestructuringDeclaration(element)
|
||||
}
|
||||
} else {
|
||||
buildErrorTopLevelDestructuringDeclaration(replacementDeclaration.toFirSourceElement())
|
||||
buildErrorTopLevelDestructuringDeclaration(element.toFirSourceElement())
|
||||
}
|
||||
}
|
||||
|
||||
fun convertDestructuringDeclarationEntry(element: KtDestructuringDeclarationEntry): FirVariable {
|
||||
val replacementDeclaration = replacementApplier?.tryReplace(element) ?: element
|
||||
requireIsInstance<KtDestructuringDeclarationEntry>(replacementDeclaration)
|
||||
requireIsInstance<FirProperty>(originalDeclaration)
|
||||
|
||||
val container = originalDeclaration.destructuringDeclarationContainerVariable?.fir
|
||||
@@ -170,72 +156,7 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
}
|
||||
|
||||
fun convertAnonymousInitializer(element: KtAnonymousInitializer, containingDeclaration: FirDeclaration?): FirAnonymousInitializer {
|
||||
val replacementDeclaration = replacementApplier?.tryReplace(element) ?: element
|
||||
requireIsInstance<KtAnonymousInitializer>(replacementDeclaration)
|
||||
return buildAnonymousInitializer(replacementDeclaration, containingDeclaration?.symbol)
|
||||
}
|
||||
|
||||
override fun convertElement(element: KtElement, original: FirElement?): FirElement? =
|
||||
super.convertElement(replacementApplier?.tryReplace(element) ?: element, original)
|
||||
|
||||
override fun convertProperty(
|
||||
property: KtProperty,
|
||||
ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?,
|
||||
ownerRegularClassTypeParametersCount: Int?,
|
||||
): FirProperty {
|
||||
val replacementProperty = replacementApplier?.tryReplace(property) ?: property
|
||||
check(replacementProperty is KtProperty)
|
||||
return super.convertProperty(
|
||||
property = replacementProperty,
|
||||
ownerRegularOrAnonymousObjectSymbol = ownerRegularOrAnonymousObjectSymbol,
|
||||
ownerRegularClassTypeParametersCount = ownerRegularClassTypeParametersCount
|
||||
)
|
||||
}
|
||||
|
||||
override fun convertPropertyAccessor(
|
||||
accessor: KtPropertyAccessor?,
|
||||
property: KtProperty,
|
||||
propertyTypeRef: FirTypeRef,
|
||||
propertySymbol: FirPropertySymbol,
|
||||
isGetter: Boolean,
|
||||
accessorAnnotationsFromProperty: List<FirAnnotation>,
|
||||
parameterAnnotationsFromProperty: List<FirAnnotation>,
|
||||
): FirPropertyAccessor? {
|
||||
val replacementAccessor = if (accessor != null) {
|
||||
val replacementAccessor = replacementApplier?.tryReplace(accessor) ?: accessor
|
||||
check(replacementAccessor is KtPropertyAccessor)
|
||||
replacementAccessor
|
||||
} else {
|
||||
accessor
|
||||
}
|
||||
|
||||
return super.convertPropertyAccessor(
|
||||
replacementAccessor,
|
||||
property,
|
||||
propertyTypeRef,
|
||||
propertySymbol,
|
||||
isGetter,
|
||||
accessorAnnotationsFromProperty,
|
||||
parameterAnnotationsFromProperty
|
||||
)
|
||||
}
|
||||
|
||||
override fun convertValueParameter(
|
||||
valueParameter: KtParameter,
|
||||
functionSymbol: FirFunctionSymbol<*>,
|
||||
defaultTypeRef: FirTypeRef?,
|
||||
valueParameterDeclaration: ValueParameterDeclaration,
|
||||
additionalAnnotations: List<FirAnnotation>,
|
||||
): FirValueParameter {
|
||||
val replacementParameter = replacementApplier?.tryReplace(valueParameter) ?: valueParameter
|
||||
check(replacementParameter is KtParameter)
|
||||
return super.convertValueParameter(
|
||||
valueParameter = replacementParameter,
|
||||
functionSymbol = functionSymbol,
|
||||
defaultTypeRef = defaultTypeRef,
|
||||
valueParameterDeclaration = valueParameterDeclaration,
|
||||
additionalAnnotations = additionalAnnotations
|
||||
)
|
||||
return buildAnonymousInitializer(element, containingDeclaration?.symbol)
|
||||
}
|
||||
|
||||
private fun extractContructorConversionParams(
|
||||
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.analysis.low.level.api.fir.lazy.resolve
|
||||
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
internal data class RawFirReplacement(val from: KtElement, val to: KtElement) {
|
||||
companion object {
|
||||
fun isApplicableForReplacement(element: KtElement) = when (element) {
|
||||
is KtFile, is KtScript, is KtClassInitializer, is KtPropertyAccessor, is KtConstructor<*>, is KtClassOrObject, is KtObjectLiteralExpression, is KtTypeAlias,
|
||||
is KtNamedFunction, is KtLambdaExpression, is KtAnonymousInitializer, is KtProperty, is KtTypeReference,
|
||||
is KtAnnotationEntry, is KtTypeParameter, is KtTypeProjection, is KtParameter, is KtBlockExpression,
|
||||
is KtSimpleNameExpression, is KtConstantExpression, is KtStringTemplateExpression, is KtReturnExpression,
|
||||
is KtTryExpression, is KtIfExpression, is KtWhenExpression, is KtDoWhileExpression, is KtWhileExpression,
|
||||
is KtForExpression, is KtBreakExpression, is KtContinueExpression, is KtBinaryExpression, is KtBinaryExpressionWithTypeRHS,
|
||||
is KtIsExpression, is KtUnaryExpression, is KtCallExpression, is KtArrayAccessExpression, is KtQualifiedExpression,
|
||||
is KtThisExpression, is KtSuperExpression, is KtParenthesizedExpression, is KtLabeledExpression, is KtAnnotatedExpression,
|
||||
is KtThrowExpression, is KtDestructuringDeclaration, is KtClassLiteralExpression, is KtCallableReferenceExpression,
|
||||
is KtCollectionLiteralExpression,
|
||||
-> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
inner class Applier {
|
||||
private var replacementApplied = false
|
||||
|
||||
private fun ensureReplacementIsValid() {
|
||||
require(from == to || isApplicableForReplacement(from)) {
|
||||
"Replacement is possible for applicable type but given ${from::class.simpleName}"
|
||||
}
|
||||
require(from::class == to::class) {
|
||||
"Replacement is possible for same type in replacements but given\n${from::class.simpleName} and ${to::class.simpleName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun tryReplace(element: KtElement): KtElement {
|
||||
if (from != element) return element
|
||||
ensureReplacementIsValid()
|
||||
replacementApplied = true
|
||||
return to
|
||||
}
|
||||
|
||||
fun ensureApplied() {
|
||||
check(from == to || replacementApplied) {
|
||||
"Replacement requested but was not applied for ${from::class.simpleName}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user