Skip to content

Commit acac5fe

Browse files
committed
Improve code quality
1 parent 7f7cb2c commit acac5fe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,14 @@ open class KotlinFileExtractor(
526526
}
527527
}
528528

529+
/**
530+
* This function traverses the declaration-parent hierarchy upwards, and retrieves the enclosing class of a class to extract the `enclInReftype` relation.
531+
* Additionally, it extracts a companion field for a companion object into its parent class.
532+
*
533+
* Note that the nested class can also be a local class declared inside a function, so the upwards traversal is skipping the non-class parents. Also, in some cases the file class is the enclosing one, which has no IR representation.
534+
*/
529535
private fun extractEnclosingClass(
530-
declarationParent: IrDeclarationParent, // The declaration parent if the element for which we are extracting the enclosing class
536+
declarationParent: IrDeclarationParent, // The declaration parent of the element for which we are extracting the enclosing class
531537
innerId: Label<out DbClassorinterface>, // ID of the inner class
532538
innerClass: IrClass?, // The inner class, if available. It's not available if the enclosing class of a generated class is being extracted
533539
innerLocId: Label<DbLocation>, // Location of the inner class
@@ -544,7 +550,7 @@ open class KotlinFileExtractor(
544550
useClassInstance(parent, parentClassTypeArguments).typeResult.id
545551
}
546552
tw.writeEnclInReftype(innerId, parentId)
547-
if (innerClass is IrClass && innerClass.isCompanion) {
553+
if (innerClass != null && innerClass.isCompanion) {
548554
// If we are a companion then our parent has a
549555
// public static final ParentClass$CompanionObjectClass CompanionObjectName;
550556
// that we need to fabricate here
@@ -561,7 +567,7 @@ open class KotlinFileExtractor(
561567

562568
break
563569
} else if (parent is IrFile) {
564-
if (innerClass is IrClass) {
570+
if (innerClass != null) {
565571
// We don't have to extract file class containers for classes
566572
break
567573
}

0 commit comments

Comments
 (0)