Skip to content

Commit

Permalink
feat(core): Support StateRecord for @OnStateEvent (#1045)
Browse files Browse the repository at this point in the history
* feat(core): Support StateRecord for @OnStateEvent
  • Loading branch information
Ahoo-Wang authored Dec 18, 2024
1 parent 75f98bd commit 4889c56
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
kotlin.code.style=official
ksp.incremental=true
ksp.incremental.log=true
Expand Down
23 changes: 23 additions & 0 deletions wow-compiler/src/test/kotlin/me/ahoo/wow/compiler/SourceFiles.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
* 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
* http://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 me.ahoo.wow.compiler

import com.tschuchort.compiletesting.SourceFile
import java.io.File

object SourceFiles {
fun File.toSourceFile(): SourceFile {
return SourceFile.new(this.name, this.readText())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package me.ahoo.wow.compiler.metadata

import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.symbolProcessorProviders
import me.ahoo.wow.compiler.SourceFiles.toSourceFile
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
Expand All @@ -32,11 +32,12 @@ class MetadataSymbolProcessorTest {
val compilation = KotlinCompilation().apply {
sources =
listOf(
SourceFile.fromPath(mockBoundedContextFile),
SourceFile.fromPath(mockCompilerAggregateFile),
mockBoundedContextFile.toSourceFile(),
mockCompilerAggregateFile.toSourceFile(),
)
symbolProcessorProviders = mutableListOf(MetadataSymbolProcessorProvider())
inheritClassPath = true
languageVersion = "1.9"
}
val result = compilation.compile()
assertThat(result.messages, result.exitCode, `is`(KotlinCompilation.ExitCode.OK))
Expand All @@ -50,11 +51,12 @@ class MetadataSymbolProcessorTest {
val compilation = KotlinCompilation().apply {
sources =
listOf(
SourceFile.fromPath(mockBoundedContextFile),
SourceFile.fromPath(mockCompilerAggregateFile),
mockBoundedContextFile.toSourceFile(),
mockCompilerAggregateFile.toSourceFile(),
)
symbolProcessorProviders = mutableListOf(MetadataSymbolProcessorProvider())
inheritClassPath = true
languageVersion = "1.9"
}
val result = compilation.compile()
assertThat(result.messages, result.exitCode, `is`(KotlinCompilation.ExitCode.OK))
Expand All @@ -65,14 +67,15 @@ class MetadataSymbolProcessorTest {
fun processExample() {
val exampleApiDir = File("../example/example-api/src/main/kotlin/me/ahoo/wow/example/api")
val exampleApiFiles = exampleApiDir.walkTopDown().filter { it.isFile }.toList()
.map { SourceFile.fromPath(it) }
.map { it.toSourceFile() }
val exampleDomainDir = File("../example/example-domain/src/main/kotlin/me/ahoo/wow/example/domain")
val exampleDomainFiles = exampleDomainDir.walkTopDown().filter { it.isFile }.toList()
.map { SourceFile.fromPath(it) }
.map { it.toSourceFile() }
val compilation = KotlinCompilation().apply {
sources = exampleDomainFiles + exampleApiFiles
symbolProcessorProviders = mutableListOf(MetadataSymbolProcessorProvider())
inheritClassPath = true
languageVersion = "1.9"
}
val result = compilation.compile()
assertThat(result.messages, result.exitCode, `is`(KotlinCompilation.ExitCode.OK))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.ahoo.wow.compiler.query

import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.symbolProcessorProviders
import me.ahoo.wow.compiler.SourceFiles.toSourceFile
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
Expand All @@ -19,11 +19,12 @@ class QuerySymbolProcessorTest {
val compilation = KotlinCompilation().apply {
sources =
listOf(
SourceFile.fromPath(mockBoundedContextFile),
SourceFile.fromPath(mockCompilerAggregateFile),
mockBoundedContextFile.toSourceFile(),
mockCompilerAggregateFile.toSourceFile(),
)
symbolProcessorProviders = mutableListOf(QuerySymbolProcessorProvider())
inheritClassPath = true
languageVersion = "1.9"
}
val result = compilation.compile()
assertThat(result.messages, result.exitCode, `is`(KotlinCompilation.ExitCode.OK))
Expand All @@ -34,14 +35,15 @@ class QuerySymbolProcessorTest {
fun processExample() {
val exampleApiDir = File("../example/example-api/src/main/kotlin/me/ahoo/wow/example/api")
val exampleApiFiles = exampleApiDir.walkTopDown().filter { it.isFile }.toList()
.map { SourceFile.fromPath(it) }
.map { it.toSourceFile() }
val exampleDomainDir = File("../example/example-domain/src/main/kotlin/me/ahoo/wow/example/domain")
val exampleDomainFiles = exampleDomainDir.walkTopDown().filter { it.isFile }.toList()
.map { SourceFile.fromPath(it) }
.map { it.toSourceFile() }
val compilation = KotlinCompilation().apply {
sources = exampleDomainFiles + exampleApiFiles
symbolProcessorProviders = mutableListOf(QuerySymbolProcessorProvider())
inheritClassPath = true
languageVersion = "1.9"
}
val result = compilation.compile()
assertThat(result.messages, result.exitCode, `is`(KotlinCompilation.ExitCode.OK))
Expand All @@ -55,11 +57,12 @@ class QuerySymbolProcessorTest {
val compilation = KotlinCompilation().apply {
sources =
listOf(
SourceFile.fromPath(mockBoundedContextFile),
SourceFile.fromPath(mockCompilerAggregateFile),
mockBoundedContextFile.toSourceFile(),
mockCompilerAggregateFile.toSourceFile()
)
symbolProcessorProviders = mutableListOf(QuerySymbolProcessorProvider())
inheritClassPath = true
languageVersion = "1.9"
}
val result = compilation.compile()
assertThat(result.messages, result.exitCode, `is`(KotlinCompilation.ExitCode.OK))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ package me.ahoo.wow.serialization.event
import com.fasterxml.jackson.databind.node.ObjectNode
import me.ahoo.wow.serialization.JsonRecord

data class StateJsonRecord(override val actual: ObjectNode) : JsonRecord
interface StateRecord : JsonRecord

data class StateJsonRecord(override val actual: ObjectNode) : StateRecord

0 comments on commit 4889c56

Please sign in to comment.