Skip to content

Commit 4bbdc61

Browse files
committed
Polish
1 parent 8fed615 commit 4bbdc61

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

rewrite-kotlin/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,15 @@ class KotlinTypeMapping(
780780
else -> Unknown.getInstance()
781781
}
782782
} else if (resolvedSymbol.callableId.classId == null) {
783-
val topLevelFunctions = resolvedSymbol.getContainingFile()?.collectTopLevelFunctions() ?: emptyList()
783+
val topLevelFunctions= buildList {
784+
resolvedSymbol.getContainingFile()?.declarations?.forEach {
785+
when (it) {
786+
is FirSimpleFunction -> add(it)
787+
is FirScript -> it.statements.filterIsInstance<FirSimpleFunction>().forEach(::add)
788+
else -> {}
789+
}
790+
}
791+
}
784792
declaringType = ShallowClass.build(resolvedSymbol.callableId.packageName.toString() + "." + firFile.name.replaceFirst(".kts", "Kt").replaceFirst(".kt", "Kt"))
785793
.withMethods(topLevelFunctions.map { methodDeclarationType(it, null) })
786794
}
@@ -1388,15 +1396,4 @@ class KotlinTypeMapping(
13881396
is FirClassLikeSymbol<*> -> moduleData.session.firProvider.getFirClassifierContainerFileIfAny(this)
13891397
else -> null
13901398
}
1391-
1392-
fun FirFile.collectTopLevelFunctions(): List<FirSimpleFunction> =
1393-
buildList {
1394-
declarations.forEach {
1395-
when (it) {
1396-
is FirSimpleFunction -> add(it)
1397-
is FirScript -> it.statements.filterIsInstance<FirSimpleFunction>().forEach(::add)
1398-
else -> {}
1399-
}
1400-
}
1401-
}
14021399
}

0 commit comments

Comments
 (0)