-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathRequiredInitializationWithDefaultValue.swift
More file actions
47 lines (44 loc) · 1.8 KB
/
RequiredInitializationWithDefaultValue.swift
File metadata and controls
47 lines (44 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@_implementationOnly import SwiftSyntax
/// Represents initialization is required for the variable
/// and default value is provided.
///
/// The variable must not be initialized already and
/// must be a stored property.
struct RequiredInitializationWithDefaultValue: RequiredVariableInitialization {
/// The underlying required initialization value.
///
/// This function parameter and code block
/// syntax is fetched from this value and
/// updated when adding this initialization
/// type to init-generator.
let base: RequiredVariableInitialization
/// The default expression when
/// no value provided explicitly.
///
/// This expression is provided
/// during initialization and used
/// to generate required initialization
/// with default value.
let expr: ExprSyntax
/// The function parameter for the initialization function.
///
/// Provides function parameter syntax of underlying initialization.
var param: FunctionParameterSyntax { base.param }
/// The code needs to be added to initialization function.
///
/// Provides code block syntax of underlying initialization.
var code: CodeBlockItemSyntax { base.code }
/// Adds current initialization type to memberwise initialization
/// generator.
///
/// New memberwise initialization generator is created after adding this
/// initialization as required with default value and returned.
///
/// - Parameter generator: The init-generator to add in.
/// - Returns: The modified generator containing this initialization.
func add(to generator: MemberwiseInitGenerator) -> MemberwiseInitGenerator {
var param = base.param
param.defaultValue = .init(value: expr)
return generator.add(.init(param: param, code: base.code))
}
}