[FIR] Code cleanup: get rid of FirClass.buildUseSiteMemberScope()
This commit is contained in:
+29
-33
@@ -15,50 +15,46 @@ import org.jetbrains.kotlin.fir.java.declarations.FirJavaConstructor
|
|||||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
|
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
|
||||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
|
import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.buildUseSiteMemberScope
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
|
|
||||||
fun renderJavaClass(renderer: FirRenderer, javaClass: FirJavaClass, session: FirSession) {
|
fun renderJavaClass(renderer: FirRenderer, javaClass: FirJavaClass, session: FirSession) {
|
||||||
val memberScope = javaClass.buildUseSiteMemberScope(session, ScopeSession())
|
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession())
|
||||||
|
|
||||||
val staticScope = javaClass.scopeProvider.getStaticScope(javaClass, session, ScopeSession())
|
val staticScope = javaClass.scopeProvider.getStaticScope(javaClass, session, ScopeSession())
|
||||||
|
|
||||||
if (memberScope == null && staticScope == null) {
|
renderer.visitMemberDeclaration(javaClass)
|
||||||
javaClass.accept(renderer, null)
|
renderer.renderSupertypes(javaClass)
|
||||||
} else {
|
renderer.renderInBraces {
|
||||||
renderer.visitMemberDeclaration(javaClass)
|
val renderedDeclarations = mutableListOf<FirDeclaration>()
|
||||||
renderer.renderSupertypes(javaClass)
|
|
||||||
renderer.renderInBraces {
|
|
||||||
val renderedDeclarations = mutableListOf<FirDeclaration>()
|
|
||||||
|
|
||||||
fun renderAndCache(symbol: FirCallableSymbol<*>) {
|
fun renderAndCache(symbol: FirCallableSymbol<*>) {
|
||||||
val enhanced = symbol.fir
|
val enhanced = symbol.fir
|
||||||
if (enhanced !in renderedDeclarations) {
|
if (enhanced !in renderedDeclarations) {
|
||||||
enhanced.accept(renderer, null)
|
enhanced.accept(renderer, null)
|
||||||
renderer.newLine()
|
renderer.newLine()
|
||||||
renderedDeclarations += enhanced
|
renderedDeclarations += enhanced
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (declaration in javaClass.declarations) {
|
for (declaration in javaClass.declarations) {
|
||||||
if (declaration in renderedDeclarations) continue
|
if (declaration in renderedDeclarations) continue
|
||||||
|
|
||||||
val scopeToUse =
|
val scopeToUse =
|
||||||
if (declaration is FirCallableMemberDeclaration<*> && declaration.status.isStatic)
|
if (declaration is FirCallableMemberDeclaration<*> && declaration.status.isStatic)
|
||||||
staticScope
|
staticScope
|
||||||
else
|
else
|
||||||
memberScope
|
memberScope
|
||||||
|
|
||||||
when (declaration) {
|
when (declaration) {
|
||||||
is FirJavaConstructor -> scopeToUse!!.processDeclaredConstructors(::renderAndCache)
|
is FirJavaConstructor -> scopeToUse!!.processDeclaredConstructors(::renderAndCache)
|
||||||
is FirJavaMethod -> scopeToUse!!.processFunctionsByName(declaration.name, ::renderAndCache)
|
is FirJavaMethod -> scopeToUse!!.processFunctionsByName(declaration.name, ::renderAndCache)
|
||||||
is FirJavaField -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
is FirJavaField -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
||||||
is FirEnumEntry -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
is FirEnumEntry -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
||||||
else -> {
|
else -> {
|
||||||
declaration.accept(renderer, null)
|
declaration.accept(renderer, null)
|
||||||
renderer.newLine()
|
renderer.newLine()
|
||||||
renderedDeclarations += declaration
|
renderedDeclarations += declaration
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -18,11 +18,11 @@ import org.jetbrains.kotlin.fir.references.FirReference
|
|||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||||
import org.jetbrains.kotlin.fir.render
|
import org.jetbrains.kotlin.fir.render
|
||||||
import org.jetbrains.kotlin.fir.resolve.buildUseSiteMemberScope
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.isFunctional
|
import org.jetbrains.kotlin.fir.resolve.calls.isFunctional
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType
|
import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
|
import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||||
@@ -433,7 +433,7 @@ class CallAndReferenceGenerator(
|
|||||||
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
||||||
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass<*>
|
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass<*>
|
||||||
var constructorSymbol: FirConstructorSymbol? = null
|
var constructorSymbol: FirConstructorSymbol? = null
|
||||||
fir?.buildUseSiteMemberScope(session, scopeSession)?.processDeclaredConstructors {
|
fir?.unsubstitutedScope(session, scopeSession)?.processDeclaredConstructors {
|
||||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||||
constructorSymbol = it
|
constructorSymbol = it
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -10,8 +10,8 @@ import org.jetbrains.kotlin.fir.backend.*
|
|||||||
import org.jetbrains.kotlin.fir.backend.collectCallableNamesFromSupertypes
|
import org.jetbrains.kotlin.fir.backend.collectCallableNamesFromSupertypes
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.buildUseSiteMemberScope
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -63,7 +63,7 @@ class FakeOverrideGenerator(
|
|||||||
val result = mutableListOf<IrDeclaration>()
|
val result = mutableListOf<IrDeclaration>()
|
||||||
if (fakeOverrideMode == FakeOverrideMode.NONE) return emptyList()
|
if (fakeOverrideMode == FakeOverrideMode.NONE) return emptyList()
|
||||||
val superTypesCallableNames = klass.collectCallableNamesFromSupertypes(session)
|
val superTypesCallableNames = klass.collectCallableNamesFromSupertypes(session)
|
||||||
val useSiteMemberScope = klass.buildUseSiteMemberScope(session, scopeSession) ?: return emptyList()
|
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession)
|
||||||
for (name in superTypesCallableNames) {
|
for (name in superTypesCallableNames) {
|
||||||
if (name in processedCallableNames) continue
|
if (name in processedCallableNames) continue
|
||||||
processedCallableNames += name
|
processedCallableNames += name
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
|||||||
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
||||||
import org.jetbrains.kotlin.fir.backend.toIrType
|
import org.jetbrains.kotlin.fir.backend.toIrType
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.buildUseSiteMemberScope
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
@@ -119,7 +119,7 @@ class Fir2IrLazyClass(
|
|||||||
val processedNames = mutableSetOf<Name>()
|
val processedNames = mutableSetOf<Name>()
|
||||||
// NB: it's necessary to take all callables from scope,
|
// NB: it's necessary to take all callables from scope,
|
||||||
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
|
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
|
||||||
val scope = fir.buildUseSiteMemberScope(session, scopeSession)!!
|
val scope = fir.unsubstitutedScope(session, scopeSession)
|
||||||
scope.processDeclaredConstructors {
|
scope.processDeclaredConstructors {
|
||||||
result += declarationStorage.getIrConstructorSymbol(it).owner
|
result += declarationStorage.getIrConstructorSymbol(it).owner
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.StoreReceiver
|
|||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.phasedFir
|
import org.jetbrains.kotlin.fir.resolve.transformers.phasedFir
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
@@ -360,7 +361,7 @@ class FirCallResolver(
|
|||||||
callInfo: CallInfo
|
callInfo: CallInfo
|
||||||
): ResolutionResult? {
|
): ResolutionResult? {
|
||||||
var constructorSymbol: FirConstructorSymbol? = null
|
var constructorSymbol: FirConstructorSymbol? = null
|
||||||
annotationClassSymbol.fir.buildUseSiteMemberScope(session, scopeSession)?.processDeclaredConstructors {
|
annotationClassSymbol.fir.unsubstitutedScope(session, scopeSession).processDeclaredConstructors {
|
||||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||||
constructorSymbol = it
|
constructorSymbol = it
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.fir.typeContext
|
|||||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -62,10 +61,6 @@ val USE_SITE = scopeSessionKey<FirClassSymbol<*>, FirTypeScope>()
|
|||||||
|
|
||||||
data class SubstitutionScopeKey(val type: ConeClassLikeType) : ScopeSessionKey<FirClassLikeSymbol<*>, FirClassSubstitutionScope>()
|
data class SubstitutionScopeKey(val type: ConeClassLikeType) : ScopeSessionKey<FirClassLikeSymbol<*>, FirClassSubstitutionScope>()
|
||||||
|
|
||||||
fun FirClass<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: ScopeSession): FirScope? {
|
|
||||||
return this.unsubstitutedScope(useSiteSession, builder)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO REMOVE */
|
/* TODO REMOVE */
|
||||||
fun createSubstitution(
|
fun createSubstitution(
|
||||||
typeParameters: List<FirTypeParameterRef>, // TODO: or really declared?
|
typeParameters: List<FirTypeParameterRef>, // TODO: or really declared?
|
||||||
|
|||||||
Reference in New Issue
Block a user