IR: minor, make IrClass.companionObject return IrClass
This commit is contained in:
+2
-2
@@ -16,9 +16,9 @@ import org.jetbrains.kotlin.backend.jvm.intrinsics.receiverAndArgs
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.IrInlineReferenceLocator
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.hasMangledParameters
|
||||
import org.jetbrains.kotlin.codegen.syntheticAccessorToSuperSuffix
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
||||
@@ -242,7 +242,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
private fun IrDeclarationWithVisibility.accessorParent(parent: IrDeclarationParent = this.parent) =
|
||||
if (visibility == JavaDescriptorVisibilities.PROTECTED_STATIC_VISIBILITY) {
|
||||
val classes = allScopes.map { it.irElement }.filterIsInstance<IrClass>()
|
||||
val companions = classes.mapNotNull { it.companionObject() }.filterIsInstance<IrClass>()
|
||||
val companions = classes.mapNotNull(IrClass::companionObject)
|
||||
val objectsInScope =
|
||||
classes.flatMap { it.declarations.filter(IrDeclaration::isAnonymousObject).filterIsInstance<IrClass>() }
|
||||
val candidates = objectsInScope + companions + classes
|
||||
|
||||
@@ -100,7 +100,8 @@ val IrDeclaration.fileEntry: SourceManager.FileEntry
|
||||
}
|
||||
}
|
||||
|
||||
fun IrClass.companionObject() = this.declarations.singleOrNull {it is IrClass && it.isCompanion }
|
||||
fun IrClass.companionObject(): IrClass? =
|
||||
this.declarations.singleOrNull { it is IrClass && it.isCompanion } as IrClass?
|
||||
|
||||
val IrDeclaration.isGetter get() = this is IrSimpleFunction && this == this.correspondingPropertySymbol?.owner?.getter
|
||||
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ class IrEfficientParcelableParcelSerializer(private val irClass: IrClass) : IrPa
|
||||
val creator: IrExpression = irClass.fields.find { it.name == CREATOR_NAME }?.let { creatorField ->
|
||||
irGetField(null, creatorField)
|
||||
} ?: irCall(irClass.creatorGetter!!).apply {
|
||||
dispatchReceiver = irGetObject((irClass.companionObject()!! as IrClass).symbol)
|
||||
dispatchReceiver = irGetObject(irClass.companionObject()!!.symbol)
|
||||
}
|
||||
|
||||
return parcelableCreatorCreateFromParcel(creator, irGet(parcel))
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclaration
|
||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
@@ -107,7 +107,7 @@ class ParcelableIrTransformer(private val context: IrPluginContext, private val
|
||||
val parcelableProperties = declaration.parcelableProperties
|
||||
|
||||
// If the companion extends Parceler, it can override parts of the generated implementation.
|
||||
val parcelerObject = declaration.companionObject()?.safeAs<IrClass>()?.takeIf {
|
||||
val parcelerObject = declaration.companionObject()?.takeIf {
|
||||
it.isSubclassOfFqName(PARCELER_FQNAME.asString())
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
// true if the class should be processed by the parcelize plugin
|
||||
val IrClass.isParcelize: Boolean
|
||||
@@ -34,7 +33,7 @@ val IrClass.isParcelize: Boolean
|
||||
|
||||
// Finds the getter for a pre-existing CREATOR field on the class companion, which is used for manual Parcelable implementations in Kotlin.
|
||||
val IrClass.creatorGetter: IrSimpleFunctionSymbol?
|
||||
get() = companionObject()?.safeAs<IrClass>()?.getPropertyGetter(CREATOR_NAME.asString())?.takeIf {
|
||||
get() = companionObject()?.getPropertyGetter(CREATOR_NAME.asString())?.takeIf {
|
||||
it.owner.correspondingPropertySymbol?.owner?.backingField?.hasAnnotation(FqName("kotlin.jvm.JvmField")) == true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user