Skip to content

Commit

Permalink
Use uniqueModel for IfMacroModel subModels before rendering
Browse files Browse the repository at this point in the history
so that we can avoid naming duplication after generation
  • Loading branch information
fummicc1 committed Dec 1, 2024
1 parent 588267d commit facf2aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Sources/MockoloFramework/Models/IfMacroModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
final class IfMacroModel: Model {
let name: String
let offset: Int64
let entities: [Model]
let entities: [(String, Model)]

var modelType: ModelType {
return .macro
}

var fullName: String {
return entities.map {$0.fullName}.joined(separator: "_")
return entities.map {$0.0}.joined(separator: "_")
}

init(name: String,
offset: Int64,
entities: [Model]) {
entities: [(String, Model)]) {
self.name = name
self.entities = entities
self.offset = offset
Expand Down
10 changes: 8 additions & 2 deletions Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,14 @@ extension IfConfigDeclSyntax {
}
}
}

let macroModel = IfMacroModel(name: name, offset: self.offset, entities: subModels)

let uniqueSubModels = uniqueEntities(
in: subModels,
exclude: [:],
fullnames: []
).map({ $0 })

let macroModel = IfMacroModel(name: name, offset: self.offset, entities: uniqueSubModels)
return (macroModel, attrDesc, hasInit)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/MockoloFramework/Templates/IfMacroTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ extension IfMacroModel {
func applyMacroTemplate(name: String,
context: RenderContext,
arguments: GenerationArguments,
entities: [Model]) -> String {
entities: [(String, Model)]) -> String {
let rendered = entities
.compactMap { model in
model.render(
model.1.render(
context: .init(
overloadingResolvedName: model.name, // FIXME: the name is not resolving overload
overloadingResolvedName: model.0,
enclosingType: context.enclosingType,
annotatedTypeKind: context.annotatedTypeKind
),
Expand Down

0 comments on commit facf2aa

Please sign in to comment.