[FIR] Move FirNestedClassifierScopeWithSubstitution to separate file
This commit is contained in:
+6
-23
@@ -6,7 +6,10 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.getNestedClassifierScope
|
||||
@@ -15,14 +18,10 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.FirCompositeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirNestedClassifierScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.nestedClassifierScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class FirAbstractTreeTransformerWithSuperTypes(
|
||||
phase: FirResolvePhase
|
||||
@@ -56,12 +55,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(
|
||||
).asReversed()
|
||||
for (superType in superTypes) {
|
||||
session.getNestedClassifierScope(superType.lookupTag)?.let { nestedClassifierScope ->
|
||||
val scope = if (nestedClassifierScope is FirNestedClassifierScope) {
|
||||
val substitutor = createSubstitutionForSupertype(superType, session)
|
||||
FirNestedClassifierScopeWithSubstitution(nestedClassifierScope, substitutor)
|
||||
} else {
|
||||
nestedClassifierScope
|
||||
}
|
||||
val scope = nestedClassifierScope.wrapNestedClassifierScopeWithSubstitutionForSuperType(superType, session)
|
||||
scopes.add(scope)
|
||||
}
|
||||
}
|
||||
@@ -86,17 +80,6 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(
|
||||
}
|
||||
}
|
||||
|
||||
private class FirNestedClassifierScopeWithSubstitution(
|
||||
private val scope: FirNestedClassifierScope,
|
||||
private val substitutor: ConeSubstitutor
|
||||
) : FirScope() {
|
||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||
val matchedClass = scope.getClassifierByName(name) ?: return
|
||||
val substitutor = substitutor.takeIf { matchedClass.fir.isInner } ?: ConeSubstitutor.Empty
|
||||
processor(matchedClass, substitutor)
|
||||
}
|
||||
}
|
||||
|
||||
fun createSubstitutionForSupertype(superType: ConeLookupTagBasedType, session: FirSession): ConeSubstitutor {
|
||||
val klass = superType.lookupTag.toSymbol(session)?.fir as? FirRegularClass ?: return ConeSubstitutor.Empty
|
||||
val mapping = klass.typeParameters.map { it.symbol }.zip(superType.typeArguments.map { it as ConeKotlinType }).toMap()
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.isInner
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.createSubstitutionForSupertype
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirNestedClassifierScopeWithSubstitution(
|
||||
private val scope: FirNestedClassifierScope,
|
||||
private val substitutor: ConeSubstitutor
|
||||
) : FirScope() {
|
||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||
val matchedClass = scope.getClassifierByName(name) ?: return
|
||||
val substitutor = substitutor.takeIf { matchedClass.fir.isInner } ?: ConeSubstitutor.Empty
|
||||
processor(matchedClass, substitutor)
|
||||
}
|
||||
}
|
||||
|
||||
fun FirScope.wrapNestedClassifierScopeWithSubstitutionForSuperType(
|
||||
superType: ConeClassLikeType,
|
||||
session: FirSession
|
||||
): FirScope = if (this is FirNestedClassifierScope) {
|
||||
val substitutor = createSubstitutionForSupertype(superType, session)
|
||||
FirNestedClassifierScopeWithSubstitution(this, substitutor)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
Reference in New Issue
Block a user