Skip to content

Commit 56aa830

Browse files
author
Ed Paulosky
authored
Adds FoundationTypes and adds function to import individual types from modules (#504)
* Adds FoundationTypes and adds import * Adds amazon file header and runs formatter
1 parent fefcbab commit 56aa830

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
package software.amazon.smithy.swift.codegen
7+
8+
import software.amazon.smithy.swift.codegen.model.buildSymbol
9+
10+
object FoundationTypes {
11+
val TimeInterval = builtInSymbol("TimeInterval")
12+
}
13+
14+
private fun builtInSymbol(symbol: String) = buildSymbol {
15+
name = symbol
16+
namespace = "Foundation"
17+
}

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class SwiftWriter(private val fullPackageName: String) : CodeWriter() {
110110
imports.addImport("Foundation", false)
111111
}
112112

113+
// Adds an import statement that imports the individual type from the specified module
114+
// Example: addIndividualTypeImport("struct", "Foundation", "Date") -> "import struct Foundation.Date"
115+
fun addIndividualTypeImport(kind: String, module: String, type: String) {
116+
imports.addImport("$kind $module.$type", false)
117+
}
118+
113119
fun addImportReferences(symbol: Symbol, vararg options: SymbolReference.ContextOption) {
114120
symbol.references.forEach { reference ->
115121
for (option in options) {

0 commit comments

Comments
 (0)