diff --git a/Sources/MockoloFramework/Models/IfMacroModel.swift b/Sources/MockoloFramework/Models/IfMacroModel.swift index be65824b..b49ef9bb 100644 --- a/Sources/MockoloFramework/Models/IfMacroModel.swift +++ b/Sources/MockoloFramework/Models/IfMacroModel.swift @@ -17,9 +17,6 @@ final class IfMacroModel: Model { let name: String let offset: Int64 - var type: SwiftType { - fatalError("unused") - } let entities: [Model] var modelType: ModelType { diff --git a/Sources/MockoloFramework/Models/MethodModel.swift b/Sources/MockoloFramework/Models/MethodModel.swift index c4ddc8d6..527fad81 100644 --- a/Sources/MockoloFramework/Models/MethodModel.swift +++ b/Sources/MockoloFramework/Models/MethodModel.swift @@ -25,9 +25,6 @@ public enum MethodKind: Equatable { final class MethodModel: Model { let name: String let returnType: SwiftType - var type: SwiftType { - return returnType - } let accessLevel: String let kind: MethodKind let offset: Int64 @@ -118,7 +115,7 @@ final class MethodModel: Model { args.append(genericWhereClauseToSignatureComponent) } args.append(contentsOf: paramTypes.map(\.displayName)) - var displayType = self.type.displayName + var displayType = self.returnType.displayName let capped = min(displayType.count, 32) displayType.removeLast(displayType.count-capped) args.append(displayType) @@ -150,7 +147,7 @@ final class MethodModel: Model { paramTypes: params.map(\.type), isAsync: isAsync, throwing: throwing, - returnType: type, + returnType: returnType, encloser: encloser) } @@ -231,7 +228,7 @@ final class MethodModel: Model { genericTypeParams: genericTypeParams, genericWhereClause: genericWhereClause, params: params, - returnType: type, + returnType: returnType, accessLevel: accessLevel, argsHistory: argsHistory, handler: handler(encloser: encloser)) diff --git a/Sources/MockoloFramework/Models/Model.swift b/Sources/MockoloFramework/Models/Model.swift index d289b419..9b5c8e13 100644 --- a/Sources/MockoloFramework/Models/Model.swift +++ b/Sources/MockoloFramework/Models/Model.swift @@ -41,9 +41,6 @@ protocol Model: AnyObject { /// Indicates whether mock generation for this model has been processed var processed: Bool { get } - /// Decl(e.g. class/struct/protocol/enum) or return type (e.g. var/func) - var type: SwiftType { get } - /// Offset where this type is declared var offset: Int64 { get } diff --git a/Sources/MockoloFramework/Templates/MethodTemplate.swift b/Sources/MockoloFramework/Templates/MethodTemplate.swift index 20f67958..8b628877 100644 --- a/Sources/MockoloFramework/Templates/MethodTemplate.swift +++ b/Sources/MockoloFramework/Templates/MethodTemplate.swift @@ -74,7 +74,7 @@ extension MethodModel { return arg.name.safeName }.joined(separator: ", ") - let defaultVal = type.defaultVal() // ?? "nil" + let defaultVal = returnType.defaultVal() // ?? "nil" var mockReturn = ".error" if returnType.typeName.isEmpty { diff --git a/Sources/MockoloFramework/Templates/NominalTemplate.swift b/Sources/MockoloFramework/Templates/NominalTemplate.swift index ef9c67d1..b9e874da 100644 --- a/Sources/MockoloFramework/Templates/NominalTemplate.swift +++ b/Sources/MockoloFramework/Templates/NominalTemplate.swift @@ -270,21 +270,14 @@ extension NominalModel { /// @param models Potentially contains typealias models /// @returns A map of typealiases with multiple possible types func typealiasWhitelist(`in` models: [(String, Model)]) -> [String: [String]]? { - let typealiasModels = models.filter{$0.1.modelType == .typeAlias} - var aliasMap = [String: [String]]() - typealiasModels.forEach { (arg: (key: String, value: Model)) in - - let alias = arg.value - if aliasMap[alias.name] == nil { - aliasMap[alias.name] = [alias.type.typeName] - } else { - if let val = aliasMap[alias.name], !val.contains(alias.type.typeName) { - aliasMap[alias.name]?.append(alias.type.typeName) - } + var aliasMap = [String: Set]() + for (_, model) in models { + if let alias = model as? TypeAliasModel { + aliasMap[alias.name, default: []].insert(alias.type.typeName) } } let aliasDupes = aliasMap.filter {$0.value.count > 1} - return aliasDupes.isEmpty ? nil : aliasDupes + return aliasDupes.isEmpty ? nil : aliasDupes.mapValues {$0.sorted()} } // Finds all combine properties that are attempting to use a property wrapper alias