FIR: change source of existing type refs in DataClassMembersGenerator to avoid sources clash
This commit is contained in:
+27
-10
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
|||||||
//T can be either PsiElement, or LighterASTNode
|
//T can be either PsiElement, or LighterASTNode
|
||||||
abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Context<T> = Context()) {
|
abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Context<T> = Context()) {
|
||||||
|
|
||||||
abstract fun T.toFirSourceElement(kind: FirSourceElementKind = FirRealSourceElementKind): FirSourceElement
|
abstract fun T.toFirSourceElement(kind: FirFakeSourceElementKind? = null): FirSourceElement
|
||||||
|
|
||||||
protected val implicitUnitType = baseSession.builtinTypes.unitType
|
protected val implicitUnitType = baseSession.builtinTypes.unitType
|
||||||
protected val implicitAnyType = baseSession.builtinTypes.anyType
|
protected val implicitAnyType = baseSession.builtinTypes.anyType
|
||||||
@@ -697,28 +697,32 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
private val session: FirSession,
|
private val session: FirSession,
|
||||||
private val source: T,
|
private val source: T,
|
||||||
private val classBuilder: FirRegularClassBuilder,
|
private val classBuilder: FirRegularClassBuilder,
|
||||||
private val primaryConstructor: FirConstructor,
|
|
||||||
private val zippedParameters: List<Pair<T, FirProperty>>,
|
private val zippedParameters: List<Pair<T, FirProperty>>,
|
||||||
private val packageFqName: FqName,
|
private val packageFqName: FqName,
|
||||||
private val classFqName: FqName,
|
private val classFqName: FqName,
|
||||||
|
private val createClassTypeRefWithSourceKind: (FirFakeSourceElementKind) -> FirTypeRef,
|
||||||
|
private val createParameterTypeRefWithSourceKind: (FirProperty, FirFakeSourceElementKind) -> FirTypeRef,
|
||||||
) {
|
) {
|
||||||
private val classTypeRef = primaryConstructor.returnTypeRef
|
|
||||||
|
|
||||||
fun generate() {
|
fun generate() {
|
||||||
generateComponentFunctions()
|
generateComponentFunctions()
|
||||||
generateCopyFunction()
|
generateCopyFunction()
|
||||||
// Refer to (IR utils or FIR backend) DataClassMembersGenerator for generating equals, hashCode, and toString
|
// Refer to (IR utils or FIR backend) DataClassMembersGenerator for generating equals, hashCode, and toString
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateComponentAccess(parameterSource: FirSourceElement?, firProperty: FirProperty) =
|
private fun generateComponentAccess(
|
||||||
|
parameterSource: FirSourceElement?,
|
||||||
|
firProperty: FirProperty,
|
||||||
|
classTypeRefWithCorrectSourceKind: FirTypeRef,
|
||||||
|
firPropertyReturnTypeRefWithCorrectSourceKind: FirTypeRef
|
||||||
|
) =
|
||||||
buildQualifiedAccessExpression {
|
buildQualifiedAccessExpression {
|
||||||
source = parameterSource
|
source = parameterSource
|
||||||
typeRef = firProperty.returnTypeRef
|
typeRef = firPropertyReturnTypeRefWithCorrectSourceKind
|
||||||
dispatchReceiver = buildThisReceiverExpression {
|
dispatchReceiver = buildThisReceiverExpression {
|
||||||
calleeReference = buildImplicitThisReference {
|
calleeReference = buildImplicitThisReference {
|
||||||
boundSymbol = classBuilder.symbol
|
boundSymbol = classBuilder.symbol
|
||||||
}
|
}
|
||||||
typeRef = classTypeRef
|
typeRef = classTypeRefWithCorrectSourceKind
|
||||||
}
|
}
|
||||||
calleeReference = buildResolvedNamedReference {
|
calleeReference = buildResolvedNamedReference {
|
||||||
source = parameterSource
|
source = parameterSource
|
||||||
@@ -755,7 +759,8 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
private fun generateCopyFunction() {
|
private fun generateCopyFunction() {
|
||||||
classBuilder.addDeclaration(
|
classBuilder.addDeclaration(
|
||||||
buildSimpleFunction {
|
buildSimpleFunction {
|
||||||
source = this@DataClassMembersGenerator.source.toFirSourceElement()
|
val classTypeRef = createClassTypeRefWithSourceKind(FirFakeSourceElementKind.DataClassGeneratedMembers)
|
||||||
|
source = this@DataClassMembersGenerator.source.toFirSourceElement(FirFakeSourceElementKind.DataClassGeneratedMembers)
|
||||||
session = this@DataClassMembersGenerator.session
|
session = this@DataClassMembersGenerator.session
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = classTypeRef
|
returnTypeRef = classTypeRef
|
||||||
@@ -764,7 +769,9 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
symbol = FirNamedFunctionSymbol(CallableId(packageFqName, classFqName, copyName))
|
symbol = FirNamedFunctionSymbol(CallableId(packageFqName, classFqName, copyName))
|
||||||
for ((ktParameter, firProperty) in zippedParameters) {
|
for ((ktParameter, firProperty) in zippedParameters) {
|
||||||
val propertyName = firProperty.name
|
val propertyName = firProperty.name
|
||||||
val parameterSource = ktParameter?.toFirSourceElement()
|
val parameterSource = ktParameter?.toFirSourceElement(FirFakeSourceElementKind.DataClassGeneratedMembers)
|
||||||
|
val propertyReturnTypeRef =
|
||||||
|
createParameterTypeRefWithSourceKind(firProperty, FirFakeSourceElementKind.DataClassGeneratedMembers)
|
||||||
valueParameters += buildValueParameter {
|
valueParameters += buildValueParameter {
|
||||||
source = parameterSource
|
source = parameterSource
|
||||||
session = this@DataClassMembersGenerator.session
|
session = this@DataClassMembersGenerator.session
|
||||||
@@ -772,7 +779,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
returnTypeRef = propertyReturnTypeRef
|
returnTypeRef = propertyReturnTypeRef
|
||||||
name = propertyName
|
name = propertyName
|
||||||
symbol = FirVariableSymbol(propertyName)
|
symbol = FirVariableSymbol(propertyName)
|
||||||
defaultValue = generateComponentAccess(parameterSource, firProperty)
|
defaultValue = generateComponentAccess(parameterSource, firProperty, propertyReturnTypeRef, classTypeRef)
|
||||||
isCrossinline = false
|
isCrossinline = false
|
||||||
isNoinline = false
|
isNoinline = false
|
||||||
isVararg = false
|
isVararg = false
|
||||||
@@ -790,4 +797,14 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
resolvedSymbol = this@toQualifiedAccess.symbol
|
resolvedSymbol = this@toQualifiedAccess.symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected inline fun <R> withDefaultSourceElementKind(newDefault: FirSourceElementKind, action: () -> R): R {
|
||||||
|
val currentForced = context.forcedElementSourceKind
|
||||||
|
context.forcedElementSourceKind = newDefault
|
||||||
|
try {
|
||||||
|
return action()
|
||||||
|
} finally {
|
||||||
|
context.forcedElementSourceKind = currentForced
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.builder
|
package org.jetbrains.kotlin.fir.builder
|
||||||
|
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.FirFunctionTarget
|
|
||||||
import org.jetbrains.kotlin.fir.FirLabel
|
|
||||||
import org.jetbrains.kotlin.fir.FirLoopTarget
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -28,4 +25,6 @@ class Context<T> {
|
|||||||
val firLoopTargets = mutableListOf<FirLoopTarget>()
|
val firLoopTargets = mutableListOf<FirLoopTarget>()
|
||||||
var capturedTypeParameters = persistentListOf<FirTypeParameterSymbol>()
|
var capturedTypeParameters = persistentListOf<FirTypeParameterSymbol>()
|
||||||
val arraySetArgument = mutableMapOf<T, FirExpression>()
|
val arraySetArgument = mutableMapOf<T, FirExpression>()
|
||||||
|
|
||||||
|
var forcedElementSourceKind: FirSourceElementKind? = null
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -10,13 +10,10 @@ import com.intellij.openapi.util.Ref
|
|||||||
import com.intellij.psi.tree.IElementType
|
import com.intellij.psi.tree.IElementType
|
||||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
import org.jetbrains.kotlin.fir.FirLightSourceElement
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElementKind
|
|
||||||
import org.jetbrains.kotlin.fir.builder.BaseFirBuilder
|
import org.jetbrains.kotlin.fir.builder.BaseFirBuilder
|
||||||
import org.jetbrains.kotlin.fir.builder.Context
|
import org.jetbrains.kotlin.fir.builder.Context
|
||||||
import org.jetbrains.kotlin.fir.builder.escapedStringToCharacter
|
import org.jetbrains.kotlin.fir.builder.escapedStringToCharacter
|
||||||
import org.jetbrains.kotlin.fir.toFirLightSourceElement
|
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef
|
||||||
import org.jetbrains.kotlin.lexer.KtToken
|
import org.jetbrains.kotlin.lexer.KtToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||||
@@ -31,7 +28,7 @@ open class BaseConverter(
|
|||||||
) : BaseFirBuilder<LighterASTNode>(baseSession, context) {
|
) : BaseFirBuilder<LighterASTNode>(baseSession, context) {
|
||||||
protected val implicitType = buildImplicitTypeRef()
|
protected val implicitType = buildImplicitTypeRef()
|
||||||
|
|
||||||
override fun LighterASTNode.toFirSourceElement(kind: FirSourceElementKind): FirLightSourceElement {
|
override fun LighterASTNode.toFirSourceElement(kind: FirFakeSourceElementKind?): FirLightSourceElement {
|
||||||
val startOffset = offset + tree.getStartOffset(this)
|
val startOffset = offset + tree.getStartOffset(this)
|
||||||
val endOffset = offset + tree.getEndOffset(this)
|
val endOffset = offset + tree.getEndOffset(this)
|
||||||
return toFirLightSourceElement(startOffset, endOffset, tree)
|
return toFirLightSourceElement(startOffset, endOffset, tree)
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -474,10 +474,11 @@ class DeclarationsConverter(
|
|||||||
baseSession,
|
baseSession,
|
||||||
classNode,
|
classNode,
|
||||||
this,
|
this,
|
||||||
firPrimaryConstructor,
|
|
||||||
zippedParameters,
|
zippedParameters,
|
||||||
context.packageFqName,
|
context.packageFqName,
|
||||||
context.className
|
context.className,
|
||||||
|
createClassTypeRefWithSourceKind = { firPrimaryConstructor.returnTypeRef },
|
||||||
|
createParameterTypeRefWithSourceKind = { property, _ -> property.returnTypeRef },
|
||||||
).generate()
|
).generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,9 @@ class RawFirBuilder(
|
|||||||
return reference.accept(Visitor(), Unit) as FirTypeRef
|
return reference.accept(Visitor(), Unit) as FirTypeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun PsiElement.toFirSourceElement(kind: FirSourceElementKind): FirPsiSourceElement<*> {
|
override fun PsiElement.toFirSourceElement(kind: FirFakeSourceElementKind?): FirPsiSourceElement<*> {
|
||||||
return this.toFirPsiSourceElement(kind)
|
val actualKind = kind ?: this@RawFirBuilder.context.forcedElementSourceKind ?: FirRealSourceElementKind
|
||||||
|
return this.toFirPsiSourceElement(actualKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val PsiElement.elementType: IElementType
|
override val PsiElement.elementType: IElementType
|
||||||
@@ -749,10 +750,17 @@ class RawFirBuilder(
|
|||||||
baseSession,
|
baseSession,
|
||||||
classOrObject,
|
classOrObject,
|
||||||
this,
|
this,
|
||||||
firPrimaryConstructor,
|
|
||||||
zippedParameters,
|
zippedParameters,
|
||||||
context.packageFqName,
|
context.packageFqName,
|
||||||
context.className
|
context.className,
|
||||||
|
createClassTypeRefWithSourceKind = { firPrimaryConstructor.returnTypeRef.copyWithNewSourceKind(it) },
|
||||||
|
createParameterTypeRefWithSourceKind = { property, newKind ->
|
||||||
|
// just making a shallow copy isn't enough type ref may be a function type ref
|
||||||
|
// and contain value parameters inside
|
||||||
|
withDefaultSourceElementKind(newKind) {
|
||||||
|
(property.returnTypeRef.psi as KtTypeReference).toFirOrImplicitType()
|
||||||
|
}
|
||||||
|
},
|
||||||
).generate()
|
).generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
@@ -43,3 +43,15 @@ inline fun buildComposedSuperTypeRef(init: FirComposedSuperTypeRefBuilder.() ->
|
|||||||
}
|
}
|
||||||
return FirComposedSuperTypeRefBuilder().apply(init).build()
|
return FirComposedSuperTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildComposedSuperTypeRefCopy(original: FirComposedSuperTypeRef, init: FirComposedSuperTypeRefBuilder.() -> Unit = {}): FirComposedSuperTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirComposedSuperTypeRefBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.annotations.addAll(original.annotations)
|
||||||
|
copyBuilder.superTypeRefs.addAll(original.superTypeRefs)
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+11
@@ -41,3 +41,14 @@ inline fun buildDelegatedTypeRef(init: FirDelegatedTypeRefBuilder.() -> Unit): F
|
|||||||
}
|
}
|
||||||
return FirDelegatedTypeRefBuilder().apply(init).build()
|
return FirDelegatedTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildDelegatedTypeRefCopy(original: FirDelegatedTypeRef, init: FirDelegatedTypeRefBuilder.() -> Unit): FirDelegatedTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirDelegatedTypeRefBuilder()
|
||||||
|
copyBuilder.delegate = original.delegate
|
||||||
|
copyBuilder.typeRef = original.typeRef
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+11
@@ -47,3 +47,14 @@ inline fun buildErrorTypeRef(init: FirErrorTypeRefBuilder.() -> Unit): FirErrorT
|
|||||||
}
|
}
|
||||||
return FirErrorTypeRefBuilder().apply(init).build()
|
return FirErrorTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildErrorTypeRefCopy(original: FirErrorTypeRef, init: FirErrorTypeRefBuilder.() -> Unit): FirErrorTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirErrorTypeRefBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.diagnostic = original.diagnostic
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+16
@@ -53,3 +53,19 @@ inline fun buildFunctionTypeRef(init: FirFunctionTypeRefBuilder.() -> Unit): Fir
|
|||||||
}
|
}
|
||||||
return FirFunctionTypeRefBuilder().apply(init).build()
|
return FirFunctionTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildFunctionTypeRefCopy(original: FirFunctionTypeRef, init: FirFunctionTypeRefBuilder.() -> Unit): FirFunctionTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirFunctionTypeRefBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.annotations.addAll(original.annotations)
|
||||||
|
copyBuilder.isMarkedNullable = original.isMarkedNullable
|
||||||
|
copyBuilder.receiverTypeRef = original.receiverTypeRef
|
||||||
|
copyBuilder.valueParameters.addAll(original.valueParameters)
|
||||||
|
copyBuilder.returnTypeRef = original.returnTypeRef
|
||||||
|
copyBuilder.isSuspend = original.isSuspend
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+10
@@ -37,3 +37,13 @@ inline fun buildImplicitTypeRef(init: FirImplicitTypeRefBuilder.() -> Unit = {})
|
|||||||
}
|
}
|
||||||
return FirImplicitTypeRefBuilder().apply(init).build()
|
return FirImplicitTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildImplicitTypeRefCopy(original: FirImplicitTypeRef, init: FirImplicitTypeRefBuilder.() -> Unit = {}): FirImplicitTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirImplicitTypeRefBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+17
@@ -55,3 +55,20 @@ inline fun buildResolvedFunctionTypeRef(init: FirResolvedFunctionTypeRefBuilder.
|
|||||||
}
|
}
|
||||||
return FirResolvedFunctionTypeRefBuilder().apply(init).build()
|
return FirResolvedFunctionTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildResolvedFunctionTypeRefCopy(original: FirResolvedFunctionTypeRef, init: FirResolvedFunctionTypeRefBuilder.() -> Unit): FirResolvedFunctionTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirResolvedFunctionTypeRefBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.annotations.addAll(original.annotations)
|
||||||
|
copyBuilder.type = original.type
|
||||||
|
copyBuilder.isSuspend = original.isSuspend
|
||||||
|
copyBuilder.isMarkedNullable = original.isMarkedNullable
|
||||||
|
copyBuilder.receiverTypeRef = original.receiverTypeRef
|
||||||
|
copyBuilder.valueParameters.addAll(original.valueParameters)
|
||||||
|
copyBuilder.returnTypeRef = original.returnTypeRef
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+16
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.types.builder
|
package org.jetbrains.kotlin.fir.types.builder
|
||||||
|
|
||||||
import kotlin.contracts.*
|
import kotlin.contracts.*
|
||||||
|
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||||
@@ -29,6 +30,7 @@ class FirResolvedTypeRefBuilder : FirAnnotationContainerBuilder {
|
|||||||
var delegatedTypeRef: FirTypeRef? = null
|
var delegatedTypeRef: FirTypeRef? = null
|
||||||
var isSuspend: Boolean = false
|
var isSuspend: Boolean = false
|
||||||
|
|
||||||
|
@OptIn(FirImplementationDetail::class)
|
||||||
override fun build(): FirResolvedTypeRef {
|
override fun build(): FirResolvedTypeRef {
|
||||||
return FirResolvedTypeRefImpl(
|
return FirResolvedTypeRefImpl(
|
||||||
source,
|
source,
|
||||||
@@ -48,3 +50,17 @@ inline fun buildResolvedTypeRef(init: FirResolvedTypeRefBuilder.() -> Unit): Fir
|
|||||||
}
|
}
|
||||||
return FirResolvedTypeRefBuilder().apply(init).build()
|
return FirResolvedTypeRefBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildResolvedTypeRefCopy(original: FirResolvedTypeRef, init: FirResolvedTypeRefBuilder.() -> Unit): FirResolvedTypeRef {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirResolvedTypeRefBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.annotations.addAll(original.annotations)
|
||||||
|
copyBuilder.type = original.type
|
||||||
|
copyBuilder.delegatedTypeRef = original.delegatedTypeRef
|
||||||
|
copyBuilder.isSuspend = original.isSuspend
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.types.impl
|
package org.jetbrains.kotlin.fir.types.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
@@ -17,7 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
|||||||
* DO NOT MODIFY IT MANUALLY
|
* DO NOT MODIFY IT MANUALLY
|
||||||
*/
|
*/
|
||||||
|
|
||||||
internal class FirResolvedTypeRefImpl(
|
class FirResolvedTypeRefImpl @FirImplementationDetail constructor(
|
||||||
override val source: FirSourceElement?,
|
override val source: FirSourceElement?,
|
||||||
override val annotations: MutableList<FirAnnotationCall>,
|
override val annotations: MutableList<FirAnnotationCall>,
|
||||||
override val type: ConeKotlinType,
|
override val type: ConeKotlinType,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,6 +8,10 @@ package org.jetbrains.kotlin.fir
|
|||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
|
import org.jetbrains.kotlin.fir.types.builder.*
|
||||||
|
import org.jetbrains.kotlin.fir.types.impl.*
|
||||||
|
import org.jetbrains.kotlin.fir.types.impl.FirFunctionTypeRefImpl
|
||||||
|
|
||||||
fun ModuleInfo.dependenciesWithoutSelf(): Sequence<ModuleInfo> = dependencies().asSequence().filter { it != this }
|
fun ModuleInfo.dependenciesWithoutSelf(): Sequence<ModuleInfo> = dependencies().asSequence().filter { it != this }
|
||||||
|
|
||||||
@@ -16,3 +20,41 @@ fun FirBlock.returnExpressions(): List<FirExpression> = listOfNotNull(statements
|
|||||||
|
|
||||||
private val PUBLIC_METHOD_NAMES_IN_OBJECT = setOf("equals", "hashCode", "getClass", "wait", "notify", "notifyAll", "toString")
|
private val PUBLIC_METHOD_NAMES_IN_OBJECT = setOf("equals", "hashCode", "getClass", "wait", "notify", "notifyAll", "toString")
|
||||||
|
|
||||||
|
// do we need a deep copy here ?
|
||||||
|
fun <R : FirTypeRef> R.copyWithNewSourceKind(newKind: FirFakeSourceElementKind): R {
|
||||||
|
if (source == null) return this
|
||||||
|
if (source?.kind == newKind) return this
|
||||||
|
if (this is FirDelegatedTypeRef) return this
|
||||||
|
val newSource = source?.withKind(newKind)
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return when (val typeRef = this) {
|
||||||
|
is FirResolvedTypeRefImpl -> buildResolvedTypeRefCopy(typeRef) {
|
||||||
|
source = newSource
|
||||||
|
}
|
||||||
|
is FirErrorTypeRef -> buildErrorTypeRefCopy(typeRef) {
|
||||||
|
source = newSource
|
||||||
|
}
|
||||||
|
is FirUserTypeRefImpl -> buildUserTypeRef {
|
||||||
|
source = newSource
|
||||||
|
isMarkedNullable = typeRef.isMarkedNullable
|
||||||
|
qualifier += typeRef.qualifier
|
||||||
|
annotations += typeRef.annotations
|
||||||
|
}
|
||||||
|
is FirResolvedFunctionTypeRef -> buildResolvedFunctionTypeRefCopy(typeRef) {
|
||||||
|
source = newSource
|
||||||
|
}
|
||||||
|
is FirImplicitTypeRef -> buildImplicitTypeRefCopy(typeRef) {
|
||||||
|
source = newSource
|
||||||
|
}
|
||||||
|
is FirComposedSuperTypeRef -> buildComposedSuperTypeRefCopy(typeRef) {
|
||||||
|
source = newSource
|
||||||
|
}
|
||||||
|
is FirFunctionTypeRefImpl -> buildFunctionTypeRefCopy(typeRef) {
|
||||||
|
source = newSource
|
||||||
|
}
|
||||||
|
is FirImplicitBuiltinTypeRef -> typeRef.withFakeSource(newKind)
|
||||||
|
else -> TODO("Not implemented for ${typeRef::class}")
|
||||||
|
} as R
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+55
-1
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 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.
|
* 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.types.impl
|
package org.jetbrains.kotlin.fir.types.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
|
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||||
@@ -16,6 +17,7 @@ import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
|||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||||
|
import org.jetbrains.kotlin.fir.withKind
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
sealed class FirImplicitBuiltinTypeRef(
|
sealed class FirImplicitBuiltinTypeRef(
|
||||||
@@ -132,3 +134,55 @@ class FirImplicitKMutableProperty2TypeRef(
|
|||||||
source, StandardClassIds.KMutableProperty2,
|
source, StandardClassIds.KMutableProperty2,
|
||||||
arrayOf(dispatchReceiverTypeArgument, extensionReceiverTypeArgument, propertyTypeArgument)
|
arrayOf(dispatchReceiverTypeArgument, extensionReceiverTypeArgument, propertyTypeArgument)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun FirImplicitBuiltinTypeRef.withFakeSource(kind: FirFakeSourceElementKind): FirImplicitBuiltinTypeRef {
|
||||||
|
val source = source ?: return this
|
||||||
|
if (source.kind == kind) return this
|
||||||
|
val newSource = source.withKind(kind)
|
||||||
|
return when (this) {
|
||||||
|
is FirImplicitUnitTypeRef -> FirImplicitUnitTypeRef(newSource)
|
||||||
|
is FirImplicitAnyTypeRef -> FirImplicitAnyTypeRef(newSource)
|
||||||
|
is FirImplicitNullableAnyTypeRef -> FirImplicitNullableAnyTypeRef(newSource)
|
||||||
|
is FirImplicitEnumTypeRef -> FirImplicitEnumTypeRef(newSource)
|
||||||
|
is FirImplicitAnnotationTypeRef -> FirImplicitAnnotationTypeRef(newSource)
|
||||||
|
is FirImplicitBooleanTypeRef -> FirImplicitBooleanTypeRef(newSource)
|
||||||
|
is FirImplicitIntTypeRef -> FirImplicitIntTypeRef(newSource)
|
||||||
|
is FirImplicitNothingTypeRef -> FirImplicitNothingTypeRef(newSource)
|
||||||
|
is FirImplicitNullableNothingTypeRef -> FirImplicitNullableNothingTypeRef(newSource)
|
||||||
|
is FirImplicitStringTypeRef -> FirImplicitStringTypeRef(newSource)
|
||||||
|
is FirImplicitKPropertyTypeRef -> FirImplicitKPropertyTypeRef(
|
||||||
|
newSource,
|
||||||
|
typeArgument = type.typeArguments[0]
|
||||||
|
)
|
||||||
|
is FirImplicitKProperty0TypeRef -> FirImplicitKProperty0TypeRef(
|
||||||
|
newSource,
|
||||||
|
propertyTypeArgument = type.typeArguments[0]
|
||||||
|
)
|
||||||
|
is FirImplicitKMutableProperty0TypeRef -> FirImplicitKMutableProperty0TypeRef(
|
||||||
|
newSource,
|
||||||
|
propertyTypeArgument = type.typeArguments[0]
|
||||||
|
)
|
||||||
|
is FirImplicitKProperty1TypeRef -> FirImplicitKProperty1TypeRef(
|
||||||
|
newSource,
|
||||||
|
receiverTypeArgument = type.typeArguments[0],
|
||||||
|
propertyTypeArgument = type.typeArguments[1]
|
||||||
|
)
|
||||||
|
is FirImplicitKMutableProperty1TypeRef -> FirImplicitKMutableProperty1TypeRef(
|
||||||
|
newSource,
|
||||||
|
receiverTypeArgument = type.typeArguments[0],
|
||||||
|
propertyTypeArgument = type.typeArguments[1]
|
||||||
|
)
|
||||||
|
is FirImplicitKProperty2TypeRef -> FirImplicitKProperty2TypeRef(
|
||||||
|
newSource,
|
||||||
|
dispatchReceiverTypeArgument = type.typeArguments[0],
|
||||||
|
extensionReceiverTypeArgument = type.typeArguments[1],
|
||||||
|
propertyTypeArgument = type.typeArguments[2]
|
||||||
|
)
|
||||||
|
is FirImplicitKMutableProperty2TypeRef -> FirImplicitKMutableProperty2TypeRef(
|
||||||
|
newSource,
|
||||||
|
dispatchReceiverTypeArgument = type.typeArguments[0],
|
||||||
|
extensionReceiverTypeArgument = type.typeArguments[1],
|
||||||
|
propertyTypeArgument = type.typeArguments[2]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -222,6 +222,31 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
|||||||
builder(resolvedTypeRef) {
|
builder(resolvedTypeRef) {
|
||||||
defaultFalse("isSuspend")
|
defaultFalse("isSuspend")
|
||||||
defaultNull("delegatedTypeRef")
|
defaultNull("delegatedTypeRef")
|
||||||
|
withCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
builder(errorTypeRef) {
|
||||||
|
withCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
builder(delegatedTypeRef) {
|
||||||
|
withCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
builder(functionTypeRef) {
|
||||||
|
withCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
builder(resolvedFunctionTypeRef) {
|
||||||
|
withCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
builder(implicitTypeRef) {
|
||||||
|
withCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
builder(composedSuperTypeRef) {
|
||||||
|
withCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
builder(breakExpression) {
|
builder(breakExpression) {
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -380,7 +380,9 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
kind = Object
|
kind = Object
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(resolvedTypeRef)
|
impl(resolvedTypeRef) {
|
||||||
|
publicImplementation()
|
||||||
|
}
|
||||||
|
|
||||||
impl(errorExpression) {
|
impl(errorExpression) {
|
||||||
defaultEmptyList("annotations")
|
defaultEmptyList("annotations")
|
||||||
|
|||||||
Reference in New Issue
Block a user