How to use rawTypes method of RawTypeRepository class

Best Mockingbird code snippet using RawTypeRepository.rawTypes

Run Mockingbird automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

MockableType.swift

Source: MockableType.swift Github

copy
1import Foundation
2import SourceKittenFramework
3import PathKit
4
5/// Classes, protocols, and extensions on either.
6class MockableType: Hashable, Comparable {
7  let name: String
8  let moduleName: String
9  let fullyQualifiedName: String
10  let fullyQualifiedModuleName: String
11  let kind: SwiftDeclarationKind
12  let accessLevel: AccessLevel
13  let methods: Set<Method>
14  let methodsCount: [Method.Reduced: UInt] // For de-duping generic methods.
15  let variables: Set<Variable>
16  let inheritedTypes: Set<MockableType>
17  let allInheritedTypeNames: [String] // Includes opaque inherited types, in declaration order.
18  let opaqueInheritedTypeNames: Set<String>
19  let selfConformanceTypes: Set<MockableType> // Types for `Self` constrained protocols.
20  let allSelfConformanceTypeNames: [String] // Includes opaque conformance type names.
21  let primarySelfConformanceType: MockableType? // Guaranteed to be a class conformance.
22  let primarySelfConformanceTypeName: String? // Specialized based on declared inheritance.
23  let genericTypeContext: [[String]] // Generic type names defined by containing types.
24  let genericTypes: [GenericType] // Generic type declarations are ordered.
25  let whereClauses: Set<WhereClause>
26  let shouldMock: Bool
27  let attributes: Attributes
28  var compilationDirectives: [CompilationDirective]
29  var containedTypes = [MockableType]()
30  let isContainedType: Bool
31  let isInGenericContainingType: Bool
32  let subclassesExternalType: Bool
33  let hasSelfConstraint: Bool
34  
35  enum Constants {
36    static let automaticInheritanceMap: [String: (moduleName: String, typeName: String)] = [
37      "Foundation.NSObjectProtocol": (moduleName: "Foundation", typeName: "NSObject"),
38    ]
39  }
40  
41  // MARK: Diagnostics
42  
43  private let baseRawType: RawType
44  let filePath: Path
45  lazy var lineNumber: Int? = {
46    return SourceSubstring.key
47      .extractLinesNumbers(from: baseRawType.dictionary,
48                           contents: baseRawType.parsedFile.file.contents)?.start
49  }()
50  
51  private let sortableIdentifier: String
52  static func < (lhs: MockableType, rhs: MockableType) -> Bool {
53    return lhs.sortableIdentifier < rhs.sortableIdentifier
54  }
55  
56  func hash(into hasher: inout Hasher) {
57    hasher.combine(sortableIdentifier)
58  }
59  
60  static func == (lhs: MockableType, rhs: MockableType) -> Bool {
61    return lhs.hashValue == rhs.hashValue
62  }
63  
64  /// Creates a `MockableType` from a set of partial `RawType` objects.
65  ///
66  /// - Parameters:
67  ///   - rawTypes: A set of partial `RawType` objects that should include the base declaration.
68  ///   - mockableTypes: All currently known `MockableType` objects used for inheritance flattening.
69  init?(from rawTypes: [RawType],
70        mockableTypes: [String: MockableType],
71        moduleNames: [String],
72        specializationContexts: [String: SpecializationContext],
73        opaqueInheritedTypeNames: Set<String>,
74        rawTypeRepository: RawTypeRepository,
75        typealiasRepository: TypealiasRepository) {
76    guard let baseRawType = rawTypes.findBaseRawType(),
77      baseRawType.kind.isMockable
78      else { return nil }
79    self.baseRawType = baseRawType
80    self.filePath = baseRawType.parsedFile.path
81    
82    let accessLevel = AccessLevel(from: baseRawType.dictionary) ?? .defaultLevel
83    guard accessLevel.isMockableType(withinSameModule: baseRawType.parsedFile.shouldMock)
84      else { return nil }
85    // Handle empty types (declared without any members).
86    let substructure = baseRawType.dictionary[SwiftDocKey.substructure.rawValue]
87      as? [StructureDictionary] ?? []
88    
89    var attributes = Attributes()
90    rawTypes.forEach({ attributes.formUnion(Attributes(from: $0.dictionary)) })
91    self.attributes = attributes
92    guard !attributes.contains(.final) else { return nil }
93    
94    self.name = baseRawType.name
95    self.moduleName = baseRawType.parsedFile.moduleName
96    self.fullyQualifiedName = baseRawType.fullyQualifiedName
97    self.fullyQualifiedModuleName = DeclaredType(from: baseRawType.fullyQualifiedModuleName)
98      .serialize(
99        with: SerializationRequest(
100          method: .moduleQualified,
101          context: SerializationRequest.Context(
102            moduleNames: moduleNames,
103            rawType: baseRawType,
104            rawTypeRepository: rawTypeRepository),
105          options: .standard))
106    self.kind = baseRawType.kind
107    self.accessLevel = accessLevel
108    self.isContainedType = !baseRawType.containingTypeNames.isEmpty
109    self.shouldMock = baseRawType.parsedFile.shouldMock
110    self.genericTypeContext = baseRawType.genericTypeContext
111    self.isInGenericContainingType = baseRawType.genericTypeContext.contains(where: { !$0.isEmpty })
112    
113    // Parse top-level declared methods and variables.
114    var (methods, variables) = MockableType
115      .parseDeclaredTypes(rawTypes: rawTypes,
116                          baseRawType: baseRawType,
117                          moduleNames: moduleNames,
118                          rawTypeRepository: rawTypeRepository,
119                          typealiasRepository: typealiasRepository)
120    
121    // Parse top-level declared generics.
122    var genericTypes = substructure
123      .compactMap({ structure -> GenericType? in
124        guard let genericType = GenericType(from: structure,
125                                            rawType: baseRawType,
126                                            moduleNames: moduleNames,
127                                            rawTypeRepository: rawTypeRepository) else { return nil }
128        return genericType
129      })
130    var whereClauses = genericTypes.flatMap({ $0.whereClauses })
131    let selfConstraintClauses: [WhereClause]
132
133    let source = baseRawType.parsedFile.data
134    if let nameSuffix = SourceSubstring.nameSuffixUpToBody.extract(from: baseRawType.dictionary,
135                                                                   contents: source),
136      let whereRange = nameSuffix.range(of: #"\bwhere\b"#, options: .regularExpression) {
137      let topLevelClauses = nameSuffix[whereRange.upperBound..<nameSuffix.endIndex]
138        .components(separatedBy: ",", excluding: .allGroups)
139        .compactMap({ WhereClause(from: String($0)) })
140        .map({ GenericType.qualifyWhereClause($0,
141                                              containingType: baseRawType,
142                                              moduleNames: moduleNames,
143                                              rawTypeRepository: rawTypeRepository) })
144      // Note: Superclass `Self` conformance must be done through the inheritance syntax, which is
145      // passed via `selfConformanceTypes`.
146      whereClauses.append(contentsOf: topLevelClauses.filter({ !$0.hasSelfConstraint }))
147      selfConstraintClauses = topLevelClauses.filter({ $0.hasSelfConstraint })
148    } else {
149      selfConstraintClauses = []
150    }
151    
152    // Parse inherited members and generics.
153    let rawInheritedTypeNames = rawTypes
154      .compactMap({ $0.dictionary[SwiftDocKey.inheritedtypes.rawValue] as? [StructureDictionary] })
155      .flatMap({ $0 })
156      .compactMap({ $0[SwiftDocKey.name.rawValue] as? String })
157    let (inheritedTypes, _, allInheritedTypeNames, subclassesExternalType) =
158      MockableType
159        .parseInheritedTypes(rawInheritedTypeNames: rawInheritedTypeNames,
160                             forConformance: false,
161                             methods: &methods,
162                             variables: &variables,
163                             genericTypes: &genericTypes,
164                             whereClauses: &whereClauses,
165                             selfConstraintClauses: selfConstraintClauses,
166                             mockableTypes: mockableTypes,
167                             moduleNames: moduleNames,
168                             genericTypeContext: genericTypeContext,
169                             specializationContexts: specializationContexts,
170                             baseRawType: baseRawType,
171                             rawTypeRepository: rawTypeRepository,
172                             typealiasRepository: typealiasRepository)
173    self.inheritedTypes = inheritedTypes
174    self.allInheritedTypeNames = allInheritedTypeNames
175    self.opaqueInheritedTypeNames = opaqueInheritedTypeNames
176      .union(Set(inheritedTypes.flatMap({ $0.opaqueInheritedTypeNames })))
177
178    // Parse protocol `Self` conformance.
179    let rawConformanceTypeNames = baseRawType.kind == .protocol ?
180      baseRawType.selfConformanceTypeNames.union(
181        Set(inheritedTypes.map({ $0.fullyQualifiedModuleName }))
182      ) : []
183    let (_, allSelfConformanceTypes, allSelfConformanceTypeNames, conformsToExternalType) =
184      MockableType
185        .parseInheritedTypes(rawInheritedTypeNames: Array(rawConformanceTypeNames),
186                             forConformance: true,
187                             methods: &methods,
188                             variables: &variables,
189                             genericTypes: &genericTypes,
190                             whereClauses: &whereClauses,
191                             selfConstraintClauses: selfConstraintClauses,
192                             mockableTypes: mockableTypes,
193                             moduleNames: moduleNames,
194                             genericTypeContext: genericTypeContext,
195                             specializationContexts: specializationContexts,
196                             baseRawType: baseRawType,
197                             rawTypeRepository: rawTypeRepository,
198                             typealiasRepository: typealiasRepository)
199    self.selfConformanceTypes = allSelfConformanceTypes
200    self.allSelfConformanceTypeNames = allSelfConformanceTypeNames
201    
202    if let inheritedPrimaryType =
203      inheritedTypes.sorted() // e.g. `protocol MyProtocol: ClassOnlyProtocol`
204        .first(where: { $0.primarySelfConformanceType != nil }) ??
205      allSelfConformanceTypes.sorted() // e.g. `protocol MyProtocol where Self: ClassOnlyProtocol`
206        .first(where: { $0.primarySelfConformanceType != nil }),
207      let primarySelfConformanceType = inheritedPrimaryType.primarySelfConformanceType,
208      let primarySelfConformanceTypeName = inheritedPrimaryType.primarySelfConformanceTypeName {
209      
210      self.primarySelfConformanceType = primarySelfConformanceType
211      self.primarySelfConformanceTypeName = primarySelfConformanceTypeName
212
213    } else if let primaryType = allSelfConformanceTypes.sorted()
214      .first(where: { $0.kind == .class }) {
215      self.primarySelfConformanceType = primaryType
216      self.primarySelfConformanceTypeName = MockableType
217        .specializedSelfConformanceTypeName(primaryType,
218                                            specializationContexts: specializationContexts,
219                                            moduleNames: moduleNames,
220                                            baseRawType: baseRawType,
221                                            rawTypeRepository: rawTypeRepository,
222                                            typealiasRepository: typealiasRepository)
223
224    } else {
225      self.primarySelfConformanceType = nil
226      self.primarySelfConformanceTypeName = nil
227    }
228    
229    self.subclassesExternalType = subclassesExternalType || conformsToExternalType
230    self.methods = methods
231    self.variables = variables
232    
233    var methodsCount = [Method.Reduced: UInt]()
234    methods.forEach({ methodsCount[Method.Reduced(from: $0), default: 0] += 1 })
235    self.methodsCount = methodsCount
236    
237    self.genericTypes = genericTypes
238    self.whereClauses = Set(whereClauses)
239    
240    // Parse any containing preprocessor macros.
241    if let offset = baseRawType.dictionary[SwiftDocKey.offset.rawValue] as? Int64 {
242      self.compilationDirectives = baseRawType.parsedFile.compilationDirectives.filter({
243        $0.range.contains(offset)
244      })
245    } else {
246      self.compilationDirectives = []
247    }
248    
249    // Check if any of the members have `Self` constraints.
250    self.hasSelfConstraint = whereClauses.contains(where: { $0.hasSelfConstraint })
251      || methods.contains(where: { $0.hasSelfConstraint })
252      || variables.contains(where: { $0.hasSelfConstraint })
253      || genericTypes.contains(where: { $0.hasSelfConstraint })
254    
255    if baseRawType.parsedFile.shouldMock {
256      self.sortableIdentifier = [
257        self.name,
258        self.genericTypes.map({ "\($0.name):\($0.constraints)" }).joined(separator: ","),
259        self.whereClauses.map({ "\($0)" }).joined(separator: ",")
260      ].joined(separator: "|")
261    } else {
262      self.sortableIdentifier = name
263    }
264  }
265  
266  private static func parseDeclaredTypes(rawTypes: [RawType],
267                                         baseRawType: RawType,
268                                         moduleNames: [String],
269                                         rawTypeRepository: RawTypeRepository,
270                                         typealiasRepository: TypealiasRepository)
271    -> (methods: Set<Method>, variables: Set<Variable>) {
272      var methods = Set<Method>()
273      var variables = Set<Variable>()
274      for rawType in rawTypes {
275        guard let substructure = rawType.dictionary[SwiftDocKey.substructure.rawValue]
276          as? [StructureDictionary] else { continue }
277        // Cannot override declarations in extensions as they are statically defined.
278        guard rawType.kind != .extension else { continue }
279        for structure in substructure {
280          if let method = Method(from: structure,
281                                 rootKind: baseRawType.kind,
282                                 rawType: rawType,
283                                 moduleNames: moduleNames,
284                                 rawTypeRepository: rawTypeRepository,
285                                 typealiasRepository: typealiasRepository) {
286            methods.insert(method)
287          }
288          if let variable = Variable(from: structure,
289                                     rootKind: baseRawType.kind,
290                                     rawType: rawType,
291                                     moduleNames: moduleNames,
292                                     rawTypeRepository: rawTypeRepository) {
293            variables.insert(variable)
294          }
295        }
296      }
297      return (methods, variables)
298  }
299  
300  // TODO: Supporting protocol `Self` conformance has bloated this function. Needs a refactor soon.
301  private static func parseInheritedTypes(rawInheritedTypeNames: [String],
302                                          forConformance: Bool,
303                                          methods: inout Set<Method>,
304                                          variables: inout Set<Variable>,
305                                          genericTypes: inout [GenericType],
306                                          whereClauses: inout [WhereClause],
307                                          selfConstraintClauses: [WhereClause],
308                                          mockableTypes: [String: MockableType],
309                                          moduleNames: [String],
310                                          genericTypeContext: [[String]],
311                                          specializationContexts: [String: SpecializationContext],
312                                          baseRawType: RawType,
313                                          rawTypeRepository: RawTypeRepository,
314                                          typealiasRepository: TypealiasRepository)
315    
316    -> (inheritedTypes: Set<MockableType>, // Directly inherited types
317    allInheritedTypes: Set<MockableType>, // Includes ancestor inheritance
318    allInheritedTypeNames: [String], // Includes ancestor inheritance and opaque type names
319    subclassesExternalType: Bool) {
320      
321      var inheritedTypes = Set<MockableType>()
322      var allInheritedTypes = Set<MockableType>()
323      var allInheritedTypeNames = [String]()
324      var subclassesExternalType = false
325      let definesDesignatedInitializer = methods.contains(where: { $0.isDesignatedInitializer })
326      
327      let resolveRawType: (String) -> RawType? = { typeName in
328        guard let nearestRawType = rawTypeRepository
329          .nearestInheritedType(named: typeName,
330                                trimmedName: typeName.removingGenericTyping(),
331                                moduleNames: moduleNames,
332                                referencingModuleName: baseRawType.parsedFile.moduleName,
333                                containingTypeNames: baseRawType.containingTypeNames[...])?
334          .findBaseRawType() else { return nil }
335        
336        // Map unmockable inherited types to other types.
337        if baseRawType.kind == .protocol,
338          let mappedType = MockableType.Constants.automaticInheritanceMap[
339            nearestRawType.fullyQualifiedModuleName
340          ],
341          let mappedRawType = rawTypeRepository.rawType(named: mappedType.typeName,
342                                                        in: mappedType.moduleName) {
343          return mappedRawType.findBaseRawType()
344        }
345        
346        return nearestRawType
347      }
348      
349      // Find the correct `MockableType` instances for inheritance based on type name.
350      let parsedInheritedTypes = rawInheritedTypeNames.flatMap({ typeName -> [MockableType] in
351        guard let nearestRawType = resolveRawType(typeName) else {
352          log("Unable to resolve inherited type \(typeName.singleQuoted) for \(baseRawType.name.singleQuoted)")
353          allInheritedTypeNames.append(typeName)
354          return []
355        }
356        
357        // Inherited types could be typealiased, which would hide conformance.
358        guard nearestRawType.kind == .typealias else {
359          guard let mockableType = mockableTypes[nearestRawType.fullyQualifiedModuleName] else {
360            return []
361          }
362          return [mockableType]
363        }
364        
365        // Resolve typealias to fully qualified root type name.
366        let actualTypeNames = typealiasRepository
367          .actualTypeNames(for: nearestRawType.fullyQualifiedModuleName,
368                           rawTypeRepository: rawTypeRepository,
369                           moduleNames: moduleNames,
370                           referencingModuleName: baseRawType.parsedFile.moduleName,
371                           containingTypeNames: baseRawType.containingTypeNames[...])
372        
373        // Resolve fully qualified root type name to raw type.
374        return actualTypeNames.compactMap({
375          guard let nearestRawType = rawTypeRepository
376            .nearestInheritedType(named: $0,
377                                  trimmedName: $0.removingGenericTyping(),
378                                  moduleNames: moduleNames,
379                                  referencingModuleName: baseRawType.parsedFile.moduleName,
380                                  containingTypeNames: baseRawType.containingTypeNames[...])?
381            .findBaseRawType() else { return nil }
382          return mockableTypes[nearestRawType.fullyQualifiedModuleName]
383        })
384      })
385
386      // Merge all inheritable members from the `MockableType` instances.
387      for mockableType in parsedInheritedTypes {
388        if baseRawType.kind == .class
389          && mockableType.kind == .class
390          && mockableType.moduleName != baseRawType.parsedFile.moduleName {
391          subclassesExternalType = true
392        }
393        
394        let shouldInheritFromType = baseRawType.kind == .protocol || mockableType.kind != .protocol
395        let specializationContext = specializationContexts[mockableType.fullyQualifiedModuleName]
396        
397        methods = methods.union(mockableType.methods
398          .filter({ method in
399            let isImplicitlySynthesized = method.attributes.contains(.implicit)
400            guard shouldInheritFromType || isImplicitlySynthesized else { return false }
401            return method.kind.typeScope.isMockable(in: baseRawType.kind) &&
402              // Mocking a subclass with designated initializers shouldn't inherit the superclass'
403              // initializers.
404              (baseRawType.kind == .protocol
405                || isImplicitlySynthesized
406                || !definesDesignatedInitializer
407                || !method.isInitializer)
408          })
409          .map({ method in // Specialize methods from generic types.
410            guard let context = specializationContext else { return method }
411            return method.specialize(using: context,
412                                     moduleNames: moduleNames,
413                                     genericTypeContext: genericTypeContext,
414                                     excludedGenericTypeNames: [],
415                                     rawTypeRepository: rawTypeRepository,
416                                     typealiasRepository: typealiasRepository)
417          })
418        )
419        variables = variables.union(mockableType.variables
420          .filter({ variable in
421            guard shouldInheritFromType || variable.attributes.contains(.implicit)
422              else { return false }
423            return variable.kind.typeScope.isMockable(in: baseRawType.kind)
424          })
425          .map({ variable in // Specialize variables from generic types.
426            guard let context = specializationContext else { return variable }
427            return variable.specialize(using: context,
428                                       moduleNames: moduleNames,
429                                       genericTypeContext: genericTypeContext,
430                                       excludedGenericTypeNames: [],
431                                       rawTypeRepository: rawTypeRepository,
432                                       typealiasRepository: typealiasRepository)
433          })
434        )
435        
436        // Classes must already implement generic constraints from protocols they conform to.
437        guard shouldInheritFromType else { continue }
438        
439        inheritedTypes.insert(mockableType)
440        
441        // Indirect inheritance.
442        if !forConformance {
443          allInheritedTypes.formUnion(mockableType.inheritedTypes)
444          allInheritedTypeNames.append(contentsOf: mockableType.allInheritedTypeNames)
445        } else {
446          allInheritedTypes.formUnion(mockableType.selfConformanceTypes)
447          allInheritedTypeNames.append(contentsOf: mockableType.allSelfConformanceTypeNames)
448        }
449        
450        let isSelfConstraintType = selfConstraintClauses.contains(where: {
451          $0.constrainedTypeName == mockableType.fullyQualifiedModuleName
452            || $0.genericConstraint == mockableType.fullyQualifiedModuleName
453        })
454        let shouldIncludeInheritedType = !forConformance ||
455          forConformance && (isSelfConstraintType || mockableType.kind == .class)
456        if shouldIncludeInheritedType {
457          allInheritedTypes.insert(mockableType)
458          allInheritedTypeNames.append(MockableType.specializedSelfConformanceTypeName(
459            mockableType,
460            specializationContexts: specializationContexts,
461            moduleNames: moduleNames,
462            baseRawType: baseRawType,
463            rawTypeRepository: rawTypeRepository,
464            typealiasRepository: typealiasRepository
465          ))
466        }
467
468        // Only bubble-up generics for protocols from inherited protocols.
469        if baseRawType.kind == .protocol && mockableType.kind == .protocol {
470          let uniqueGenericTypes = Set<String>(genericTypes.map({ $0.name }))
471          genericTypes.append(contentsOf: mockableType.genericTypes.filter({
472            !uniqueGenericTypes.contains($0.name)
473          }))
474          whereClauses.append(contentsOf: mockableType.whereClauses)
475        }
476      }
477      return (inheritedTypes, allInheritedTypes, allInheritedTypeNames, subclassesExternalType)
478  }
479  
480  private static func specializedSelfConformanceTypeName(
481    _ type: MockableType,
482    specializationContexts: [String: SpecializationContext],
483    moduleNames: [String],
484    baseRawType: RawType,
485    rawTypeRepository: RawTypeRepository,
486    typealiasRepository: TypealiasRepository
487  ) -> String {
488    guard !type.genericTypes.isEmpty, !specializationContexts.isEmpty,
489      let context = specializationContexts[type.fullyQualifiedModuleName]
490      else { return type.fullyQualifiedModuleName }
491    
492    let specializedGenericTypes = context.typeList.map({ specialization -> String in
493      let serializationContext = SerializationRequest
494        .Context(moduleNames: moduleNames,
495                 rawType: baseRawType,
496                 rawTypeRepository: rawTypeRepository,
497                 typealiasRepository: typealiasRepository)
498      let qualifiedTypeNameRequest = SerializationRequest(method: .moduleQualified,
499                                                          context: serializationContext,
500                                                          options: .standard)
501      return specialization.serialize(with: qualifiedTypeNameRequest)
502    })
503    
504    let specializedTypeName = type.fullyQualifiedModuleName.removingGenericTyping() +
505      "<" + specializedGenericTypes.joined(separator: ", ") + ">"
506    return specializedTypeName
507  }
508}
509
Full Screen

