@@ -39,9 +39,11 @@ import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
3939import org.jetbrains.kotlin.fir.references.FirSuperReference
4040import org.jetbrains.kotlin.fir.references.toResolvedBaseSymbol
4141import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticFunctionSymbol
42+ import org.jetbrains.kotlin.fir.resolve.providers.firProvider
4243import org.jetbrains.kotlin.fir.resolve.providers.toSymbol
4344import org.jetbrains.kotlin.fir.resolve.toFirRegularClass
4445import org.jetbrains.kotlin.fir.resolve.toSymbol
46+ import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
4547import org.jetbrains.kotlin.fir.symbols.SymbolInternals
4648import org.jetbrains.kotlin.fir.symbols.impl.*
4749import org.jetbrains.kotlin.fir.types.*
@@ -59,11 +61,11 @@ import org.openrewrite.java.JavaTypeMapping
5961import org.openrewrite.java.internal.JavaTypeCache
6062import org.openrewrite.java.tree.JavaType
6163import org.openrewrite.java.tree.JavaType.*
64+ import org.openrewrite.java.tree.JavaType.Array
6265import org.openrewrite.java.tree.TypeUtils
6366import org.openrewrite.kotlin.KotlinTypeSignatureBuilder.Companion.convertClassIdToFqn
6467import org.openrewrite.kotlin.KotlinTypeSignatureBuilder.Companion.methodName
6568import org.openrewrite.kotlin.KotlinTypeSignatureBuilder.Companion.variableName
66- import kotlin.collections.ArrayList
6769
6870@Suppress(" DuplicatedCode" )
6971class KotlinTypeMapping (
@@ -778,10 +780,9 @@ class KotlinTypeMapping(
778780 else -> Unknown .getInstance()
779781 }
780782 } else if (resolvedSymbol.callableId.classId == null ) {
781- methodDeclarationType( resolvedSymbol.fir, null )
783+ val topLevelFunctions = resolvedSymbol.getContainingFile()?.collectTopLevelFunctions() ? : emptyList( )
782784 declaringType = ShallowClass .build(resolvedSymbol.callableId.packageName.toString() + " ." + firFile.name.replaceFirst(" .kts" , " Kt" ).replaceFirst(" .kt" , " Kt" ))
783- // .withMethods(mutableListOf(methodDeclarationType(resolvedSymbol.fir, null)))
784- // TODO: <need to add methods information here too
785+ .withMethods(topLevelFunctions.map { methodDeclarationType(it, null ) })
785786 }
786787 } else {
787788 declaringType = TypeUtils .asFullyQualified(type(function.typeRef))
@@ -1380,4 +1381,22 @@ class KotlinTypeMapping(
13801381 }
13811382 }
13821383 }
1384+
1385+ private fun FirBasedSymbol <* >.getContainingFile () =
1386+ when (this ) {
1387+ is FirCallableSymbol <* > -> moduleData.session.firProvider.getFirCallableContainerFile(this )
1388+ is FirClassLikeSymbol <* > -> moduleData.session.firProvider.getFirClassifierContainerFileIfAny(this )
1389+ else -> null
1390+ }
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+ }
13831402}
0 commit comments