Minor, introduce IrType.classOrNull
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
@@ -12,14 +12,13 @@ import org.jetbrains.kotlin.builtins.UnsignedType
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.getPackageFragment
|
||||
@@ -30,7 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
// This is what Context collects about IR.
|
||||
// This is what Context collects about IR.
|
||||
abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: IrModuleFragment) {
|
||||
|
||||
abstract val symbols: Symbols<T>
|
||||
@@ -192,7 +191,7 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
||||
function.parent is IrPackageFragment &&
|
||||
function.getPackageFragment()!!.fqName.asString() == "kotlin" &&
|
||||
function.valueParameters.isEmpty() &&
|
||||
(symbol.owner.extensionReceiverParameter?.type?.classifierOrNull?.owner as? IrClass).let { receiverClass ->
|
||||
symbol.owner.extensionReceiverParameter?.type?.classOrNull?.owner.let { receiverClass ->
|
||||
receiverClass?.fqNameWhenAvailable?.toUnsafe() == KotlinBuiltIns.FQ_NAMES.kProperty0
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
||||
@@ -39,7 +39,7 @@ class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
||||
// TODO: is this the correct way to get the class?
|
||||
// -1 means value is either IMPLICIT or EXTENSION receiver
|
||||
get() = if (this is IrValueParameterSymbol && owner.index == -1 && owner.name.isSpecial /* <this> */)
|
||||
owner.type.classifierOrNull?.owner as IrClass
|
||||
owner.type.classOrNull?.owner
|
||||
else
|
||||
null
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ fun IrType.isFunctionTypeOrSubtype(): Boolean = DFS.ifAny(listOf(this), { it.sup
|
||||
|
||||
fun IrType.isTypeParameter() = classifierOrNull is IrTypeParameterSymbol
|
||||
|
||||
fun IrType.isInterface() = (classifierOrNull?.owner as? IrClass)?.kind == ClassKind.INTERFACE
|
||||
fun IrType.isInterface() = classOrNull?.owner?.kind == ClassKind.INTERFACE
|
||||
|
||||
fun IrType.isFunctionOrKFunction() = isFunction() || isKFunction()
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ val IrType.classifierOrFail: IrClassifierSymbol
|
||||
val IrType.classifierOrNull: IrClassifierSymbol?
|
||||
get() = safeAs<IrSimpleType>()?.classifier
|
||||
|
||||
val IrType.classOrNull: IrClassSymbol?
|
||||
get() = classifierOrNull as? IrClassSymbol
|
||||
|
||||
fun IrType.makeNotNull() =
|
||||
if (this is IrSimpleType && this.hasQuestionMark) {
|
||||
IrSimpleTypeImpl(
|
||||
@@ -82,7 +85,7 @@ fun IrType.toKotlinType(): KotlinType {
|
||||
}
|
||||
|
||||
fun IrType.getClass(): IrClass? =
|
||||
(this.classifierOrNull as? IrClassSymbol)?.owner
|
||||
classOrNull?.owner
|
||||
|
||||
fun IrClassSymbol.createType(hasQuestionMark: Boolean, arguments: List<IrTypeArgument>): IrSimpleType =
|
||||
IrSimpleTypeImpl(
|
||||
|
||||
Reference in New Issue
Block a user