in Sources/MockoloFramework/Utils/InheritanceResolver.swift [27:78]
func lookupEntities(key: String,
declKind: NominalTypeDeclKind,
protocolMap: [String: Entity],
inheritanceMap: [String: Entity]) -> ([Model], [Model], [String], Set<String>, [String]) {
// Used to keep track of types to be mocked
var models = [Model]()
// Used to keep track of types that were already mocked
var processedModels = [Model]()
// Gather attributes declared in current or parent protocols
var attributes = [String]()
// Gather inherited types declared in current or parent protocols
var inheritedTypes = Set<String>()
// Gather filepaths used for imports
var paths = [String]()
// Look up the mock entities of a protocol specified by the name.
if let current = protocolMap[key] {
let sub = current.entityNode.subContainer(metadata: current.metadata, declKind: declKind, path: current.filepath, isProcessed: current.isProcessed)
models.append(contentsOf: sub.members)
if !current.isProcessed {
attributes.append(contentsOf: sub.attributes)
}
inheritedTypes.formUnion(current.entityNode.inheritedTypes)
paths.append(current.filepath)
if declKind == .protocol { // TODO: remove this once parent protocol (current decl = classtype) handling is resolved.
// If the protocol inherits other protocols, look up their entities as well.
for parent in current.entityNode.inheritedTypes {
if parent != .class, parent != .anyType, parent != .anyObject {
let (parentModels, parentProcessedModels, parentAttributes, parentInheritedTypes, parentPaths) = lookupEntities(key: parent, declKind: declKind, protocolMap: protocolMap, inheritanceMap: inheritanceMap)
models.append(contentsOf: parentModels)
processedModels.append(contentsOf: parentProcessedModels)
attributes.append(contentsOf: parentAttributes)
inheritedTypes.formUnion(parentInheritedTypes)
paths.append(contentsOf: parentPaths)
}
}
}
} else if let parentMock = inheritanceMap["\(key)Mock"], declKind == .protocol {
// If the parent protocol is not in the protocol map, look it up in the input parent mocks map.
let sub = parentMock.entityNode.subContainer(metadata: parentMock.metadata, declKind: declKind, path: parentMock.filepath, isProcessed: parentMock.isProcessed)
processedModels.append(contentsOf: sub.members)
if !parentMock.isProcessed {
attributes.append(contentsOf: sub.attributes)
}
paths.append(parentMock.filepath)
}
return (models, processedModels, attributes, inheritedTypes, paths)
}