Kotlin: Refactor extractStaticTypeAccessQualifier

Avoids a cast
This commit is contained in:
Ian Lynagh
2022-08-30 17:04:40 +01:00
parent f5d43b80ed
commit 3459e5e432

View File

@@ -1544,19 +1544,18 @@ open class KotlinFileExtractor(
}
private fun extractStaticTypeAccessQualifier(target: IrDeclaration, parentExpr: Label<out DbExprparent>, locId: Label<DbLocation>, enclosingCallable: Label<out DbCallable>, enclosingStmt: Label<out DbStmt>) {
if (target.shouldExtractAsStaticMemberOfClass) {
extractTypeAccessRecursive(target.parentAsClass.toRawType(), locId, parentExpr, -1, enclosingCallable, enclosingStmt)
} else if (target.shouldExtractAsStaticMemberOfFile) {
extractTypeAccess(useFileClassType(target.parent as IrFile), locId, parentExpr, -1, enclosingCallable, enclosingStmt)
if (target.shouldExtractAsStatic) {
val parent = target.parent
if (parent is IrClass) {
extractTypeAccessRecursive(parent.toRawType(), locId, parentExpr, -1, enclosingCallable, enclosingStmt)
} else if (parent is IrFile) {
extractTypeAccess(useFileClassType(parent), locId, parentExpr, -1, enclosingCallable, enclosingStmt)
} else {
logger.warnElement("Unexpected static type access qualifer ${parent.javaClass}", target)
}
}
}
private val IrDeclaration.shouldExtractAsStaticMemberOfClass: Boolean
get() = this.shouldExtractAsStatic && parent is IrClass
private val IrDeclaration.shouldExtractAsStaticMemberOfFile: Boolean
get() = this.shouldExtractAsStatic && parent is IrFile
private fun isStaticAnnotatedNonCompanionMember(f: IrSimpleFunction) =
f.parentClassOrNull?.isNonCompanionObject == true &&
(f.hasAnnotation(jvmStaticFqName) || f.correspondingPropertySymbol?.owner?.hasAnnotation(jvmStaticFqName) == true)