FIR: Initialize dispatchReceiverType and containingClassAttr for callable members
This commit is contained in:
@@ -96,7 +96,7 @@ class JavaScopeProvider(
|
||||
val scope = buildJavaEnhancementScope(useSiteSession, symbol, scopeSession, visitedSymbols)
|
||||
visitedSymbols.remove(symbol)
|
||||
useSiteSuperType.wrapSubstitutionScopeIfNeed(
|
||||
useSiteSession, scope, symbol.fir, scopeSession, regularClass.classId
|
||||
useSiteSession, scope, symbol.fir, scopeSession, derivedClass = regularClass
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -112,7 +112,7 @@ class JavaScopeProvider(
|
||||
else JavaTypeParameterStack.EMPTY
|
||||
),
|
||||
superTypeEnhancementScopes,
|
||||
regularClass.classId,
|
||||
regularClass.defaultType(),
|
||||
), wrappedDeclaredScope
|
||||
)
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.*
|
||||
import org.jetbrains.kotlin.fir.java.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.constructType
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProviderInternals
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.SymbolProviderCache
|
||||
import org.jetbrains.kotlin.fir.resolve.scopes.wrapScopeWithJvmMapped
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
@@ -187,6 +189,9 @@ class JavaSymbolProvider(
|
||||
buildOuterClassTypeParameterRef { symbol = it.symbol }
|
||||
}
|
||||
}
|
||||
|
||||
val dispatchReceiver = classId.defaultType(typeParameters.map { it.symbol } )
|
||||
|
||||
status = FirResolvedDeclarationStatusImpl(
|
||||
javaClass.visibility,
|
||||
javaClass.modality
|
||||
@@ -200,7 +205,7 @@ class JavaSymbolProvider(
|
||||
// TODO: may be we can process fields & methods later.
|
||||
// However, they should be built up to override resolve stage
|
||||
for (javaField in javaClass.fields) {
|
||||
declarations += convertJavaFieldToFir(javaField, classId, javaTypeParameterStack)
|
||||
declarations += convertJavaFieldToFir(javaField, classId, javaTypeParameterStack, dispatchReceiver)
|
||||
}
|
||||
val valueParametersForAnnotationConstructor = ValueParametersForAnnotationConstructor()
|
||||
val classIsAnnotation = classKind == ClassKind.ANNOTATION_CLASS
|
||||
@@ -212,7 +217,8 @@ class JavaSymbolProvider(
|
||||
classId,
|
||||
javaTypeParameterStack,
|
||||
classIsAnnotation,
|
||||
valueParametersForAnnotationConstructor
|
||||
valueParametersForAnnotationConstructor,
|
||||
dispatchReceiver
|
||||
)
|
||||
}
|
||||
val javaClassDeclaredConstructors = javaClass.constructors
|
||||
@@ -243,11 +249,16 @@ class JavaSymbolProvider(
|
||||
}
|
||||
|
||||
if (classKind == ClassKind.ENUM_CLASS) {
|
||||
generateValuesFunction(session, classId.packageFqName, classId.relativeClassName)
|
||||
generateValuesFunction(
|
||||
session,
|
||||
classId.packageFqName,
|
||||
classId.relativeClassName
|
||||
)
|
||||
generateValueOfFunction(session, classId.packageFqName, classId.relativeClassName)
|
||||
}
|
||||
if (classIsAnnotation) {
|
||||
declarations += buildConstructorForAnnotationClass(constructorId, this, valueParametersForAnnotationConstructor)
|
||||
declarations +=
|
||||
buildConstructorForAnnotationClass(constructorId, this, valueParametersForAnnotationConstructor)
|
||||
}
|
||||
parentClassTypeParameterStackCache.remove(classSymbol)
|
||||
}
|
||||
@@ -265,7 +276,8 @@ class JavaSymbolProvider(
|
||||
private fun convertJavaFieldToFir(
|
||||
javaField: JavaField,
|
||||
classId: ClassId,
|
||||
javaTypeParameterStack: JavaTypeParameterStack
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
dispatchReceiver: ConeClassLikeType
|
||||
): FirDeclaration {
|
||||
val fieldName = javaField.name
|
||||
val fieldId = CallableId(classId.packageFqName, classId.relativeClassName, fieldName)
|
||||
@@ -289,6 +301,8 @@ class JavaSymbolProvider(
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||
origin = FirDeclarationOrigin.Java
|
||||
addAnnotationsFrom(this@JavaSymbolProvider.session, javaField, javaTypeParameterStack)
|
||||
}.apply {
|
||||
containingClassAttr = ConeClassLikeLookupTagImpl(classId)
|
||||
}
|
||||
else -> buildJavaField {
|
||||
source = (javaField as? JavaElementImpl<*>)?.psi?.toFirPsiSourceElement()
|
||||
@@ -311,6 +325,14 @@ class JavaSymbolProvider(
|
||||
isStatic = javaField.isStatic
|
||||
addAnnotationsFrom(this@JavaSymbolProvider.session, javaField, javaTypeParameterStack)
|
||||
initializer = convertJavaInitializerToFir(javaField.initializerValue)
|
||||
|
||||
if (!javaField.isStatic) {
|
||||
dispatchReceiverType = dispatchReceiver
|
||||
}
|
||||
}.apply {
|
||||
if (javaField.isStatic) {
|
||||
containingClassAttr = ConeClassLikeLookupTagImpl(classId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,7 +347,8 @@ class JavaSymbolProvider(
|
||||
classId: ClassId,
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
classIsAnnotation: Boolean,
|
||||
valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor
|
||||
valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor,
|
||||
dispatchReceiver: ConeClassLikeType
|
||||
): FirJavaMethod {
|
||||
val methodName = javaMethod.name
|
||||
val methodId = CallableId(classId.packageFqName, classId.relativeClassName, methodName)
|
||||
@@ -364,6 +387,14 @@ class JavaSymbolProvider(
|
||||
isExternal = false
|
||||
isSuspend = false
|
||||
}
|
||||
|
||||
if (!javaMethod.isStatic) {
|
||||
dispatchReceiverType = dispatchReceiver
|
||||
}
|
||||
}.apply {
|
||||
if (javaMethod.isStatic) {
|
||||
containingClassAttr = ConeClassLikeLookupTagImpl(classId)
|
||||
}
|
||||
}
|
||||
if (classIsAnnotation) {
|
||||
val parameterForAnnotationConstructor = buildJavaValueParameter {
|
||||
@@ -425,6 +456,8 @@ class JavaSymbolProvider(
|
||||
)
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
containingClassAttr = ownerClassBuilder.symbol.toLookupTag()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,6 +478,8 @@ class JavaSymbolProvider(
|
||||
visibility = Visibilities.Public
|
||||
isInner = false
|
||||
isPrimary = true
|
||||
}.apply {
|
||||
containingClassAttr = ownerClassBuilder.symbol.toLookupTag()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -5,10 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.java.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.FirConstructorBuilder
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
@@ -37,6 +38,7 @@ class FirJavaConstructor @FirImplementationDetail constructor(
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override var status: FirDeclarationStatus,
|
||||
override var resolvePhase: FirResolvePhase,
|
||||
override val dispatchReceiverType: ConeKotlinType?,
|
||||
) : FirConstructor() {
|
||||
override val receiverTypeRef: FirTypeRef? get() = null
|
||||
|
||||
@@ -154,7 +156,8 @@ class FirJavaConstructorBuilder : FirConstructorBuilder() {
|
||||
typeParameters,
|
||||
annotations,
|
||||
status,
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES,
|
||||
dispatchReceiverType
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
package org.jetbrains.kotlin.fir.java.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.FirFieldBuilder
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFieldSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
@@ -42,6 +43,8 @@ class FirJavaField @FirImplementationDetail constructor(
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val typeParameters: MutableList<FirTypeParameter>,
|
||||
override var initializer: FirExpression?,
|
||||
override val dispatchReceiverType: ConeKotlinType?,
|
||||
override val attributes: FirDeclarationAttributes,
|
||||
) : FirField() {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
@@ -55,8 +58,6 @@ class FirJavaField @FirImplementationDetail constructor(
|
||||
override val origin: FirDeclarationOrigin
|
||||
get() = FirDeclarationOrigin.Java
|
||||
|
||||
override val attributes: FirDeclarationAttributes = FirDeclarationAttributes()
|
||||
|
||||
override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirField {
|
||||
returnTypeRef = returnTypeRef.transformSingle(transformer, data)
|
||||
return this
|
||||
@@ -163,6 +164,8 @@ internal class FirJavaFieldBuilder : FirFieldBuilder() {
|
||||
annotations,
|
||||
typeParameters,
|
||||
initializer,
|
||||
dispatchReceiverType,
|
||||
attributes,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
package org.jetbrains.kotlin.fir.java.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.contracts.impl.FirEmptyContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -53,6 +54,7 @@ class FirJavaMethod @FirImplementationDetail constructor(
|
||||
containerSource: DeserializedContainerSource?,
|
||||
symbol: FirFunctionSymbol<FirSimpleFunction>,
|
||||
annotations: MutableList<FirAnnotationCall>,
|
||||
dispatchReceiverType: ConeKotlinType?,
|
||||
) : FirSimpleFunctionImpl(
|
||||
source,
|
||||
session,
|
||||
@@ -65,6 +67,7 @@ class FirJavaMethod @FirImplementationDetail constructor(
|
||||
body,
|
||||
status,
|
||||
containerSource,
|
||||
dispatchReceiverType = dispatchReceiverType,
|
||||
contractDescription = FirEmptyContractDescription,
|
||||
name,
|
||||
symbol,
|
||||
@@ -107,6 +110,7 @@ class FirJavaMethodBuilder : FirSimpleFunctionBuilder() {
|
||||
containerSource,
|
||||
symbol,
|
||||
annotations,
|
||||
dispatchReceiverType,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+11
-1
@@ -95,14 +95,18 @@ class FirSignatureEnhancement(
|
||||
session = this@FirSignatureEnhancement.session
|
||||
this.symbol = symbol
|
||||
this.name = name
|
||||
returnTypeRef = newReturnTypeRef
|
||||
|
||||
// TODO: Use some kind of copy mechanism
|
||||
visibility = firElement.visibility
|
||||
modality = firElement.modality
|
||||
returnTypeRef = newReturnTypeRef
|
||||
isVar = firElement.isVar
|
||||
isStatic = firElement.isStatic
|
||||
annotations += firElement.annotations
|
||||
status = firElement.status
|
||||
initializer = firElement.initializer
|
||||
dispatchReceiverType = firElement.dispatchReceiverType
|
||||
attributes = firElement.attributes.copy()
|
||||
}
|
||||
return symbol
|
||||
}
|
||||
@@ -221,12 +225,16 @@ class FirSignatureEnhancement(
|
||||
isInner = firMethod.isInner
|
||||
}
|
||||
this.symbol = symbol
|
||||
dispatchReceiverType = firMethod.dispatchReceiverType
|
||||
attributes = firMethod.attributes.copy()
|
||||
}
|
||||
} else {
|
||||
FirConstructorBuilder().apply {
|
||||
returnTypeRef = newReturnTypeRef
|
||||
status = firMethod.status
|
||||
this.symbol = symbol
|
||||
dispatchReceiverType = firMethod.dispatchReceiverType
|
||||
attributes = firMethod.attributes.copy()
|
||||
}
|
||||
}.apply {
|
||||
source = firMethod.source
|
||||
@@ -250,6 +258,8 @@ class FirSignatureEnhancement(
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||
valueParameters += newValueParameters
|
||||
typeParameters += firMethod.typeParameters
|
||||
dispatchReceiverType = firMethod.dispatchReceiverType
|
||||
attributes = firMethod.attributes.copy()
|
||||
}
|
||||
}
|
||||
else -> throw AssertionError("Unknown Java method to enhance: ${firMethod.render()}")
|
||||
|
||||
+2
-1
@@ -104,7 +104,8 @@ class JavaClassMembersEnhancementScope(
|
||||
FirDeclarationOrigin.Enhancement,
|
||||
newParameterTypes = valueParameters.zip(newParameterTypes).map { (valueParameter, newType) ->
|
||||
newType ?: valueParameter.returnTypeRef.coneType
|
||||
}
|
||||
},
|
||||
newDispatchReceiverType = dispatchReceiverType,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user