in Sources/MockoloFramework/Utils/InheritanceResolver.swift [27:83]
func lookupEntities(key: String,
declType: DeclType,
protocolMap: [String: Entity],
inheritanceMap: [String: Entity]) -> ([Model], [Model], [String], [String], [(String, Data, Int64)]) {
// 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 filepaths and contents used for imports
var pathToContents = [(String, Data, Int64)]()
// 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, declType: declType, path: current.filepath, data: current.data, isProcessed: current.isProcessed)
models.append(contentsOf: sub.members)
if !current.isProcessed {
attributes.append(contentsOf: sub.attributes)
}
if let data = current.data {
pathToContents.append((current.filepath, data, current.entityNode.offset))
}
paths.append(current.filepath)
if declType == .protocolType { // 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, parentPaths, parentPathToContents) = lookupEntities(key: parent, declType: declType, protocolMap: protocolMap, inheritanceMap: inheritanceMap)
models.append(contentsOf: parentModels)
processedModels.append(contentsOf: parentProcessedModels)
attributes.append(contentsOf: parentAttributes)
paths.append(contentsOf: parentPaths)
pathToContents.append(contentsOf:parentPathToContents)
}
}
}
} else if let parentMock = inheritanceMap["\(key)Mock"], declType == .protocolType {
// 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, declType: declType, path: parentMock.filepath, data: parentMock.data, isProcessed: parentMock.isProcessed)
processedModels.append(contentsOf: sub.members)
if !parentMock.isProcessed {
attributes.append(contentsOf: sub.attributes)
}
if let data = parentMock.data {
pathToContents.append((parentMock.filepath, data, parentMock.entityNode.offset))
}
paths.append(parentMock.filepath)
}
return (models, processedModels, attributes, paths, pathToContents)
}