Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
mattt edited this page Feb 7, 2020 · 13 revisions

Module

public class Module: Codable

Inheritance

Codable

Initializers

init(name:sourceFiles:)

public init(name: String = "Anonymous", sourceFiles: [SourceFile])

Properties

topLevelSymbols

var topLevelSymbols: [Symbol] = {
        return symbols.filter { $0.declaration is Type || $0.id.pathComponents.isEmpty }
    }()

relationshipsByObject

var relationshipsByObject: [Symbol.ID: [Relationship]] = {
        Dictionary(grouping: relationships, by: { $0.object.id })
    }()

relationshipsBySubject

var relationshipsBySubject: [Symbol.ID: [Relationship]] = {
        Dictionary(grouping: relationships, by: { $0.subject.id })
    }()

baseClasses

var baseClasses: [Symbol] = {
        return symbols.filter { $0.declaration is Class &&
                                typesInherited(by: $0).isEmpty }
    }()

symbolsByIdentifier

var symbolsByIdentifier: [Symbol.ID: [Symbol]] = {
        return Dictionary(grouping: symbols, by: { $0.id })
    }()

relationships

var relationships: [Relationship] = {
        var relationships: Set<Relationship> = []
        for symbol in symbols {
            let `extension` = symbol.context.compactMap({ $0 as? Extension }).first

            if let container = symbol.context.compactMap({ $0 as? Symbol }).last {
                let predicate: Relationship.Predicate

                switch container.declaration {
                case is Protocol:
                    if symbol.declaration.modifiers.contains(where: { $0.name == "optional" }) {
                        predicate = .optionalRequirementOf
                    } else {
                        predicate = .requirementOf
                    }
                default:
                    predicate = .memberOf
                }

                relationships.insert(Relationship(subject: symbol, predicate: predicate, object: container))
            }

            if let `extension` = `extension` {
                for extended in symbols.filter({ $0.declaration is Type &&  $0.id.matches(`extension`.extendedType) }) {
                    let predicate: Relationship.Predicate
                    switch extended.declaration {
                    case is Protocol:
                        predicate = .defaultImplementationOf
                    default:
                        predicate = .memberOf
                    }

                    relationships.insert(Relationship(subject: symbol, predicate: predicate, object: extended))
                }
            }

            if let type = symbol.declaration as? Type {
                let inheritance = Set((type.inheritance + (`extension`?.inheritance ?? [])).flatMap { $0.split(separator: "&").map { $0.trimmingCharacters(in: .whitespaces) } })
                for name in inheritance {
                    let inheritedTypes = symbols.filter({ ($0.declaration is Class || $0.declaration is Protocol) && $0.id.matches(name) })
                    if inheritedTypes.isEmpty {
                        let inherited = Symbol(declaration: Unknown(name: name), context: [], documentation: nil, sourceLocation: nil)
                        relationships.insert(Relationship(subject: symbol, predicate: .inheritsFrom, object: inherited))
                    } else {
                        for inherited in inheritedTypes {
                            let predicate: Relationship.Predicate
                            if symbol.declaration is Class, inherited.declaration is Class {
                                predicate = .inheritsFrom
                            } else {
                                predicate = .conformsTo
                            }

                            relationships.insert(Relationship(subject: symbol, predicate: predicate, object: inherited))
                        }
                    }
                }
            }
        }

        return Array(relationships)
    }()

name

let name: String

symbols

let symbols: [Symbol]

sourceFiles

let sourceFiles: [SourceFile]

Methods

typesInheriting(from:)

public func typesInheriting(from symbol: Symbol) -> [Symbol]

requirements(of:)

public func requirements(of symbol: Symbol) -> [Symbol]

conditionalCounterparts(of:)

public func conditionalCounterparts(of symbol: Symbol) -> [Symbol]

typesInherited(by:)

public func typesInherited(by symbol: Symbol) -> [Symbol]

optionalRequirements(of:)

public func optionalRequirements(of symbol: Symbol) -> [Symbol]

typesConformed(by:)

public func typesConformed(by symbol: Symbol) -> [Symbol]

typesConforming(to:)

public func typesConforming(to symbol: Symbol) -> [Symbol]

members(of:)

public func members(of symbol: Symbol) -> [Symbol]