Skip to content

Commit

Permalink
Create entity
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMarquis committed Nov 28, 2023
1 parent 6f4c36d commit 433e244
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ kotlinCompileTestingKsp = { module = "dev.zacsweers.kctfork:ksp", version = "0.4
kotlinReflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kspApi = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
sealedObjectInstances = { module = "fr.smarquis.sealed:sealed-object-instances", version = "1.8.0" }

[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
Expand Down
48 changes: 48 additions & 0 deletions multi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 Simon Marquis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
kotlin("multiplatform")
alias(libs.plugins.ksp)
}
kotlin {
applyDefaultHierarchyTemplate()
jvm()

@Suppress("unused")
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.sealedObjectInstances)
}
}

@Suppress("TestDependenciesInNonTestConfigurations")
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}

val jvmMain by getting
val jvmTest by getting
}
}

dependencies {
// https://kotlinlang.org/docs/ksp-multiplatform.html#avoid-the-ksp-configuration-on-ksp-1-0-1
add("kspCommonMainMetadata", libs.sealedObjectInstances)
add("kspJvm", libs.sealedObjectInstances)
}
29 changes: 29 additions & 0 deletions multi/src/commonMain/kotlin/com/example/Entity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2023 Simon Marquis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example

import fr.smarquis.sealed.SealedObjectInstances

sealed class Entity private constructor(private val id: String) {
data object Foo : Entity("Foo")
data object Bar : Entity("Bar")
data object Baz : Entity("Baz")

@SealedObjectInstances
companion object {
val all: Set<Entity> by lazy { Entity.sealedObjectInstances() }
}
}
30 changes: 30 additions & 0 deletions multi/src/commonTest/kotlin/com/example/EntityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 Simon Marquis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example

import kotlin.test.Test
import kotlin.test.assertEquals

class EntityTest {

@Test
fun test() {
assertEquals(
expected = setOf(Entity.Foo, Entity.Bar, Entity.Baz),
actual = Entity.Companion.all,
)
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ plugins {
rootProject.name = "sealed-object-instances"
include("processor")
include("app")
include("multi")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
Expand Down

0 comments on commit 433e244

Please sign in to comment.