1616
1717package org.jacodb.ets.dto
1818
19+ import mu.KotlinLogging
1920import org.jacodb.ets.model.BasicBlock
2021import org.jacodb.ets.model.EtsAddExpr
2122import org.jacodb.ets.model.EtsAliasType
@@ -50,6 +51,8 @@ import org.jacodb.ets.model.EtsEntity
5051import org.jacodb.ets.model.EtsEnumValueType
5152import org.jacodb.ets.model.EtsEqExpr
5253import org.jacodb.ets.model.EtsExpExpr
54+ import org.jacodb.ets.model.EtsExportInfo
55+ import org.jacodb.ets.model.EtsExportType
5356import org.jacodb.ets.model.EtsExpr
5457import org.jacodb.ets.model.EtsField
5558import org.jacodb.ets.model.EtsFieldImpl
@@ -63,6 +66,8 @@ import org.jacodb.ets.model.EtsGlobalRef
6366import org.jacodb.ets.model.EtsGtEqExpr
6467import org.jacodb.ets.model.EtsGtExpr
6568import org.jacodb.ets.model.EtsIfStmt
69+ import org.jacodb.ets.model.EtsImportInfo
70+ import org.jacodb.ets.model.EtsImportType
6671import org.jacodb.ets.model.EtsInExpr
6772import org.jacodb.ets.model.EtsInstanceCallExpr
6873import org.jacodb.ets.model.EtsInstanceFieldRef
@@ -131,6 +136,8 @@ import org.jacodb.ets.model.EtsValue
131136import org.jacodb.ets.model.EtsVoidType
132137import org.jacodb.ets.model.EtsYieldExpr
133138
139+ private val logger = KotlinLogging .logger {}
140+
134141class EtsMethodBuilder (
135142 signature : EtsMethodSignature ,
136143 typeParameters : List <EtsType > = emptyList(),
@@ -715,10 +722,14 @@ fun EtsFileDto.toEtsFile(): EtsFile {
715722 val signature = signature.toEtsFileSignature()
716723 val classes = classes.map { it.toEtsClass() }
717724 val namespaces = namespaces.map { it.toEtsNamespace() }
725+ val importInfos = importInfos.map { it.toEtsImportInfo() }
726+ val exportInfos = exportInfos.map { it.toEtsExportInfo() }
718727 return EtsFile (
719728 signature = signature,
720729 classes = classes,
721730 namespaces = namespaces,
731+ importInfos = importInfos,
732+ exportInfos = exportInfos,
722733 )
723734}
724735
@@ -737,6 +748,32 @@ fun LocalDto.toEtsLocal(): EtsLocal {
737748 )
738749}
739750
751+ fun ImportInfoDto.toEtsImportInfo (): EtsImportInfo {
752+ return EtsImportInfo (
753+ name = importName,
754+ type = when (importType) {
755+ " Identifier" -> EtsImportType .DEFAULT
756+ " NamedImports" -> EtsImportType .NAMED
757+ " NamespaceImport" -> EtsImportType .NAMESPACE
758+ " " -> EtsImportType .SIDE_EFFECT
759+ else -> error(" Unknown import type: $importType " )
760+ },
761+ from = importFrom,
762+ nameBeforeAs = nameBeforeAs,
763+ modifiers = EtsModifiers (modifiers),
764+ )
765+ }
766+
767+ fun ExportInfoDto.toEtsExportInfo (): EtsExportInfo {
768+ return EtsExportInfo (
769+ name = exportName,
770+ type = exportType.toEtsExportType(),
771+ from = exportFrom,
772+ nameBeforeAs = nameBeforeAs,
773+ modifiers = EtsModifiers (modifiers),
774+ )
775+ }
776+
740777private fun Int.toEtsClassCategory (): EtsClassCategory {
741778 return when (this ) {
742779 0 -> EtsClassCategory .CLASS
@@ -748,3 +785,18 @@ private fun Int.toEtsClassCategory(): EtsClassCategory {
748785 else -> error(" Unknown class category: $this " )
749786 }
750787}
788+
789+ private fun Int.toEtsExportType (): EtsExportType {
790+ return when (this ) {
791+ 0 -> EtsExportType .NAME_SPACE
792+ 1 -> EtsExportType .CLASS
793+ 2 -> EtsExportType .METHOD
794+ 3 -> EtsExportType .LOCAL
795+ 4 -> EtsExportType .TYPE
796+ 9 -> EtsExportType .UNKNOWN
797+ else -> {
798+ logger.warn { " Unknown export type value: $this , defaulting to UNKNOWN" }
799+ EtsExportType .UNKNOWN
800+ }
801+ }
802+ }
0 commit comments