FIR scopes: createSuspendView -> more abstract replaceWithWrapperSymbolIfNeeded

Related to KT-59818
This commit is contained in:
Mikhail Glukhikh
2023-12-21 11:35:49 +01:00
committed by Space Team
parent 1ebf0f5376
commit d1edbe0c4b
2 changed files with 14 additions and 12 deletions
@@ -333,26 +333,27 @@ class JavaClassUseSiteMemberScope(
} }
} }
override fun FirNamedFunctionSymbol.createSuspendView(): FirSimpleFunction? { override fun FirNamedFunctionSymbol.replaceWithWrapperSymbolIfNeeded(): FirNamedFunctionSymbol {
val continuationParameter = fir.valueParameters.lastOrNull() ?: return null if (!isJavaOrEnhancement) return this
val owner = ownerClassLookupTag.toSymbol(session)?.fir as? FirJavaClass ?: return null val continuationParameter = fir.valueParameters.lastOrNull() ?: return this
val owner = ownerClassLookupTag.toSymbol(session)?.fir as? FirJavaClass ?: return this
val continuationParameterType = continuationParameter val continuationParameterType = continuationParameter
.returnTypeRef .returnTypeRef
.resolveIfJavaType(session, owner.javaTypeParameterStack) .resolveIfJavaType(session, owner.javaTypeParameterStack)
.coneTypeSafe<ConeKotlinType>() .coneTypeSafe<ConeKotlinType>()
?.lowerBoundIfFlexible() as? ConeClassLikeType ?.lowerBoundIfFlexible() as? ConeClassLikeType
?: return null ?: return this
if (continuationParameterType.lookupTag.classId.asSingleFqName() != StandardNames.CONTINUATION_INTERFACE_FQ_NAME) return null if (continuationParameterType.lookupTag.classId.asSingleFqName() != StandardNames.CONTINUATION_INTERFACE_FQ_NAME) return this
return buildSimpleFunctionCopy(fir) { return buildSimpleFunctionCopy(fir) {
valueParameters.clear() valueParameters.clear()
valueParameters.addAll(fir.valueParameters.dropLast(1)) valueParameters.addAll(fir.valueParameters.dropLast(1))
returnTypeRef = buildResolvedTypeRef { returnTypeRef = buildResolvedTypeRef {
type = continuationParameterType.typeArguments[0].type ?: return null type = continuationParameterType.typeArguments[0].type ?: return this@replaceWithWrapperSymbolIfNeeded
} }
(status as FirDeclarationStatusImpl).isSuspend = true (status as FirDeclarationStatusImpl).isSuspend = true
symbol = FirNamedFunctionSymbol(callableId) symbol = FirNamedFunctionSymbol(callableId)
} }.symbol
} }
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
@@ -6,8 +6,6 @@
package org.jetbrains.kotlin.fir.scopes.impl package org.jetbrains.kotlin.fir.scopes.impl
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import org.jetbrains.kotlin.fir.declarations.isJavaOrEnhancement
import org.jetbrains.kotlin.fir.declarations.utils.isStatic import org.jetbrains.kotlin.fir.declarations.utils.isStatic
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.scopes.* import org.jetbrains.kotlin.fir.scopes.*
@@ -77,7 +75,7 @@ abstract class AbstractFirUseSiteMemberScope(
if (!symbol.isVisibleInCurrentClass()) return@processFunctionsByName if (!symbol.isVisibleInCurrentClass()) return@processFunctionsByName
val directOverridden = computeDirectOverriddenForDeclaredFunction(symbol) val directOverridden = computeDirectOverriddenForDeclaredFunction(symbol)
directOverriddenFunctions[symbol] = directOverridden directOverriddenFunctions[symbol] = directOverridden
destination += (symbol.takeIf { it.isJavaOrEnhancement }?.createSuspendView()?.symbol ?: symbol) destination += symbol.replaceWithWrapperSymbolIfNeeded()
} }
} }
@@ -219,7 +217,10 @@ abstract class AbstractFirUseSiteMemberScope(
return classifierNamesCached return classifierNamesCached
} }
protected open fun FirNamedFunctionSymbol.createSuspendView(): FirSimpleFunction? { /**
return null * This function is currently used only for creating suspend views in Java.
*/
protected open fun FirNamedFunctionSymbol.replaceWithWrapperSymbolIfNeeded(): FirNamedFunctionSymbol {
return this
} }
} }