func models()

in Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift [427:489]


    func models(with acl: String, metadata: AnnotationMetadata?, processed: Bool) -> [Model] {
        // Detect whether it's static
        let isStatic = self.modifiers.isStatic

        // Need to access pattern bindings to get name, type, and other info of a var decl
        let varmodels = self.bindings.compactMap { (v: PatternBindingSyntax) -> Model in
            let name = v.pattern.trimmedDescription
            var typeName: String?
            var potentialInitParam = false

            // Get the type info and whether it can be a var param for an initializer
            if let vtype = v.typeAnnotation?.type.trimmedDescription {
                potentialInitParam = name.canBeInitParam(type: vtype, isStatic: isStatic)
                typeName = vtype
            }

            let storageKind: VariableModel.MockStorageKind
            switch v.accessorBlock?.accessors {
            case .accessors(let accessorDecls):
                if accessorDecls.contains(where: { $0.accessorSpecifier.tokenKind == .keyword(.set) }) {
                    storageKind = .stored(needsSetCount: true)
                } else if let getterDecl = accessorDecls.first(where: { $0.accessorSpecifier.tokenKind == .keyword(.get) }) {
                    if getterDecl.body == nil { // is protoccol
                        var getterEffects = VariableModel.GetterEffects.empty
                        if getterDecl.effectSpecifiers?.asyncSpecifier != nil {
                            getterEffects.isAsync = true
                        }
                        if let `throws` = getterDecl.effectSpecifiers?.throwsClause {
                            getterEffects.throwing = .init(`throws`)
                        }
                        if getterEffects == .empty {
                            storageKind = .stored(needsSetCount: false)
                        } else {
                            storageKind = .computed(getterEffects)
                        }
                    } else { // is class
                        storageKind = .computed(.empty)
                    }
                } else {
                    // will never happens
                    storageKind = .stored(needsSetCount: false) // fallback
                }
            case .getter:
                storageKind = .computed(.empty)
            case nil:
                storageKind = .stored(needsSetCount: true)
            }

            return VariableModel(name: name,
                                 type: typeName.map { SwiftType($0) },
                                 acl: acl,
                                 isStatic: isStatic,
                                 storageKind: storageKind,
                                 canBeInitParam: potentialInitParam,
                                 offset: v.offset,
                                 rxTypes: metadata?.varTypes,
                                 customModifiers: metadata?.modifiers,
                                 modelDescription: self.description,
                                 combineType: metadata?.combineTypes?[name] ?? metadata?.combineTypes?["all"],
                                 processed: processed)
        }
        return varmodels
    }