Skip to content

Commit 433e244

Browse files
committed
Create entity
1 parent 6f4c36d commit 433e244

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ kotlinCompileTestingKsp = { module = "dev.zacsweers.kctfork:ksp", version = "0.4
1212
kotlinReflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
1313
kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
1414
kspApi = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
15+
sealedObjectInstances = { module = "fr.smarquis.sealed:sealed-object-instances", version = "1.8.0" }
1516

1617
[plugins]
1718
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }

multi/build.gradle.kts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2023 Simon Marquis
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
plugins {
17+
kotlin("multiplatform")
18+
alias(libs.plugins.ksp)
19+
}
20+
kotlin {
21+
applyDefaultHierarchyTemplate()
22+
jvm()
23+
24+
@Suppress("unused")
25+
sourceSets {
26+
val commonMain by getting {
27+
dependencies {
28+
implementation(libs.sealedObjectInstances)
29+
}
30+
}
31+
32+
@Suppress("TestDependenciesInNonTestConfigurations")
33+
val commonTest by getting {
34+
dependencies {
35+
implementation(kotlin("test"))
36+
}
37+
}
38+
39+
val jvmMain by getting
40+
val jvmTest by getting
41+
}
42+
}
43+
44+
dependencies {
45+
// https://kotlinlang.org/docs/ksp-multiplatform.html#avoid-the-ksp-configuration-on-ksp-1-0-1
46+
add("kspCommonMainMetadata", libs.sealedObjectInstances)
47+
add("kspJvm", libs.sealedObjectInstances)
48+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2023 Simon Marquis
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example
17+
18+
import fr.smarquis.sealed.SealedObjectInstances
19+
20+
sealed class Entity private constructor(private val id: String) {
21+
data object Foo : Entity("Foo")
22+
data object Bar : Entity("Bar")
23+
data object Baz : Entity("Baz")
24+
25+
@SealedObjectInstances
26+
companion object {
27+
val all: Set<Entity> by lazy { Entity.sealedObjectInstances() }
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2023 Simon Marquis
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example
17+
18+
import kotlin.test.Test
19+
import kotlin.test.assertEquals
20+
21+
class EntityTest {
22+
23+
@Test
24+
fun test() {
25+
assertEquals(
26+
expected = setOf(Entity.Foo, Entity.Bar, Entity.Baz),
27+
actual = Entity.Companion.all,
28+
)
29+
}
30+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ plugins {
3535
rootProject.name = "sealed-object-instances"
3636
include("processor")
3737
include("app")
38+
include("multi")
3839

3940
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
4041
enableFeaturePreview("STABLE_CONFIGURATION_CACHE")

0 commit comments

Comments
 (0)