[FIR2IR] Add static functions to Fir2IrLazyClass.declarations
^KT-55269
This commit is contained in:
committed by
Space Team
parent
5d6cb2b691
commit
866150a2e0
@@ -13,9 +13,11 @@ import org.jetbrains.kotlin.fir.declarations.utils.*
|
|||||||
import org.jetbrains.kotlin.fir.dispatchReceiverClassLookupTagOrNull
|
import org.jetbrains.kotlin.fir.dispatchReceiverClassLookupTagOrNull
|
||||||
import org.jetbrains.kotlin.fir.isNewPlaceForBodyGeneration
|
import org.jetbrains.kotlin.fir.isNewPlaceForBodyGeneration
|
||||||
import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
|
import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
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.fir.symbols.impl.isStatic
|
||||||
import org.jetbrains.kotlin.fir.types.isNullableAny
|
import org.jetbrains.kotlin.fir.types.isNullableAny
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -164,55 +166,44 @@ class Fir2IrLazyClass(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle generated methods for enum classes (values(), valueOf(String)).
|
|
||||||
if (fir.classKind == ClassKind.ENUM_CLASS) {
|
if (fir.classKind == ClassKind.ENUM_CLASS) {
|
||||||
for (declaration in fir.declarations) {
|
for (declaration in fir.declarations) {
|
||||||
if (declaration !is FirCallableDeclaration || !declaration.isStatic || !shouldBuildStub(declaration)) continue
|
if (declaration is FirEnumEntry && shouldBuildStub(declaration)) {
|
||||||
|
result += declarationStorage.getIrValueSymbol(declaration.symbol).owner as IrDeclaration
|
||||||
when (declaration) {
|
|
||||||
is FirSimpleFunction -> {
|
|
||||||
// TODO we also come here for all deserialized / enhanced static enum members (with declaration.source == null).
|
|
||||||
// For such members we currently can't tell whether they are compiler-generated methods or not.
|
|
||||||
// Note: we must drop declarations from Java here to avoid FirJavaTypeRefs inside
|
|
||||||
if (declaration.source == null && declaration.origin !is FirDeclarationOrigin.Java ||
|
|
||||||
declaration.source?.kind == KtFakeSourceElementKind.EnumGeneratedDeclaration
|
|
||||||
) {
|
|
||||||
result += declarationStorage.getIrFunctionSymbol(declaration.symbol, forceTopLevelPrivate = isTopLevelPrivate).owner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is FirEnumEntry -> {
|
|
||||||
result += declarationStorage.getIrValueSymbol(declaration.symbol).owner as IrDeclaration
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val ownerLookupTag = fir.symbol.toLookupTag()
|
val ownerLookupTag = fir.symbol.toLookupTag()
|
||||||
for (name in scope.getCallableNames()) {
|
|
||||||
scope.processFunctionsByName(name) {
|
fun addDeclarationsFromScope(scope: FirContainingNamesAwareScope?) {
|
||||||
if (it.isSubstitutionOrIntersectionOverride) return@processFunctionsByName
|
if (scope == null) return
|
||||||
if (!shouldBuildStub(it.fir)) return@processFunctionsByName
|
for (name in scope.getCallableNames()) {
|
||||||
if (it.dispatchReceiverClassLookupTagOrNull() == ownerLookupTag) {
|
scope.processFunctionsByName(name) {
|
||||||
if (it.isAbstractMethodOfAny()) {
|
if (it.isSubstitutionOrIntersectionOverride) return@processFunctionsByName
|
||||||
return@processFunctionsByName
|
if (!shouldBuildStub(it.fir)) return@processFunctionsByName
|
||||||
|
if (it.isStatic || it.dispatchReceiverClassLookupTagOrNull() == ownerLookupTag) {
|
||||||
|
if (it.isAbstractMethodOfAny()) {
|
||||||
|
return@processFunctionsByName
|
||||||
|
}
|
||||||
|
result += declarationStorage.getIrFunctionSymbol(it, forceTopLevelPrivate = isTopLevelPrivate).owner
|
||||||
}
|
}
|
||||||
result += declarationStorage.getIrFunctionSymbol(it, forceTopLevelPrivate = isTopLevelPrivate).owner
|
|
||||||
}
|
}
|
||||||
}
|
scope.processPropertiesByName(name) {
|
||||||
scope.processPropertiesByName(name) {
|
if (it.isSubstitutionOrIntersectionOverride) return@processPropertiesByName
|
||||||
if (it.isSubstitutionOrIntersectionOverride) return@processPropertiesByName
|
if (!shouldBuildStub(it.fir)) return@processPropertiesByName
|
||||||
if (!shouldBuildStub(it.fir)) return@processPropertiesByName
|
if (it is FirPropertySymbol && (it.isStatic || it.dispatchReceiverClassLookupTagOrNull() == ownerLookupTag)) {
|
||||||
if (it is FirPropertySymbol && it.dispatchReceiverClassLookupTagOrNull() == ownerLookupTag) {
|
result.addIfNotNull(
|
||||||
result.addIfNotNull(
|
declarationStorage.getIrPropertySymbol(it, forceTopLevelPrivate = isTopLevelPrivate).owner as? IrDeclaration
|
||||||
declarationStorage.getIrPropertySymbol(it, forceTopLevelPrivate = isTopLevelPrivate).owner as? IrDeclaration
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addDeclarationsFromScope(scope)
|
||||||
|
addDeclarationsFromScope(fir.staticScope(session, scopeSession))
|
||||||
|
|
||||||
with(classifierStorage) {
|
with(classifierStorage) {
|
||||||
result.addAll(this@Fir2IrLazyClass.createContextReceiverFields(fir))
|
result.addAll(this@Fir2IrLazyClass.createContextReceiverFields(fir))
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -8,9 +8,11 @@ package org.jetbrains.kotlin.fir.declarations
|
|||||||
import kotlinx.collections.immutable.PersistentList
|
import kotlinx.collections.immutable.PersistentList
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import kotlinx.collections.immutable.toPersistentList
|
import kotlinx.collections.immutable.toPersistentList
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.labelName
|
import org.jetbrains.kotlin.fir.labelName
|
||||||
import org.jetbrains.kotlin.fir.resolve.*
|
import org.jetbrains.kotlin.fir.resolve.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.*
|
import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstitutionForSuperType
|
import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstitutionForSuperType
|
||||||
@@ -240,8 +242,11 @@ fun ContextReceiverGroup.asTowerDataElement(): FirTowerDataElement =
|
|||||||
fun FirScope.asTowerDataElement(isLocal: Boolean): FirTowerDataElement =
|
fun FirScope.asTowerDataElement(isLocal: Boolean): FirTowerDataElement =
|
||||||
FirTowerDataElement(scope = this, implicitReceiver = null, isLocal = isLocal)
|
FirTowerDataElement(scope = this, implicitReceiver = null, isLocal = isLocal)
|
||||||
|
|
||||||
fun FirClass.staticScope(sessionHolder: SessionHolder) =
|
fun FirClass.staticScope(sessionHolder: SessionHolder): FirContainingNamesAwareScope? =
|
||||||
scopeProvider.getStaticScope(this, sessionHolder.session, sessionHolder.scopeSession)
|
staticScope(sessionHolder.session, sessionHolder.scopeSession)
|
||||||
|
|
||||||
|
fun FirClass.staticScope(session: FirSession, scopeSession: ScopeSession): FirContainingNamesAwareScope? =
|
||||||
|
scopeProvider.getStaticScope(this, session, scopeSession)
|
||||||
|
|
||||||
typealias ContextReceiverGroup = List<ContextReceiverValue<*>>
|
typealias ContextReceiverGroup = List<ContextReceiverValue<*>>
|
||||||
typealias FirLocalScopes = PersistentList<FirLocalScope>
|
typealias FirLocalScopes = PersistentList<FirLocalScope>
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB ENUM_CLASS name:JEnum modality:FINAL vis
|
|||||||
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:values visibility:public modality:FINAL <> () returnType:kotlin.Array<<root>.JEnum>
|
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:values visibility:public modality:FINAL <> () returnType:kotlin.Array<<root>.JEnum>
|
||||||
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:<root>.JEnum
|
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:<root>.JEnum
|
||||||
VALUE_PARAMETER name:value index:0 type:kotlin.String
|
VALUE_PARAMETER name:value index:0 type:kotlin.String
|
||||||
|
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:entries visibility:public modality:FINAL [val]
|
||||||
|
FIELD PROPERTY_BACKING_FIELD name:entries type:kotlin.enums.EnumEntries visibility:public [final,static]
|
||||||
|
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-entries> visibility:public modality:FINAL <> () returnType:kotlin.enums.EnumEntries
|
||||||
|
correspondingProperty: PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:entries visibility:public modality:FINAL [val]
|
||||||
FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:<root>.JEnum) returnType:kotlin.Any [fake_override]
|
FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:<root>.JEnum) returnType:kotlin.Any [fake_override]
|
||||||
overridden:
|
overridden:
|
||||||
protected final fun clone (): kotlin.Any declared in kotlin.Enum
|
protected final fun clone (): kotlin.Any declared in kotlin.Enum
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:J modality:OPEN visibility:public superTypes:[kotlin.Any]
|
CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:J modality:OPEN visibility:public superTypes:[kotlin.Any]
|
||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.J
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.J
|
||||||
CONSTRUCTOR IR_EXTERNAL_JAVA_DECLARATION_STUB visibility:public <> () returnType:<root>.J [primary]
|
CONSTRUCTOR IR_EXTERNAL_JAVA_DECLARATION_STUB visibility:public <> () returnType:<root>.J [primary]
|
||||||
|
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:bar visibility:public modality:OPEN <> () returnType:kotlin.Unit
|
||||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:<root>.J, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:<root>.J, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||||
overridden:
|
overridden:
|
||||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||||
|
|||||||
Reference in New Issue
Block a user