Skip to content

Commit

Permalink
Add lazy modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Feb 16, 2024
1 parent c965f3b commit 439f7ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/swiftpoet.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/outfoxx/swiftpoet/Modifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/io/outfoxx/swiftpoet/test/PropertySpecTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 439f7ee

Please sign in to comment.