Skip to content

Commit

Permalink
remove type requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
sidepelican committed Nov 6, 2024
1 parent b5ac35c commit 1e69000
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 25 deletions.
3 changes: 0 additions & 3 deletions Sources/MockoloFramework/Models/IfMacroModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions Sources/MockoloFramework/Models/MethodModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -150,7 +147,7 @@ final class MethodModel: Model {
paramTypes: params.map(\.type),
isAsync: isAsync,
throwing: throwing,
returnType: type,
returnType: returnType,
encloser: encloser)
}

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions Sources/MockoloFramework/Models/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion Sources/MockoloFramework/Templates/MethodTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 5 additions & 12 deletions Sources/MockoloFramework/Templates/NominalTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>]()
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
Expand Down

0 comments on commit 1e69000

Please sign in to comment.