Skip to content

Commit a6312ef

Browse files
committed
Split Symbol.swift to reduce complexity of the file
1 parent 791b7e7 commit a6312ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1774
-1442
lines changed

Sources/SymbolKit/Mixin.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 Foundation
12+
13+
/**
14+
A protocol that allows extracted symbols to have extra data
15+
aside from the base ``SymbolGraph/Symbol``.
16+
*/
17+
public protocol Mixin: Codable {
18+
/**
19+
The key under which a mixin's data is filed.
20+
21+
> Important: With respect to deserialization, this framework assumes `mixinKey`s between instances of `SymbolMixin` are unique.
22+
*/
23+
static var mixinKey: String { get }
24+
}

Sources/SymbolKit/SymbolGraph/Misc/LineList.swift renamed to Sources/SymbolKit/SymbolGraph/LineList/LineList.swift

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -202,37 +202,3 @@ extension SymbolGraph.LineList {
202202
}
203203
}
204204
}
205-
206-
extension SymbolGraph.LineList {
207-
/**
208-
Represents a selection in text: a start and end position, a half-open range.
209-
*/
210-
public struct SourceRange: Equatable, Codable {
211-
/**
212-
The range's start position.
213-
*/
214-
public var start: Position
215-
216-
/**
217-
The range's end position.
218-
*/
219-
public var end: Position
220-
}
221-
}
222-
223-
extension SymbolGraph.LineList.SourceRange {
224-
/**
225-
Represents a cursor position in text.
226-
*/
227-
public struct Position: Equatable, Codable {
228-
/**
229-
The zero-based line number of a document.
230-
*/
231-
public var line: Int
232-
233-
/**
234-
The zero-based *byte offset* into a line.
235-
*/
236-
public var character: Int
237-
}
238-
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 Foundation
12+
13+
extension SymbolGraph.LineList.SourceRange {
14+
/**
15+
Represents a cursor position in text.
16+
*/
17+
public struct Position: Equatable, Codable {
18+
/**
19+
The zero-based line number of a document.
20+
*/
21+
public var line: Int
22+
23+
/**
24+
The zero-based *byte offset* into a line.
25+
*/
26+
public var character: Int
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 Foundation
12+
13+
extension SymbolGraph.LineList {
14+
/**
15+
Represents a selection in text: a start and end position, a half-open range.
16+
*/
17+
public struct SourceRange: Equatable, Codable {
18+
/**
19+
The range's start position.
20+
*/
21+
public var start: Position
22+
23+
/**
24+
The range's end position.
25+
*/
26+
public var end: Position
27+
}
28+
}

Sources/SymbolKit/SymbolGraph/Relationship.swift

Lines changed: 1 addition & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension SymbolGraph {
4343
static var mixinKeys: Set<CodingKeys> {
4444
return [
4545
.swiftConstraints,
46-
.sourceOrigin
46+
.sourceOrigin,
4747
]
4848
}
4949
}
@@ -106,164 +106,3 @@ extension SymbolGraph {
106106
}
107107
}
108108
}
109-
110-
extension SymbolGraph.Relationship {
111-
/// The kind of relationship.
112-
public struct Kind: Codable, RawRepresentable, Equatable, Hashable {
113-
public var rawValue: String
114-
public init(rawValue: String) {
115-
self.rawValue = rawValue
116-
}
117-
118-
/**
119-
A symbol `A` is a member of another symbol `B`.
120-
121-
For example, a method or field of a class would be
122-
a member of that class.
123-
124-
The implied inverse of this relationship is that
125-
symbol `B` is the owner of a member symbol `A`.
126-
*/
127-
public static let memberOf = Kind(rawValue: "memberOf")
128-
129-
/**
130-
A symbol `A` conforms to an interface/protocol symbol `B`.
131-
132-
For example, a class `C` that conforms to protocol `P` in Swift would
133-
use this relationship.
134-
135-
The implied inverse of this relationship is that
136-
a symbol `B` that has a conformer `A`.
137-
*/
138-
public static let conformsTo = Kind(rawValue: "conformsTo")
139-
140-
/**
141-
A symbol `A` inherits another symbol `B`.
142-
143-
For example, a derived class inherits from a base class,
144-
or a protocol that refines another protocol would use this relationship.
145-
146-
The implied inverse of this relationship is that
147-
a symbol `B` is a base of another symbol `A`.
148-
*/
149-
public static let inheritsFrom = Kind(rawValue: "inheritsFrom")
150-
151-
/**
152-
A symbol `A` serves as a default implementation of
153-
an interface requirement `B`.
154-
155-
The implied inverse of this relationship is that
156-
an interface requirement `B` has a default implementation of `A`.
157-
*/
158-
public static let defaultImplementationOf = Kind(rawValue: "defaultImplementationOf")
159-
160-
/**
161-
A symbol `A` overrides another symbol `B`, typically through inheritance.
162-
163-
The implied inverse of this relationship is that
164-
a symbol `A` is the base of symbol `B`.
165-
*/
166-
public static let overrides = Kind(rawValue: "overrides")
167-
168-
/**
169-
A symbol `A` is a requirement of interface `B`.
170-
171-
The implied inverse of this relationship is that
172-
an interface `B` has a requirement of `A`.
173-
*/
174-
public static let requirementOf = Kind(rawValue: "requirementOf")
175-
176-
/**
177-
A symbol `A` is an optional requirement of interface `B`.
178-
179-
The implied inverse of this relationship is that
180-
an interface `B` has an optional requirement of `A`.
181-
*/
182-
public static let optionalRequirementOf = Kind(rawValue: "optionalRequirementOf")
183-
}
184-
}
185-
186-
// MARK: - Mixins
187-
188-
extension SymbolGraph.Relationship {
189-
/// A mixin defining a source symbol's origin.
190-
public struct SourceOrigin: Mixin, Codable, Hashable {
191-
public static var mixinKey = "sourceOrigin"
192-
193-
/// Precise Identifier
194-
public var identifier: String
195-
196-
/// Display Name
197-
public var displayName: String
198-
199-
public init(identifier: String, displayName: String) {
200-
self.identifier = identifier
201-
self.displayName = displayName
202-
}
203-
204-
enum CodingKeys: String, CodingKey {
205-
case identifier, displayName
206-
}
207-
208-
public init(from decoder: Decoder) throws {
209-
let container = try decoder.container(keyedBy: CodingKeys.self)
210-
self.identifier = try container.decode(String.self, forKey: .identifier)
211-
self.displayName = try container.decode(String.self, forKey: .displayName)
212-
}
213-
214-
public func encode(to encoder: Encoder) throws {
215-
var container = encoder.container(keyedBy: CodingKeys.self)
216-
try container.encode(identifier, forKey: .identifier)
217-
try container.encode(displayName, forKey: .displayName)
218-
}
219-
}
220-
221-
/// A view of a relationship in terms of the Swift programming language.
222-
public var swift: Swift {
223-
return .init(relationship: self)
224-
}
225-
226-
/// A view of a relationship in terms of the Swift programming language.
227-
public struct Swift {
228-
/// The relationship that may have Swift-specific information.
229-
public var relationship: SymbolGraph.Relationship
230-
231-
public init(relationship: SymbolGraph.Relationship) {
232-
self.relationship = relationship
233-
}
234-
235-
/// The generic constraints on a relationship.
236-
///
237-
/// > Note: `conformsTo` relationships may have constraints for *conditional conformance*.
238-
public var genericConstraints: [SymbolGraph.Symbol.Swift.GenericConstraint] {
239-
guard let genericConstraints = relationship.mixins[GenericConstraints.mixinKey] as? GenericConstraints else {
240-
return []
241-
}
242-
return genericConstraints.constraints
243-
}
244-
}
245-
}
246-
247-
extension SymbolGraph.Relationship.Swift {
248-
/// A mixin collecting Swift generic constraints.
249-
public struct GenericConstraints: Mixin, Codable, Hashable {
250-
public static var mixinKey = "swiftConstraints"
251-
252-
/// Generic constraints.
253-
public var constraints: [SymbolGraph.Symbol.Swift.GenericConstraint]
254-
255-
public init(constraints: [SymbolGraph.Symbol.Swift.GenericConstraint]) {
256-
self.constraints = constraints
257-
}
258-
259-
public init(from decoder: Decoder) throws {
260-
let container = try decoder.singleValueContainer()
261-
self.constraints = try container.decode([SymbolGraph.Symbol.Swift.GenericConstraint].self)
262-
}
263-
264-
public func encode(to encoder: Encoder) throws {
265-
var container = encoder.singleValueContainer()
266-
try container.encode(constraints)
267-
}
268-
}
269-
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 Foundation
12+
13+
extension SymbolGraph.Relationship {
14+
/// The kind of relationship.
15+
public struct Kind: Codable, RawRepresentable, Equatable, Hashable {
16+
public var rawValue: String
17+
public init(rawValue: String) {
18+
self.rawValue = rawValue
19+
}
20+
21+
/**
22+
A symbol `A` is a member of another symbol `B`.
23+
24+
For example, a method or field of a class would be
25+
a member of that class.
26+
27+
The implied inverse of this relationship is that
28+
symbol `B` is the owner of a member symbol `A`.
29+
*/
30+
public static let memberOf = Kind(rawValue: "memberOf")
31+
32+
/**
33+
A symbol `A` conforms to an interface/protocol symbol `B`.
34+
35+
For example, a class `C` that conforms to protocol `P` in Swift would
36+
use this relationship.
37+
38+
The implied inverse of this relationship is that
39+
a symbol `B` that has a conformer `A`.
40+
*/
41+
public static let conformsTo = Kind(rawValue: "conformsTo")
42+
43+
/**
44+
A symbol `A` inherits another symbol `B`.
45+
46+
For example, a derived class inherits from a base class,
47+
or a protocol that refines another protocol would use this relationship.
48+
49+
The implied inverse of this relationship is that
50+
a symbol `B` is a base of another symbol `A`.
51+
*/
52+
public static let inheritsFrom = Kind(rawValue: "inheritsFrom")
53+
54+
/**
55+
A symbol `A` serves as a default implementation of
56+
an interface requirement `B`.
57+
58+
The implied inverse of this relationship is that
59+
an interface requirement `B` has a default implementation of `A`.
60+
*/
61+
public static let defaultImplementationOf = Kind(rawValue: "defaultImplementationOf")
62+
63+
/**
64+
A symbol `A` overrides another symbol `B`, typically through inheritance.
65+
66+
The implied inverse of this relationship is that
67+
a symbol `A` is the base of symbol `B`.
68+
*/
69+
public static let overrides = Kind(rawValue: "overrides")
70+
71+
/**
72+
A symbol `A` is a requirement of interface `B`.
73+
74+
The implied inverse of this relationship is that
75+
an interface `B` has a requirement of `A`.
76+
*/
77+
public static let requirementOf = Kind(rawValue: "requirementOf")
78+
79+
/**
80+
A symbol `A` is an optional requirement of interface `B`.
81+
82+
The implied inverse of this relationship is that
83+
an interface `B` has an optional requirement of `A`.
84+
*/
85+
public static let optionalRequirementOf = Kind(rawValue: "optionalRequirementOf")
86+
}
87+
}

0 commit comments

Comments
 (0)