FIR: simplify type parameter scopes
This commit is contained in:
+3
-4
@@ -67,7 +67,7 @@ class FirTypeResolveTransformer(val superTypesOnly: Boolean = false) : FirTransf
|
||||
classLikeName = classLikeName.child(klass.name)
|
||||
val classId = ClassId(packageFqName, classLikeName, false)
|
||||
scope = FirCompositeScope(mutableListOf(scope))
|
||||
scope.scopes += FirClassLikeTypeParameterScope(classId, klass.session)
|
||||
scope.scopes += FirClassLikeTypeParameterScope(klass)
|
||||
resolveSuperTypesAndExpansions(klass)
|
||||
|
||||
scope.scopes += FirNestedClassifierScope(classId, klass.session)
|
||||
@@ -82,9 +82,8 @@ class FirTypeResolveTransformer(val superTypesOnly: Boolean = false) : FirTransf
|
||||
|
||||
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||
classLikeName = classLikeName.child(typeAlias.name)
|
||||
val classId = ClassId(packageFqName, classLikeName, false)
|
||||
scope = FirCompositeScope(mutableListOf(scope))
|
||||
scope.scopes += FirClassLikeTypeParameterScope(classId, typeAlias.session)
|
||||
scope.scopes += FirClassLikeTypeParameterScope(typeAlias)
|
||||
|
||||
resolveSuperTypesAndExpansions(typeAlias)
|
||||
|
||||
@@ -95,7 +94,7 @@ class FirTypeResolveTransformer(val superTypesOnly: Boolean = false) : FirTransf
|
||||
|
||||
override fun transformNamedFunction(namedFunction: FirNamedFunction, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||
scope = FirCompositeScope(mutableListOf(scope))
|
||||
scope.scopes += FirFunctionTypeParameterScope(file, classLikeName, namedFunction.name, namedFunction.session)
|
||||
scope.scopes += FirFunctionTypeParameterScope(namedFunction)
|
||||
|
||||
val result = super.transformNamedFunction(namedFunction, data)
|
||||
scope = scope.scopes[0] as FirCompositeScope
|
||||
|
||||
+3
-7
@@ -5,18 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirClassLikeTypeParameterScope(val classId: ClassId, val session: FirSession) : FirScope {
|
||||
class FirClassLikeTypeParameterScope(classLike: FirMemberDeclaration) : FirScope {
|
||||
|
||||
private val firProvider = FirProvider.getInstance(session)
|
||||
|
||||
val typeParameters = firProvider.getFirClassifierByFqName(classId)?.typeParameters.orEmpty().groupBy { it.name }
|
||||
val typeParameters = classLike.typeParameters.groupBy { it.name }
|
||||
|
||||
override fun processClassifiersByName(name: Name, processor: (ConeSymbol) -> Boolean): Boolean {
|
||||
val matchedTypeParameters = typeParameters[name] ?: return true
|
||||
|
||||
+2
-20
@@ -5,32 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationContainer
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirNamedFunction
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirFunctionTypeParameterScope(
|
||||
val file: FirFile,
|
||||
val className: FqName,
|
||||
val functionName: Name,
|
||||
val session: FirSession
|
||||
) : FirScope {
|
||||
class FirFunctionTypeParameterScope(function: FirNamedFunction) : FirScope {
|
||||
|
||||
private val firProvider = FirProvider.getInstance(session)
|
||||
|
||||
val typeParameterContainer = when {
|
||||
className.isRoot -> file
|
||||
else -> firProvider.getFirClassifierByFqName(ClassId(file.packageFqName, className, false)) as? FirDeclarationContainer
|
||||
}?.declarations?.filterIsInstance<FirNamedFunction>()?.find { it.name == functionName }
|
||||
|
||||
val typeParameters = typeParameterContainer?.typeParameters.orEmpty().groupBy { it.name }
|
||||
val typeParameters = function.typeParameters.groupBy { it.name }
|
||||
|
||||
override fun processClassifiersByName(name: Name, processor: (ConeSymbol) -> Boolean): Boolean {
|
||||
val matchedTypeParameters = typeParameters[name] ?: return true
|
||||
|
||||
Reference in New Issue
Block a user