@@ -104,26 +104,22 @@ open class KotlinFileExtractor(
104104 }
105105 }
106106 is IrFunction -> {
107- @Suppress(" UNCHECKED_CAST" )
108- val parentId = useDeclarationParent(declaration.parent, false ) as Label <DbReftype >
107+ val parentId = useDeclarationParent(declaration.parent, false ).cast<DbReftype >()
109108 extractFunction(declaration, parentId, true , null , listOf ())
110109 }
111110 is IrAnonymousInitializer -> {
112111 // Leaving this intentionally empty. init blocks are extracted during class extraction.
113112 }
114113 is IrProperty -> {
115- @Suppress(" UNCHECKED_CAST" )
116- val parentId = useDeclarationParent(declaration.parent, false ) as Label <DbReftype >
114+ val parentId = useDeclarationParent(declaration.parent, false ).cast<DbReftype >()
117115 extractProperty(declaration, parentId, true , null , listOf ())
118116 }
119117 is IrEnumEntry -> {
120- @Suppress(" UNCHECKED_CAST" )
121- val parentId = useDeclarationParent(declaration.parent, false ) as Label <DbReftype >
118+ val parentId = useDeclarationParent(declaration.parent, false ).cast<DbReftype >()
122119 extractEnumEntry(declaration, parentId)
123120 }
124121 is IrField -> {
125- @Suppress(" UNCHECKED_CAST" )
126- val parentId = useDeclarationParent(declaration.parent, false ) as Label <DbReftype >
122+ val parentId = useDeclarationParent(declaration.parent, false ).cast<DbReftype >()
127123 extractField(declaration, parentId)
128124 }
129125 is IrTypeAlias -> extractTypeAlias(declaration)
@@ -252,16 +248,12 @@ open class KotlinFileExtractor(
252248 // TODO: There's lots of duplication between this and extractClassSource.
253249 // Can we share it?
254250 if (kind == ClassKind .INTERFACE || kind == ClassKind .ANNOTATION_CLASS ) {
255- @Suppress(" UNCHECKED_CAST" )
256- val interfaceId = id as Label <out DbInterface >
257- @Suppress(" UNCHECKED_CAST" )
258- val sourceInterfaceId = useClassSource(c) as Label <out DbInterface >
251+ val interfaceId = id.cast<DbInterface >()
252+ val sourceInterfaceId = useClassSource(c).cast<DbInterface >()
259253 tw.writeInterfaces(interfaceId, cls, pkgId, sourceInterfaceId)
260254 } else {
261- @Suppress(" UNCHECKED_CAST" )
262- val classId = id as Label <out DbClass >
263- @Suppress(" UNCHECKED_CAST" )
264- val sourceClassId = useClassSource(c) as Label <out DbClass >
255+ val classId = id.cast<DbClass >()
256+ val sourceClassId = useClassSource(c).cast<DbClass >()
265257 tw.writeClasses(classId, cls, pkgId, sourceClassId)
266258
267259 if (kind == ClassKind .ENUM_CLASS ) {
@@ -344,8 +336,7 @@ open class KotlinFileExtractor(
344336
345337 private fun extractLocalTypeDeclStmt (c : IrClass , callable : Label <out DbCallable >, parent : Label <out DbStmtparent >, idx : Int ) {
346338 val extractStaticInit = c.declarations.none { it is IrAnonymousInitializer }
347- @Suppress(" UNCHECKED_CAST" )
348- val id = extractClassSource(c, true , extractStaticInit) as Label <out DbClass >
339+ val id = extractClassSource(c, true , extractStaticInit).cast<DbClass >()
349340 extractLocalTypeDeclStmt(id, c, callable, parent, idx)
350341 }
351342
@@ -362,8 +353,7 @@ open class KotlinFileExtractor(
362353 DeclarationStackAdjuster (c).use {
363354
364355 val id = if (c.isAnonymousObject) {
365- @Suppress(" UNCHECKED_CAST" )
366- useAnonymousClass(c).javaResult.id as Label <out DbClass >
356+ useAnonymousClass(c).javaResult.id.cast<DbClass >()
367357 } else {
368358 useClassSource(c)
369359 }
@@ -372,12 +362,10 @@ open class KotlinFileExtractor(
372362 val pkgId = extractPackage(pkg)
373363 val kind = c.kind
374364 if (kind == ClassKind .INTERFACE || kind == ClassKind .ANNOTATION_CLASS ) {
375- @Suppress(" UNCHECKED_CAST" )
376- val interfaceId = id as Label <out DbInterface >
365+ val interfaceId = id.cast<DbInterface >()
377366 tw.writeInterfaces(interfaceId, cls, pkgId, interfaceId)
378367 } else {
379- @Suppress(" UNCHECKED_CAST" )
380- val classId = id as Label <out DbClass >
368+ val classId = id.cast<DbClass >()
381369 tw.writeClasses(classId, cls, pkgId, classId)
382370
383371 if (kind == ClassKind .ENUM_CLASS ) {
@@ -410,8 +398,7 @@ open class KotlinFileExtractor(
410398 tw.writeFieldsKotlinType(instance.id, type.kotlinResult.id)
411399 tw.writeHasLocation(instance.id, locId)
412400 addModifiers(instance.id, " public" , " static" , " final" )
413- @Suppress(" UNCHECKED_CAST" )
414- tw.writeClass_object(id as Label <DbClass >, instance.id)
401+ tw.writeClass_object(id.cast<DbClass >(), instance.id)
415402 }
416403
417404 extractClassModifiers(c, id)
@@ -430,8 +417,7 @@ open class KotlinFileExtractor(
430417 if (parent is IrClass ) {
431418 val parentId =
432419 if (parent.isAnonymousObject) {
433- @Suppress(" UNCHECKED_CAST" )
434- useAnonymousClass(parent).javaResult.id as Label <out DbClass >
420+ useAnonymousClass(parent).javaResult.id.cast<DbClass >()
435421 } else {
436422 useClassInstance(parent, parentClassTypeArguments).typeResult.id
437423 }
@@ -447,8 +433,7 @@ open class KotlinFileExtractor(
447433 tw.writeFieldsKotlinType(instance.id, type.kotlinResult.id)
448434 tw.writeHasLocation(instance.id, innerLocId)
449435 addModifiers(instance.id, " public" , " static" , " final" )
450- @Suppress(" UNCHECKED_CAST" )
451- tw.writeType_companion_object(parentId, instance.id, innerId as Label <DbClass >)
436+ tw.writeType_companion_object(parentId, instance.id, innerId.cast<DbClass >())
452437 }
453438 }
454439
@@ -660,8 +645,7 @@ open class KotlinFileExtractor(
660645 }
661646 val allParamTypes = if (extReceiver != null ) {
662647 val extendedType = useType(extReceiver.type)
663- @Suppress(" UNCHECKED_CAST" )
664- tw.writeKtExtensionFunctions(id as Label <DbMethod >, extendedType.javaResult.id, extendedType.kotlinResult.id)
648+ tw.writeKtExtensionFunctions(id.cast<DbMethod >(), extendedType.javaResult.id, extendedType.kotlinResult.id)
665649
666650 val t = extractValueParameter(extReceiver, id, 0 , null , sourceDeclaration, classTypeArgsIncludingOuterClasses)
667651 listOf (t) + paramTypes
@@ -680,15 +664,13 @@ open class KotlinFileExtractor(
680664 typeSubstitution != null -> useType(substReturnType).javaResult.shortName
681665 else -> f.returnType.classFqName?.shortName()?.asString() ? : f.name.asString()
682666 }
683- @Suppress(" UNCHECKED_CAST" )
684- val constrId = id as Label <DbConstructor >
667+ val constrId = id.cast<DbConstructor >()
685668 tw.writeConstrs(constrId, shortName, " $shortName$paramsSignature " , unitType.javaResult.id, parentId, sourceDeclaration as Label <DbConstructor >)
686669 tw.writeConstrsKotlinType(constrId, unitType.kotlinResult.id)
687670 } else {
688671 val returnType = useType(substReturnType, TypeContext .RETURN )
689672 val shortName = getFunctionShortName(f)
690- @Suppress(" UNCHECKED_CAST" )
691- val methodId = id as Label <DbMethod >
673+ val methodId = id.cast<DbMethod >()
692674 tw.writeMethods(methodId, shortName, " $shortName$paramsSignature " , returnType.javaResult.id, parentId, sourceDeclaration as Label <DbMethod >)
693675 tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
694676 }
@@ -755,8 +737,7 @@ open class KotlinFileExtractor(
755737 val setter = p.setter
756738
757739 if (getter != null ) {
758- @Suppress(" UNCHECKED_CAST" )
759- val getterId = extractFunction(getter, parentId, extractBackingField, typeSubstitution, classTypeArgs) as Label <out DbMethod >?
740+ val getterId = extractFunction(getter, parentId, extractBackingField, typeSubstitution, classTypeArgs)?.cast<DbMethod >()
760741 if (getterId != null ) {
761742 tw.writeKtPropertyGetters(id, getterId)
762743 }
@@ -770,8 +751,7 @@ open class KotlinFileExtractor(
770751 if (! p.isVar) {
771752 logger.errorElement(" !isVar property with a setter" , p)
772753 }
773- @Suppress(" UNCHECKED_CAST" )
774- val setterId = extractFunction(setter, parentId, extractBackingField, typeSubstitution, classTypeArgs) as Label <out DbMethod >?
754+ val setterId = extractFunction(setter, parentId, extractBackingField, typeSubstitution, classTypeArgs)?.cast<DbMethod >()
775755 if (setterId != null ) {
776756 tw.writeKtPropertySetters(id, setterId)
777757 }
@@ -1937,8 +1917,7 @@ open class KotlinFileExtractor(
19371917 val id = extractNewExpr(e.symbol.owner, (e.type as ? IrSimpleType )?.arguments, type, locId, parent, idx, callable, enclosingStmt)
19381918
19391919 if (isAnonymous) {
1940- @Suppress(" UNCHECKED_CAST" )
1941- tw.writeIsAnonymClass(type.javaResult.id as Label <DbClass >, id)
1920+ tw.writeIsAnonymClass(type.javaResult.id.cast<DbClass >(), id)
19421921 }
19431922
19441923 extractCallValueArguments(id, e, enclosingStmt, callable, 0 )
@@ -2147,8 +2126,7 @@ open class KotlinFileExtractor(
21472126 val methodId = useFunction<DbConstructor >(e.symbol.owner)
21482127
21492128 tw.writeHasLocation(id, locId)
2150- @Suppress(" UNCHECKED_CAST" )
2151- tw.writeCallableBinding(id as Label <DbCaller >, methodId)
2129+ tw.writeCallableBinding(id.cast<DbCaller >(), methodId)
21522130 extractCallValueArguments(id, e, id, callable, 0 )
21532131 val dr = e.dispatchReceiver
21542132 if (dr != null ) {
@@ -2919,8 +2897,7 @@ open class KotlinFileExtractor(
29192897 writeExpressionMetadataToTrapFile(callId, labels.methodId, retId)
29202898
29212899 val callableId = useFunction<DbCallable >(target.owner.realOverrideTarget, classTypeArgsIncludingOuterClasses)
2922- @Suppress(" UNCHECKED_CAST" )
2923- tw.writeCallableBinding(callId as Label <out DbCaller >, callableId)
2900+ tw.writeCallableBinding(callId.cast<DbCaller >(), callableId)
29242901
29252902 val useFirstArgAsDispatch: Boolean
29262903 if (dispatchReceiver != null ) {
@@ -3399,8 +3376,7 @@ open class KotlinFileExtractor(
33993376 locId : Label <DbLocation >,
34003377 parameters : List <IrValueParameter >
34013378 ) {
3402- @Suppress(" UNCHECKED_CAST" )
3403- val funLabels = addFunctionNInvoke(tw.getFreshIdLabel(), lambda.returnType, ids.type.javaResult.id as Label <DbReftype >, locId)
3379+ val funLabels = addFunctionNInvoke(tw.getFreshIdLabel(), lambda.returnType, ids.type.javaResult.id.cast<DbReftype >(), locId)
34043380
34053381 // Return
34063382 val retId = tw.getFreshIdLabel<DbReturnstmt >()
@@ -3911,8 +3887,7 @@ open class KotlinFileExtractor(
39113887
39123888 val idNewexpr = extractNewExpr(ids.constructor , ids.type, locId, id, 1 , callable, enclosingStmt)
39133889
3914- @Suppress(" UNCHECKED_CAST" )
3915- tw.writeIsAnonymClass(ids.type.javaResult.id as Label <DbClass >, idNewexpr)
3890+ tw.writeIsAnonymClass(ids.type.javaResult.id.cast<DbClass >(), idNewexpr)
39163891
39173892 extractTypeAccessRecursive(e.typeOperand, locId, idNewexpr, - 3 , callable, enclosingStmt)
39183893
@@ -3964,8 +3939,7 @@ open class KotlinFileExtractor(
39643939 currentDeclaration : IrDeclaration
39653940 ): Label <out DbClass > {
39663941 // Write class
3967- @Suppress(" UNCHECKED_CAST" )
3968- val id = ids.type.javaResult.id as Label <out DbClass >
3942+ val id = ids.type.javaResult.id.cast<DbClass >()
39693943 val pkgId = extractPackage(" " )
39703944 tw.writeClasses(id, " " , pkgId, id)
39713945 tw.writeHasLocation(id, locId)
@@ -3990,8 +3964,7 @@ open class KotlinFileExtractor(
39903964 val baseConstructorId = useFunction<DbConstructor >(baseConstructor as IrFunction )
39913965
39923966 tw.writeHasLocation(superCallId, locId)
3993- @Suppress(" UNCHECKED_CAST" )
3994- tw.writeCallableBinding(superCallId as Label <DbCaller >, baseConstructorId)
3967+ tw.writeCallableBinding(superCallId.cast<DbCaller >(), baseConstructorId)
39953968
39963969 addModifiers(id, " final" )
39973970 addVisibilityModifierToLocalOrAnonymousClass(id)
0 commit comments