Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lazy modifier #116

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 21 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,26 @@ class PropertySpecTests {
)
}

@Test
@DisplayName("Adds lazy modifier")
fun lazyProperty() {
val testProperty =
PropertySpec.varBuilder("test", STRING, LAZY)
.build()

val out = StringWriter()
testProperty.emit(CodeWriter(out), setOf())

assertThat(
out.toString(),
equalTo(
"""
lazy var test: Swift.String
""".trimIndent()
)
)
}

@Test
@DisplayName("Adds unowned modifier")
fun unownedReferences() {
Expand Down
Loading