[FIR] builder: provide containingDeclarationSymbol
We cannot use only non-local declarations as anchors due to the same resolution logic between member declarations of local classes, so we have to support such cases as well ^KT-63042
This commit is contained in:
committed by
Space Team
parent
be4bc81b1b
commit
c5cba4c053
+715
-644
File diff suppressed because it is too large
Load Diff
+13
-3
@@ -7,15 +7,19 @@ package org.jetbrains.kotlin.fir.lightTree.fir
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.DestructuringContext
|
||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.addDestructuringStatements
|
||||
import org.jetbrains.kotlin.fir.declarations.FirVariable
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCallCopy
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildBlock
|
||||
import org.jetbrains.kotlin.fir.generateTemporaryVariable
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
@@ -27,6 +31,7 @@ data class DestructuringDeclaration(
|
||||
val source: KtSourceElement,
|
||||
val annotations: List<FirAnnotation>,
|
||||
) {
|
||||
context(AbstractRawFirBuilder<*>)
|
||||
fun toFirDestructingDeclaration(
|
||||
moduleData: FirModuleData,
|
||||
tmpVariable: Boolean = true,
|
||||
@@ -49,19 +54,24 @@ class DestructuringEntry(
|
||||
val source: KtSourceElement,
|
||||
val returnTypeRef: FirTypeRef,
|
||||
val name: Name,
|
||||
val annotations: List<FirAnnotation>,
|
||||
val annotations: List<FirAnnotationCall>,
|
||||
) {
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
companion object : DestructuringContext<DestructuringEntry> {
|
||||
override val DestructuringEntry.returnTypeRef: FirTypeRef get() = returnTypeRef
|
||||
override val DestructuringEntry.name: Name get() = name
|
||||
override val DestructuringEntry.source: KtSourceElement get() = source
|
||||
override fun DestructuringEntry.extractAnnotationsTo(target: FirAnnotationContainerBuilder) {
|
||||
target.annotations += annotations
|
||||
override fun DestructuringEntry.extractAnnotationsTo(target: FirAnnotationContainerBuilder, containerSymbol: FirBasedSymbol<*>) {
|
||||
target.annotations += annotations.map {
|
||||
buildAnnotationCallCopy(it) {
|
||||
containingDeclarationSymbol = containerSymbol
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context(AbstractRawFirBuilder<*>)
|
||||
fun MutableList<FirStatement>.addDestructuringStatements(
|
||||
moduleData: FirModuleData,
|
||||
multiDeclaration: DestructuringDeclaration,
|
||||
|
||||
+15
-6
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.isFromVararg
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSyntaxDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCallCopy
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildPropertyAccessExpression
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
||||
import org.jetbrains.kotlin.fir.references.builder.buildPropertyFromParameterResolvedNamedReference
|
||||
@@ -128,8 +129,16 @@ class ValueParameter(
|
||||
source = propertySource
|
||||
}
|
||||
}
|
||||
|
||||
isVar = this@ValueParameter.isVar
|
||||
symbol = FirPropertySymbol(callableId)
|
||||
val propertySymbol = FirPropertySymbol(callableId)
|
||||
val remappedAnnotations = modifiers.annotations.map {
|
||||
buildAnnotationCallCopy(it) {
|
||||
containingDeclarationSymbol = propertySymbol
|
||||
}
|
||||
}
|
||||
|
||||
symbol = propertySymbol
|
||||
dispatchReceiverType = currentDispatchReceiver
|
||||
isLocal = false
|
||||
status = FirDeclarationStatusImpl(modifiers.getVisibility(), modifiers.getModality(isClassOrObject = false)).apply {
|
||||
@@ -145,7 +154,7 @@ class ValueParameter(
|
||||
moduleData = moduleData,
|
||||
origin = FirDeclarationOrigin.Source,
|
||||
source = defaultAccessorSource,
|
||||
annotations = modifiers.annotations.filter {
|
||||
annotations = remappedAnnotations.filter {
|
||||
it.useSiteTarget == FIELD || it.useSiteTarget == PROPERTY_DELEGATE_FIELD
|
||||
}.toMutableList(),
|
||||
returnTypeRef = returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.DefaultAccessor),
|
||||
@@ -154,7 +163,7 @@ class ValueParameter(
|
||||
status = status.copy(isLateInit = false),
|
||||
)
|
||||
|
||||
annotations += modifiers.annotations.filter {
|
||||
annotations += remappedAnnotations.filter {
|
||||
it.useSiteTarget == null || it.useSiteTarget == PROPERTY
|
||||
}
|
||||
|
||||
@@ -168,7 +177,7 @@ class ValueParameter(
|
||||
isInline = modifiers.hasInline(),
|
||||
).also {
|
||||
it.initContainingClassAttr(context)
|
||||
it.replaceAnnotations(modifiers.annotations.filterUseSiteTarget(PROPERTY_GETTER))
|
||||
it.replaceAnnotations(remappedAnnotations.filterUseSiteTarget(PROPERTY_GETTER))
|
||||
}
|
||||
setter = if (this.isVar) FirDefaultPropertySetter(
|
||||
defaultAccessorSource,
|
||||
@@ -177,11 +186,11 @@ class ValueParameter(
|
||||
type.copyWithNewSourceKind(KtFakeSourceElementKind.DefaultAccessor),
|
||||
modifiers.getVisibility(),
|
||||
symbol,
|
||||
parameterAnnotations = modifiers.annotations.filterUseSiteTarget(SETTER_PARAMETER),
|
||||
parameterAnnotations = remappedAnnotations.filterUseSiteTarget(SETTER_PARAMETER),
|
||||
isInline = modifiers.hasInline(),
|
||||
).also {
|
||||
it.initContainingClassAttr(context)
|
||||
it.replaceAnnotations(modifiers.annotations.filterUseSiteTarget(PROPERTY_SETTER))
|
||||
it.replaceAnnotations(remappedAnnotations.filterUseSiteTarget(PROPERTY_SETTER))
|
||||
} else null
|
||||
}.apply {
|
||||
if (firValueParameter.isVararg) {
|
||||
|
||||
+4
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
* 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.lightTree
|
||||
@@ -24,7 +24,8 @@ abstract class AbstractLightTree2FirConverterTestCase : AbstractRawFirBuilderTes
|
||||
).buildFirFile(Paths.get(filePath))
|
||||
val firDump = FirRenderer.withDeclarationAttributes().renderElementAsString(firFile)
|
||||
|
||||
val expectedFile = File(filePath.replace(".kt", ".txt"))
|
||||
val expectedFile = File(expectedPath(filePath, ".txt"))
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, firDump)
|
||||
checkAnnotationOwners(filePath, firFile)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user