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
Interface
Mattt edited this page Apr 5, 2020
·
12 revisions
public final class Interface: Codable
Codable
public required init(imports: [Import], symbols: [Symbol])
let imports: [Import]
let symbols: [Symbol]
var symbolsGroupedByIdentifier: [Symbol.ID: [Symbol]] = {
return Dictionary(grouping: symbols, by: { $0.id })
}()
var symbolsGroupedByQualifiedName: [String: [Symbol]] = {
return Dictionary(grouping: symbols, by: { $0.id.description })
}()
var topLevelSymbols: [Symbol] = {
return symbols.filter { $0.api is Type || $0.id.pathComponents.isEmpty }
}()
var baseClasses: [Symbol] = {
return symbols.filter { $0.api is Class &&
typesInherited(by: $0).isEmpty }
}()
var classHierarchies: [Symbol: Set<Symbol>] = {
var classClusters: [Symbol: Set<Symbol>] = [:]
for baseClass in baseClasses {
var superclasses = Set(CollectionOfOne(baseClass))
while !superclasses.isEmpty {
let subclasses = Set(superclasses.flatMap { typesInheriting(from: $0) }.filter { $0.isPublic })
defer { superclasses = subclasses }
classClusters[baseClass, default: []].formUnion(subclasses)
}
}
return classClusters
}()
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.api {
case is Protocol:
if symbol.api.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` {
if let extended = symbols.first(where: { $0.api is Type && $0.id.matches(`extension`.extendedType) }) {
let predicate: Relationship.Predicate
switch extended.api {
case is Protocol:
predicate = .defaultImplementationOf
default:
predicate = .memberOf
}
relationships.insert(Relationship(subject: symbol, predicate: predicate, object: extended))
}
}
if let type = symbol.api as? Type {
var inheritedTypeNames: Set<String> = []
inheritedTypeNames.formUnion(type.inheritance.flatMap { $0.split(separator: "&").map { $0.trimmingCharacters(in: .whitespaces) }
})
for `extension` in extensionsByExtendedType[symbol.id.description] ?? [] {
inheritedTypeNames.formUnion(`extension`.inheritance)
}
inheritedTypeNames = Set(inheritedTypeNames.flatMap { $0.split(separator: "&").map { $0.trimmingCharacters(in: .whitespaces) } })
for name in inheritedTypeNames {
let inheritedTypes = symbols.filter({ ($0.api is Class || $0.api is Protocol) && $0.id.description == name })
if inheritedTypes.isEmpty {
let inherited = Symbol(api: Unknown(name: name), context: [], declaration: nil, documentation: nil, sourceLocation: nil)
relationships.insert(Relationship(subject: symbol, predicate: .conformsTo, object: inherited))
} else {
for inherited in inheritedTypes {
let predicate: Relationship.Predicate
if symbol.api is Class, inherited.api is Class {
predicate = .inheritsFrom
} else {
predicate = .conformsTo
}
relationships.insert(Relationship(subject: symbol, predicate: predicate, object: inherited))
}
}
}
}
}
return Array(relationships)
}()
var relationshipsBySubject: [Symbol.ID: [Relationship]] = {
Dictionary(grouping: relationships, by: { $0.subject.id })
}()
var relationshipsByObject: [Symbol.ID: [Relationship]] = {
Dictionary(grouping: relationships, by: { $0.object.id })
}()
public func members(of symbol: Symbol) -> [Symbol]
public func requirements(of symbol: Symbol) -> [Symbol]
public func optionalRequirements(of symbol: Symbol) -> [Symbol]
public func typesInherited(by symbol: Symbol) -> [Symbol]
public func typesInheriting(from symbol: Symbol) -> [Symbol]
public func typesConformed(by symbol: Symbol) -> [Symbol]
public func typesConforming(to symbol: Symbol) -> [Symbol]
public func conditionalCounterparts(of symbol: Symbol) -> [Symbol]
Generated at 2021-05-05T17:50:46+0000 using swift-doc 1.0.0-beta.6.