Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f729f8

Browse files
tamasvajkigfoo
authored andcommitted
Merge two implementation of enclosing class extraction
1 parent fe93338 commit 5f729f8

1 file changed

Lines changed: 15 additions & 34 deletions

File tree

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

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ open class KotlinFileExtractor(
403403
}
404404
}
405405

406-
fun extractEnclosingClass(innerClass: IrClass, innerId: Label<out DbClassorinterface>, innerLocId: Label<DbLocation>, parentClassTypeArguments: List<IrTypeArgument>) {
407-
with("inner class", innerClass) {
408-
var parent: IrDeclarationParent? = innerClass.parent
406+
private fun extractEnclosingClass(innerDeclaration: IrDeclaration, innerId: Label<out DbClassorinterface>, innerLocId: Label<DbLocation>, parentClassTypeArguments: List<IrTypeArgument>) {
407+
with("enclosing class", innerDeclaration) {
408+
var parent: IrDeclarationParent? = innerDeclaration.parent
409409
while (parent != null) {
410410
if (parent is IrClass) {
411411
val parentId =
@@ -416,13 +416,13 @@ open class KotlinFileExtractor(
416416
useClassInstance(parent, parentClassTypeArguments).typeResult.id
417417
}
418418
tw.writeEnclInReftype(innerId, parentId)
419-
if(innerClass.isCompanion) {
419+
if (innerDeclaration is IrClass && innerDeclaration.isCompanion) {
420420
// If we are a companion then our parent has a
421421
// public static final ParentClass$CompanionObjectClass CompanionObjectName;
422422
// that we need to fabricate here
423-
val instance = useCompanionObjectClassInstance(innerClass)
424-
if(instance != null) {
425-
val type = useSimpleTypeClass(innerClass, emptyList(), false)
423+
val instance = useCompanionObjectClassInstance(innerDeclaration)
424+
if (instance != null) {
425+
val type = useSimpleTypeClass(innerDeclaration, emptyList(), false)
426426
tw.writeFields(instance.id, instance.name, type.javaResult.id, innerId, instance.id)
427427
tw.writeFieldsKotlinType(instance.id, type.kotlinResult.id)
428428
tw.writeHasLocation(instance.id, innerLocId)
@@ -432,6 +432,13 @@ open class KotlinFileExtractor(
432432
}
433433
}
434434

435+
break
436+
} else if (parent is IrFile) {
437+
if (this.filePath != parent.path) {
438+
logger.error("Unexpected file parent found")
439+
}
440+
val fileId = extractFileClass(parent)
441+
tw.writeEnclInReftype(innerId, fileId)
435442
break
436443
}
437444

@@ -3955,33 +3962,7 @@ open class KotlinFileExtractor(
39553962
addVisibilityModifierToLocalOrAnonymousClass(id)
39563963
extractClassSupertypes(superTypes, listOf(), id, inReceiverContext = true)
39573964

3958-
var parent: IrDeclarationParent? = currentDeclaration.parent
3959-
while (parent != null) {
3960-
// todo: merge this with the implementation in `extractClassSource`
3961-
if (parent is IrClass) {
3962-
val parentId =
3963-
if (parent.isAnonymousObject) {
3964-
@Suppress("UNCHECKED_CAST")
3965-
useAnonymousClass(parent).javaResult.id as Label<out DbClass>
3966-
} else {
3967-
useClassInstance(parent, listOf()).typeResult.id
3968-
}
3969-
tw.writeEnclInReftype(id, parentId)
3970-
3971-
break
3972-
}
3973-
3974-
if (parent is IrFile) {
3975-
if (this.filePath != parent.path) {
3976-
logger.error("Unexpected file parent found")
3977-
}
3978-
val fileId = extractFileClass(parent)
3979-
tw.writeEnclInReftype(id, fileId)
3980-
break
3981-
}
3982-
3983-
parent = (parent as? IrDeclaration)?.parent
3984-
}
3965+
extractEnclosingClass(currentDeclaration, id, locId, listOf())
39853966

39863967
return id
39873968
}

0 commit comments

Comments
 (0)