Skip to content

Commit f95ab51

Browse files
committed
Split Symbol.swift to reduce complexity of the file
1 parent 1245e32 commit f95ab51

13 files changed

Lines changed: 840 additions & 718 deletions
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
public extension SymbolGraph.Symbol.Availability {
14+
/**
15+
Availability of a symbol in a particular domain.
16+
*/
17+
struct AvailabilityItem: Codable {
18+
/**
19+
The domain in which this availability applies; if undefined, applies to all reasonable domains.
20+
*/
21+
public var domain: Domain?
22+
23+
/**
24+
The version in which a symbol appeared.
25+
*/
26+
public var introducedVersion: SymbolGraph.SemanticVersion?
27+
28+
/**
29+
The version in which a symbol was deprecated.
30+
31+
> Note: If a symbol is *unconditionally deprecated*, this key should be undefined or `null` (see below).
32+
*/
33+
public var deprecatedVersion: SymbolGraph.SemanticVersion?
34+
35+
/**
36+
The version in which a symbol was obsoleted.
37+
38+
> Note: If a symbol is *unconditionally obsoleted*, this key should be undefined or `null` (see below).
39+
*/
40+
public var obsoletedVersion: SymbolGraph.SemanticVersion?
41+
42+
/**
43+
A message further describing availability for documentation purposes.
44+
*/
45+
public var message: String?
46+
47+
/**
48+
If a symbol was renamed at this point, its new name is given here.
49+
50+
> Note: This is not necessarily an identifier but an attribute string provided by a compiler.
51+
*/
52+
public var renamed: String?
53+
54+
/**
55+
If defined and `true`, is unconditionally deprecated regardless
56+
of version, and possibly regardless of domain.
57+
If undefined, assume `false`.
58+
*/
59+
public var isUnconditionallyDeprecated: Bool
60+
61+
/**
62+
If defined and `true`, is unconditionally unavailable regardless
63+
of version, and possibly regardless of domain.
64+
If undefined, assume `false`.
65+
*/
66+
public var isUnconditionallyUnavailable: Bool
67+
68+
/**
69+
A formal but lenient indication that this symbol will definitely be deprecated
70+
in future version of the availability domain, but the version hasn't
71+
been decided yet. This is also known as *soft deprecation*.
72+
73+
Soft deprecation should not provide build errors, runtime errors, or
74+
warnings that can be upgraded to errors, but provides extra time for
75+
usage of a symbol to decrease before providing an explicit
76+
availability deadline.
77+
78+
If a symbol is formally deprecated with an explicit version in the
79+
`deprecated` property above, the `willEventuallyBeDeprecated` key
80+
should not exist. In the event that it is still included
81+
despite this specification, `deprecated` should always take precedence
82+
over this property in clients.
83+
*/
84+
public var willEventuallyBeDeprecated: Bool
85+
86+
enum CodingKeys: String, CodingKey {
87+
case domain
88+
case introducedVersion = "introduced"
89+
case deprecatedVersion = "deprecated"
90+
case obsoletedVersion = "obsoleted"
91+
case message
92+
case renamed
93+
case isUnconditionallyDeprecated
94+
case isUnconditionallyUnavailable
95+
case willEventuallyBeDeprecated
96+
}
97+
98+
public init(from decoder: Decoder) throws {
99+
let container = try decoder.container(keyedBy: CodingKeys.self)
100+
let domain = try container.decodeIfPresent(Domain.self, forKey: .domain)
101+
if domain?.rawValue == "*" {
102+
self.domain = nil
103+
} else {
104+
self.domain = domain
105+
}
106+
self.introducedVersion = try container.decodeIfPresent(SymbolGraph.SemanticVersion.self, forKey: .introducedVersion)
107+
self.deprecatedVersion = try container.decodeIfPresent(SymbolGraph.SemanticVersion.self, forKey: .deprecatedVersion)
108+
self.obsoletedVersion = try container.decodeIfPresent(SymbolGraph.SemanticVersion.self, forKey: .obsoletedVersion)
109+
self.message = try container.decodeIfPresent(String.self, forKey: .message)
110+
self.renamed = try container.decodeIfPresent(String.self, forKey: .renamed)
111+
self.isUnconditionallyDeprecated = try container.decodeIfPresent(Bool.self, forKey: .isUnconditionallyDeprecated) ?? false
112+
self.isUnconditionallyUnavailable = try container.decodeIfPresent(Bool.self, forKey: .isUnconditionallyUnavailable) ?? false
113+
self.willEventuallyBeDeprecated = try container.decodeIfPresent(Bool.self, forKey: .willEventuallyBeDeprecated) ?? false
114+
}
115+
116+
public func encode(to encoder: Encoder) throws {
117+
var container = encoder.container(keyedBy: CodingKeys.self)
118+
try container.encode(domain, forKey: .domain)
119+
if let introducedVersion = introducedVersion {
120+
try container.encode(introducedVersion, forKey: .introducedVersion)
121+
}
122+
if let deprecatedVersion = deprecatedVersion {
123+
try container.encode(deprecatedVersion, forKey: .deprecatedVersion)
124+
}
125+
if let obsoletedVersion = obsoletedVersion {
126+
try container.encode(obsoletedVersion, forKey: .obsoletedVersion)
127+
}
128+
if let message = message {
129+
try container.encode(message, forKey: .message)
130+
}
131+
if let renamed = renamed {
132+
try container.encode(renamed, forKey: .renamed)
133+
}
134+
if isUnconditionallyDeprecated {
135+
try container.encode(isUnconditionallyDeprecated, forKey: .isUnconditionallyDeprecated)
136+
}
137+
if isUnconditionallyUnavailable {
138+
try container.encode(isUnconditionallyUnavailable, forKey: .isUnconditionallyUnavailable)
139+
}
140+
if willEventuallyBeDeprecated {
141+
try container.encode(willEventuallyBeDeprecated, forKey: .willEventuallyBeDeprecated)
142+
}
143+
}
144+
145+
public init(domain: SymbolGraph.Symbol.Availability.Domain?,
146+
introducedVersion: SymbolGraph.SemanticVersion?,
147+
deprecatedVersion: SymbolGraph.SemanticVersion?,
148+
obsoletedVersion: SymbolGraph.SemanticVersion?,
149+
message: String?,
150+
renamed: String?,
151+
isUnconditionallyDeprecated: Bool,
152+
isUnconditionallyUnavailable: Bool,
153+
willEventuallyBeDeprecated: Bool) {
154+
self.domain = domain
155+
self.introducedVersion = introducedVersion
156+
self.deprecatedVersion = deprecatedVersion
157+
self.obsoletedVersion = obsoletedVersion
158+
self.message = message
159+
self.renamed = renamed
160+
self.isUnconditionallyDeprecated = isUnconditionallyDeprecated
161+
self.isUnconditionallyUnavailable = isUnconditionallyUnavailable
162+
self.willEventuallyBeDeprecated = willEventuallyBeDeprecated
163+
}
164+
}
165+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
public extension SymbolGraph.Symbol.Availability {
14+
/**
15+
A versioned context where a symbol resides.
16+
17+
For example, a domain can be an operating system, programming language,
18+
or perhaps a web platform.
19+
20+
A single framework, library, or module could theoretically be
21+
an `AvailabilityDomain`, as it is a containing context and almost always
22+
has a version.
23+
However, availability is usually tied to some larger platform like an SDK for
24+
an operating system like *iOS*.
25+
26+
There may be exceptions when there isn't a reasonable larger context.
27+
For example, a web framework's larger context is simply *the Web*.
28+
Therefore, a web framework could be its own domain so that deprecations and
29+
API changes can be tracked across versions of that framework.
30+
*/
31+
struct Domain: Codable, RawRepresentable {
32+
public var rawValue: String
33+
public init(rawValue: String) {
34+
self.rawValue = rawValue
35+
}
36+
37+
/**
38+
The Swift Programming Language.
39+
40+
This domain main indicate that a symbol is unavailable
41+
in Swift, or availability applies to particular versions
42+
of Swift.
43+
*/
44+
public static let swift = "Swift"
45+
46+
/**
47+
The Swift Package Manager Package Description Format.
48+
*/
49+
public static let swiftPM = "SwiftPM"
50+
51+
/**
52+
Apple's macOS operating system.
53+
*/
54+
public static let macOS = "macOS"
55+
56+
/**
57+
An application extension for the macOS operating system.
58+
*/
59+
public static let macOSAppExtension = "macOSAppExtension"
60+
61+
/**
62+
The iOS operating system.
63+
*/
64+
public static let iOS = "iOS"
65+
66+
/**
67+
An application extension for the iOS operating system.
68+
*/
69+
public static let iOSAppExtension = "iOSAppExtension"
70+
71+
/**
72+
The watchOS operating system.
73+
*/
74+
public static let watchOS = "watchOS"
75+
76+
/**
77+
An application extension for the watchOS operating system.
78+
*/
79+
public static let watchOSAppExtension = "watchOSAppExtension"
80+
81+
/**
82+
The tvOS operating system.
83+
*/
84+
public static let tvOS = "tvOS"
85+
86+
/**
87+
An application extension for the tvOS operating system.
88+
*/
89+
public static let tvOSAppExtension = "tvOSAppExtension"
90+
91+
/**
92+
The Mac Catalyst platform.
93+
*/
94+
public static let macCatalyst = "macCatalyst"
95+
96+
/**
97+
An application extension for the Mac Catalyst platform.
98+
*/
99+
public static let macCatalystAppExtension = "macCatalystAppExtension"
100+
101+
/**
102+
A Linux-based operating system, but not a specific distribution.
103+
*/
104+
public static let linux = "Linux"
105+
}
106+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
public extension SymbolGraph.Symbol {
14+
/**
15+
Availability is described by a *domain* and the versions in which
16+
certain events may have occurred, such as a symbol's appearance in a framework,
17+
its deprecation, obsolescence, or removal.
18+
A symbol may have zero or more availability items.
19+
20+
For example,
21+
a class introduced in iOS 11 would have:
22+
23+
- a availability domain of `"iOS"` and
24+
- an `introduced` version of `11.0.0`.
25+
26+
As another example,
27+
a method `foo` that was renamed to `bar` in iOS 10.1 would have:
28+
29+
- an availability domain of `"iOS"`,
30+
- a `deprecated` version `10.1.0`, and
31+
- a `renamed` string of `"bar"`.
32+
33+
Some symbols may be *unconditionally* unavailable or deprecated.
34+
This means that the availability applies to any version, and
35+
possibly to all domains if the `availabilityDomain` key is undefined.
36+
*/
37+
struct Availability: Mixin, Codable {
38+
public static let mixinKey = "availability"
39+
40+
public var availability: [AvailabilityItem]
41+
42+
public init(from decoder: Decoder) throws {
43+
let container = try decoder.singleValueContainer()
44+
availability = try container.decode([AvailabilityItem].self)
45+
}
46+
47+
public func encode(to encoder: Encoder) throws {
48+
var container = encoder.singleValueContainer()
49+
try container.encode(availability)
50+
}
51+
52+
public init(availability: [AvailabilityItem]) {
53+
self.availability = availability
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)