ProcessTypesOperation.swift

Source: ProcessTypesOperation.swift Github

copy
1import Foundation
2import SourceKittenFramework
3import os.log
4
5public class ProcessTypesOperation: BasicOperation {
6  let parseFilesResult: ParseFilesOperation.Result
7  let checkCacheResult: CheckCacheOperation.Result?
8  let useRelaxedLinking: Bool
9  
10  public class Result {
11    fileprivate(set) var mockableTypes = [MockableType]()
12    fileprivate(set) var parsedFiles = [ParsedFile]()
13  }
14  
15  public let result = Result()
16  let rawTypeRepository = RawTypeRepository()
17  let typealiasRepository = TypealiasRepository()
18  
19  public override var description: String { "Process Types" }
20  
21  public init(parseFilesResult: ParseFilesOperation.Result,
22              checkCacheResult: CheckCacheOperation.Result?,
23              useRelaxedLinking: Bool) {
24    self.parseFilesResult = parseFilesResult
25    self.checkCacheResult = checkCacheResult
26    self.useRelaxedLinking = useRelaxedLinking
27    retainForever(rawTypeRepository)
28    retainForever(typealiasRepository)
29  }
30  
31  override func run() {
32    guard checkCacheResult?.isCached != true else { return }
33    time(.processTypes) {
34      let queue = OperationQueue.createForActiveProcessors()
35      let processStructuresOperations = parseFilesResult.parsedFiles
36        .map({ parsedFile -> ProcessStructuresOperation in
37          let structureDictionary = parsedFile.structure.dictionary
38          let operation = ProcessStructuresOperation(structureDictionary: structureDictionary,
39                                                     parsedFile: parsedFile)
40          retainForever(operation)
41          return operation
42        })
43      queue.addOperations(processStructuresOperations, waitUntilFinished: true)
44      processStructuresOperations.forEach({
45        $0.result.rawTypes.forEach({
46          rawTypeRepository.addRawType($0)
47          if let typeAlias = Typealias(from: $0) { typealiasRepository.addTypealias(typeAlias) }
48        })
49      })
50      
51      let flattenInheritanceOperations = rawTypeRepository.rawTypes
52        .flatMap({ $0.value })
53        .map({ $0.value })
54        .filter({ $0.first(where: { $0.kind.isMockable })?.parsedFile.shouldMock == true })
55        .filter({ $0.first?.isContainedType != true })
56        .map({ rawType -> FlattenInheritanceOperation in
57          let operation = FlattenInheritanceOperation(
58            rawType: rawType,
59            moduleDependencies: parseFilesResult.moduleDependencies,
60            rawTypeRepository: rawTypeRepository,
61            typealiasRepository: typealiasRepository,
62            useRelaxedLinking: useRelaxedLinking
63          )
64          retainForever(operation)
65          return operation
66        })
67      queue.addOperations(flattenInheritanceOperations, waitUntilFinished: true)
68      result.mockableTypes = flattenInheritanceOperations
69        .compactMap({ $0.result.mockableType })
70        .filter({ !$0.isContainedType })
71      result.parsedFiles = parseFilesResult.parsedFiles
72      log("Created \(result.mockableTypes.count) mockable type\(result.mockableTypes.count != 1 ? "s" : "")")
73    }
74  }
75}
76
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger rawTypes code on LambdaTest Cloud Grid

Execute automation tests with rawTypes on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)