This repository was archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Module
mattt edited this page Feb 7, 2020
·
13 revisions
public class Module: Codable
Codable
public init(name: String = "Anonymous", sourceFiles: [SourceFile])
var topLevelSymbols: [Symbol] = {
return symbols.filter { $0.declaration is Type || $0.id.pathComponents.isEmpty }
}()
var relationshipsByObject: [Symbol.ID: [Relationship]] = {
Dictionary(grouping: relationships, by: { $0.object.id })
}()
var relationshipsBySubject: [Symbol.ID: [Relationship]] = {
Dictionary(grouping: relationships, by: { $0.subject.id })
}()
var baseClasses: [Symbol] = {
return symbols.filter { $0.declaration is Class &&
typesInherited(by: $0).isEmpty }
}()
var symbolsByIdentifier: [Symbol.ID: [Symbol]] = {
return Dictionary(grouping: symbols, by: { $0.id })
}()
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)
}()
let name: String
let symbols: [Symbol]
let sourceFiles: [SourceFile]
public func typesInheriting(from symbol: Symbol) -> [Symbol]
public func requirements(of symbol: Symbol) -> [Symbol]
public func conditionalCounterparts(of symbol: Symbol) -> [Symbol]
public func typesInherited(by symbol: Symbol) -> [Symbol]
public func optionalRequirements(of symbol: Symbol) -> [Symbol]
public func typesConformed(by symbol: Symbol) -> [Symbol]
public func typesConforming(to symbol: Symbol) -> [Symbol]
public func members(of symbol: Symbol) -> [Symbol]
Generated at 2021-05-05T17:50:46+0000 using swift-doc 1.0.0-beta.6.