Skip to content

Commit 2d3a2b7

Browse files
committed
Create entity
1 parent 6f4c36d commit 2d3a2b7

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
17+
18+
plugins {
19+
kotlin("multiplatform")
20+
alias(libs.plugins.ksp)
21+
}
22+
kotlin {
23+
applyDefaultHierarchyTemplate()
24+
jvm()
25+
26+
@Suppress("unused")
27+
sourceSets {
28+
val commonMain by getting {
29+
dependencies {
30+
implementation(libs.sealedObjectInstances)
31+
}
32+
}
33+
34+
@Suppress("TestDependenciesInNonTestConfigurations")
35+
val commonTest by getting {
36+
dependencies {
37+
implementation(kotlin("test"))
38+
}
39+
}
40+
41+
val jvmMain by getting
42+
val jvmTest by getting
43+
}
44+
}
45+
46+
dependencies {
47+
// https://kotlinlang.org/docs/ksp-multiplatform.html#avoid-the-ksp-configuration-on-ksp-1-0-1
48+
add("kspCommonMainMetadata", libs.sealedObjectInstances)
49+
add("kspJvm", libs.sealedObjectInstances)
50+
}
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)