|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright (c) 2021 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See https://swift.org/LICENSE.txt for license information |
| 8 | + See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +*/ |
| 10 | + |
| 11 | +import SymbolKit |
| 12 | + |
| 13 | +// MARK: Custom Relationship Kind Identifiers |
| 14 | + |
| 15 | +extension SymbolGraph.Relationship.Kind { |
| 16 | + /// This relationship connects top-level extended type symbols the |
| 17 | + /// respective extended module symbol. |
| 18 | + static let declaredIn = Self(rawValue: "declaredIn") |
| 19 | + |
| 20 | + /// This relationship markes a parent-child hierarchy between a nested |
| 21 | + /// extended type symbol and its parent extended type symbol. It mirrors the |
| 22 | + /// `memberOf` relationship between the two respective original type symbols. |
| 23 | + static let inContextOf = Self(rawValue: "inContextOf") |
| 24 | +} |
| 25 | + |
| 26 | +// MARK: Custom Symbol Kind Identifiers |
| 27 | + |
| 28 | +extension SymbolGraph.Symbol.KindIdentifier { |
| 29 | + static let extendedProtocol = Self(rawValue: "protocol.extension") |
| 30 | + |
| 31 | + static let extendedStructure = Self(rawValue: "struct.extension") |
| 32 | + |
| 33 | + static let extendedClass = Self(rawValue: "class.extension") |
| 34 | + |
| 35 | + static let extendedEnumeration = Self(rawValue: "enum.extension") |
| 36 | + |
| 37 | + static let unknownExtendedType = Self(rawValue: "unknown.extension") |
| 38 | + |
| 39 | + static let extendedModule = Self(rawValue: "module.extension") |
| 40 | + |
| 41 | + init?(extending other: Self) { |
| 42 | + switch other { |
| 43 | + case .struct: |
| 44 | + self = .extendedStructure |
| 45 | + case .protocol: |
| 46 | + self = .extendedProtocol |
| 47 | + case .class: |
| 48 | + self = .extendedClass |
| 49 | + case .enum: |
| 50 | + self = .extendedEnumeration |
| 51 | + case .module: |
| 52 | + self = .extendedModule |
| 53 | + default: |
| 54 | + return nil |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + static func extendedType(for extensionBlock: SymbolGraph.Symbol) -> Self? { |
| 59 | + guard let extensionMixin = extensionBlock.mixins[SymbolGraph.Symbol.Swift.Extension.mixinKey] as? SymbolGraph.Symbol.Swift.Extension else { |
| 60 | + return nil |
| 61 | + } |
| 62 | + |
| 63 | + guard let typeKind = extensionMixin.typeKind else { |
| 64 | + return nil |
| 65 | + } |
| 66 | + |
| 67 | + return Self(extending: typeKind) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +extension SymbolGraph.Symbol.Kind { |
| 72 | + static func extendedType(for extensionBlock: SymbolGraph.Symbol) -> Self { |
| 73 | + let id = SymbolGraph.Symbol.KindIdentifier.extendedType(for: extensionBlock) |
| 74 | + switch id { |
| 75 | + case .some(.extendedProtocol): |
| 76 | + return Self(parsedIdentifier: .extendedProtocol, displayName: "Extended Protocol") |
| 77 | + case .some(.extendedStructure): |
| 78 | + return Self(parsedIdentifier: .extendedStructure, displayName: "Extended Structure") |
| 79 | + case .some(.extendedClass): |
| 80 | + return Self(parsedIdentifier: .extendedClass, displayName: "Extended Class") |
| 81 | + case .some(.extendedEnumeration): |
| 82 | + return Self(parsedIdentifier: .extendedEnumeration, displayName: "Extended Enumeration") |
| 83 | + default: |
| 84 | + return unknownExtendedType |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + static let unknownExtendedType = Self(parsedIdentifier: .unknownExtendedType, displayName: "Extended Type") |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | +// MARK: Swift AccessControl Levels |
| 93 | + |
| 94 | +extension SymbolGraph.Symbol.AccessControl { |
| 95 | + static let `private` = Self(rawValue: "private") |
| 96 | + |
| 97 | + static let filePrivate = Self(rawValue: "fileprivate") |
| 98 | + |
| 99 | + static let `internal` = Self(rawValue: "internal") |
| 100 | + |
| 101 | + static let `public` = Self(rawValue: "public") |
| 102 | + |
| 103 | + static let open = Self(rawValue: "open") |
| 104 | +} |
0 commit comments