[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.FirJavaMethod
|
||||
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
|
||||
|
||||
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())
|
||||
|
||||
if (memberScope == null && staticScope == null) {
|
||||
javaClass.accept(renderer, null)
|
||||
} else {
|
||||
renderer.visitMemberDeclaration(javaClass)
|
||||
renderer.renderSupertypes(javaClass)
|
||||
renderer.renderInBraces {
|
||||
val renderedDeclarations = mutableListOf<FirDeclaration>()
|
||||
renderer.visitMemberDeclaration(javaClass)
|
||||
renderer.renderSupertypes(javaClass)
|
||||
renderer.renderInBraces {
|
||||
val renderedDeclarations = mutableListOf<FirDeclaration>()
|
||||
|
||||
fun renderAndCache(symbol: FirCallableSymbol<*>) {
|
||||
val enhanced = symbol.fir
|
||||
if (enhanced !in renderedDeclarations) {
|
||||
enhanced.accept(renderer, null)
|
||||
renderer.newLine()
|
||||
renderedDeclarations += enhanced
|
||||
}
|
||||
fun renderAndCache(symbol: FirCallableSymbol<*>) {
|
||||
val enhanced = symbol.fir
|
||||
if (enhanced !in renderedDeclarations) {
|
||||
enhanced.accept(renderer, null)
|
||||
renderer.newLine()
|
||||
renderedDeclarations += enhanced
|
||||
}
|
||||
}
|
||||
|
||||
for (declaration in javaClass.declarations) {
|
||||
if (declaration in renderedDeclarations) continue
|
||||
for (declaration in javaClass.declarations) {
|
||||
if (declaration in renderedDeclarations) continue
|
||||
|
||||
val scopeToUse =
|
||||
if (declaration is FirCallableMemberDeclaration<*> && declaration.status.isStatic)
|
||||
staticScope
|
||||
else
|
||||
memberScope
|
||||
val scopeToUse =
|
||||
if (declaration is FirCallableMemberDeclaration<*> && declaration.status.isStatic)
|
||||
staticScope
|
||||
else
|
||||
memberScope
|
||||
|
||||
when (declaration) {
|
||||
is FirJavaConstructor -> scopeToUse!!.processDeclaredConstructors(::renderAndCache)
|
||||
is FirJavaMethod -> scopeToUse!!.processFunctionsByName(declaration.name, ::renderAndCache)
|
||||
is FirJavaField -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
||||
is FirEnumEntry -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
||||
else -> {
|
||||
declaration.accept(renderer, null)
|
||||
renderer.newLine()
|
||||
renderedDeclarations += declaration
|
||||
}
|
||||
when (declaration) {
|
||||
is FirJavaConstructor -> scopeToUse!!.processDeclaredConstructors(::renderAndCache)
|
||||
is FirJavaMethod -> scopeToUse!!.processFunctionsByName(declaration.name, ::renderAndCache)
|
||||
is FirJavaField -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
||||
is FirEnumEntry -> scopeToUse!!.processPropertiesByName(declaration.name, ::renderAndCache)
|
||||
else -> {
|
||||
declaration.accept(renderer, null)
|
||||
renderer.newLine()
|
||||
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.FirSuperReference
|
||||
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.inference.isBuiltinFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
|
||||
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.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
@@ -433,7 +433,7 @@ class CallAndReferenceGenerator(
|
||||
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
||||
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass<*>
|
||||
var constructorSymbol: FirConstructorSymbol? = null
|
||||
fir?.buildUseSiteMemberScope(session, scopeSession)?.processDeclaredConstructors {
|
||||
fir?.unsubstitutedScope(session, scopeSession)?.processDeclaredConstructors {
|
||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||
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.declarations.*
|
||||
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.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -63,7 +63,7 @@ class FakeOverrideGenerator(
|
||||
val result = mutableListOf<IrDeclaration>()
|
||||
if (fakeOverrideMode == FakeOverrideMode.NONE) return emptyList()
|
||||
val superTypesCallableNames = klass.collectCallableNamesFromSupertypes(session)
|
||||
val useSiteMemberScope = klass.buildUseSiteMemberScope(session, scopeSession) ?: return emptyList()
|
||||
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession)
|
||||
for (name in superTypesCallableNames) {
|
||||
if (name in processedCallableNames) continue
|
||||
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.toIrType
|
||||
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.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
@@ -119,7 +119,7 @@ class Fir2IrLazyClass(
|
||||
val processedNames = mutableSetOf<Name>()
|
||||
// NB: it's necessary to take all callables from scope,
|
||||
// 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 {
|
||||
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.resultType
|
||||
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.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
@@ -360,7 +361,7 @@ class FirCallResolver(
|
||||
callInfo: CallInfo
|
||||
): ResolutionResult? {
|
||||
var constructorSymbol: FirConstructorSymbol? = null
|
||||
annotationClassSymbol.fir.buildUseSiteMemberScope(session, scopeSession)?.processDeclaredConstructors {
|
||||
annotationClassSymbol.fir.unsubstitutedScope(session, scopeSession).processDeclaredConstructors {
|
||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||
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.FirScope
|
||||
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.types.*
|
||||
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>()
|
||||
|
||||
fun FirClass<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: ScopeSession): FirScope? {
|
||||
return this.unsubstitutedScope(useSiteSession, builder)
|
||||
}
|
||||
|
||||
/* TODO REMOVE */
|
||||
fun createSubstitution(
|
||||
typeParameters: List<FirTypeParameterRef>, // TODO: or really declared?
|
||||
|
||||
Reference in New Issue
Block a user