diff --git a/api/swiftpoet.api b/api/swiftpoet.api index 3286064d..fe74148d 100644 --- a/api/swiftpoet.api +++ b/api/swiftpoet.api @@ -454,6 +454,7 @@ public final class io/outfoxx/swiftpoet/Modifier : java/lang/Enum { public static final field FINAL Lio/outfoxx/swiftpoet/Modifier; public static final field INOUT Lio/outfoxx/swiftpoet/Modifier; public static final field INTERNAL Lio/outfoxx/swiftpoet/Modifier; + public static final field LAZY Lio/outfoxx/swiftpoet/Modifier; public static final field MUTATING Lio/outfoxx/swiftpoet/Modifier; public static final field NONMUTATING Lio/outfoxx/swiftpoet/Modifier; public static final field OPEN Lio/outfoxx/swiftpoet/Modifier; diff --git a/src/main/java/io/outfoxx/swiftpoet/Modifier.kt b/src/main/java/io/outfoxx/swiftpoet/Modifier.kt index d8986395..42ddf67a 100644 --- a/src/main/java/io/outfoxx/swiftpoet/Modifier.kt +++ b/src/main/java/io/outfoxx/swiftpoet/Modifier.kt @@ -30,6 +30,8 @@ enum class Modifier( CLASS("class", Target.FUNCTION, Target.PROPERTY), STATIC("static", Target.FUNCTION, Target.PROPERTY), + LAZY("lazy", Target.PROPERTY), + MUTATING("mutating", Target.FUNCTION, Target.PROPERTY), NONMUTATING("nonmutating", Target.FUNCTION, Target.PROPERTY), diff --git a/src/test/java/io/outfoxx/swiftpoet/test/PropertySpecTests.kt b/src/test/java/io/outfoxx/swiftpoet/test/PropertySpecTests.kt index 8c4d4e45..f4af3b58 100644 --- a/src/test/java/io/outfoxx/swiftpoet/test/PropertySpecTests.kt +++ b/src/test/java/io/outfoxx/swiftpoet/test/PropertySpecTests.kt @@ -22,6 +22,7 @@ import io.outfoxx.swiftpoet.DeclaredTypeName.Companion.typeName import io.outfoxx.swiftpoet.FunctionSignatureSpec import io.outfoxx.swiftpoet.FunctionSpec import io.outfoxx.swiftpoet.INT +import io.outfoxx.swiftpoet.Modifier.LAZY import io.outfoxx.swiftpoet.Modifier.PRIVATE import io.outfoxx.swiftpoet.Modifier.PUBLIC import io.outfoxx.swiftpoet.Modifier.UNOWNED @@ -87,6 +88,27 @@ class PropertySpecTests { ) } + @Test + @DisplayName("Adds lazy modifier") + fun lazyProperty() { + val testProperty = + PropertySpec.varBuilder("test", STRING, LAZY) + .initializer("{ %S }()", 1) + .build() + + val out = StringWriter() + testProperty.emit(CodeWriter(out), setOf()) + + assertThat( + out.toString(), + equalTo( + """ + lazy var test: Swift.String = { "1" }() + """.trimIndent() + ) + ) + } + @Test @DisplayName("Adds unowned modifier") fun unownedReferences() {