-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f4603e
commit 824cc43
Showing
24 changed files
with
131 additions
and
59 deletions.
There are no files selected for viewing
43 changes: 41 additions & 2 deletions
43
processor/src/main/kotlin/com/bethibande/actors/KSPProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
package com.bethibande.actors | ||
|
||
import com.bethibande.actors.generation.ActorGenerator | ||
import com.bethibande.actors.collectors.ActorStateCollector | ||
import com.bethibande.actors.collectors.ActorStateFieldCollector | ||
import com.bethibande.actors.engine.EngineData | ||
import com.bethibande.actors.engine.EngineEnvironment | ||
import com.bethibande.actors.engine.GenerationEngine | ||
import com.bethibande.actors.engine.kotlinpoet.KotlinPoetEngine | ||
import com.google.devtools.ksp.processing.Resolver | ||
import com.google.devtools.ksp.processing.SymbolProcessor | ||
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment | ||
import com.google.devtools.ksp.symbol.KSAnnotated | ||
import java.util.ServiceLoader | ||
|
||
class KSPProcessor(private val environment: SymbolProcessorEnvironment): SymbolProcessor { | ||
|
||
companion object { | ||
const val DEFAULT_ENGINE = KotlinPoetEngine.ENGINE_NAME | ||
} | ||
|
||
private fun findEngine(name: String): GenerationEngine? = ServiceLoader.load( | ||
GenerationEngine::class.java, | ||
GenerationEngine::class.java.classLoader | ||
) | ||
.firstOrNull { it.name().equals(name, true) } | ||
|
||
private fun listEngines(): String = ServiceLoader.load( | ||
GenerationEngine::class.java, | ||
GenerationEngine::class.java.classLoader | ||
).joinToString { it.name() } | ||
|
||
private fun collectData(resolver: Resolver, environment: SymbolProcessorEnvironment): EngineData { | ||
val fieldResolver = ActorStateFieldCollector(resolver) | ||
|
||
val stateTypes = ActorStateCollector().collect(resolver, environment) | ||
stateTypes.forEach { type -> fieldResolver.collectFields(type) } | ||
|
||
return EngineData(stateTypes) | ||
} | ||
|
||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
ActorGenerator().generate(resolver, environment) | ||
val data = collectData(resolver, environment) | ||
|
||
val engineName = DEFAULT_ENGINE | ||
val engine = findEngine(engineName) ?: throw IllegalArgumentException("Unknown engine: $engineName, available engines are: ${listEngines()}") | ||
|
||
engine.generate( | ||
EngineEnvironment(environment, resolver, emptyMap()), | ||
data | ||
) | ||
|
||
return emptyList() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
processor/src/main/kotlin/com/bethibande/actors/engine/EngineData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.bethibande.actors.engine | ||
|
||
import com.bethibande.actors.struct.ActorStateType | ||
|
||
data class EngineData( | ||
val types: List<ActorStateType> | ||
) |
10 changes: 10 additions & 0 deletions
10
processor/src/main/kotlin/com/bethibande/actors/engine/EngineEnvironment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bethibande.actors.engine | ||
|
||
import com.google.devtools.ksp.processing.Resolver | ||
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment | ||
|
||
data class EngineEnvironment( | ||
val environment: SymbolProcessorEnvironment, | ||
val resolver: Resolver, | ||
val options: Map<String, String> | ||
) |
8 changes: 8 additions & 0 deletions
8
processor/src/main/kotlin/com/bethibande/actors/engine/GenerationEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.bethibande.actors.engine | ||
|
||
interface GenerationEngine { | ||
|
||
fun name(): String | ||
fun generate(context: EngineEnvironment, data: EngineData) | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
processor/src/main/kotlin/com/bethibande/actors/engine/kotlinpoet/ActorGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.bethibande.actors.engine.kotlinpoet | ||
|
||
import com.bethibande.actors.engine.kotlinpoet.commands.CommandGenerator | ||
import com.bethibande.actors.struct.ActorStateType | ||
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment | ||
|
||
class ActorGenerator { | ||
|
||
fun generate(value: ActorStateType, environment: SymbolProcessorEnvironment) { | ||
CommandGenerator.generate(environment, value) | ||
ReferenceGenerator.generate(environment, value) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ibande/actors/generation/FileGenerator.kt → ...actors/engine/kotlinpoet/FileGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
processor/src/main/kotlin/com/bethibande/actors/engine/kotlinpoet/KotlinPoetEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bethibande.actors.engine.kotlinpoet | ||
|
||
import com.bethibande.actors.engine.EngineData | ||
import com.bethibande.actors.engine.EngineEnvironment | ||
import com.bethibande.actors.engine.GenerationEngine | ||
|
||
class KotlinPoetEngine: GenerationEngine { | ||
|
||
companion object { | ||
const val ENGINE_NAME = "kotlinpoet" | ||
} | ||
|
||
override fun name(): String = ENGINE_NAME | ||
|
||
override fun generate(context: EngineEnvironment, data: EngineData) { | ||
val generator = ActorGenerator() | ||
data.types.forEach { type -> generator.generate(type, context.environment) } | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...e/actors/generation/ReferenceGenerator.kt → ...s/engine/kotlinpoet/ReferenceGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ibande/actors/generation/SpecGenerator.kt → ...actors/engine/kotlinpoet/SpecGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...de/actors/generation/TypeSpecGenerator.kt → ...rs/engine/kotlinpoet/TypeSpecGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ration/behavior/CloseBehaviorGenerator.kt → ...inpoet/behavior/CloseBehaviorGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ion/behavior/ContainsBehaviorGenerator.kt → ...oet/behavior/ContainsBehaviorGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...neration/behavior/GetBehaviorGenerator.kt → ...tlinpoet/behavior/GetBehaviorGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...neration/behavior/SetBehaviorGenerator.kt → ...tlinpoet/behavior/SetBehaviorGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...eration/commands/CloseCommandGenerator.kt → ...linpoet/commands/CloseCommandGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...s/generation/commands/CommandGenerator.kt → ...e/kotlinpoet/commands/CommandGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tion/commands/ContainsCommandGenerator.kt → ...poet/commands/ContainsCommandGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...eneration/commands/GetCommandGenerator.kt → ...otlinpoet/commands/GetCommandGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...generation/commands/InterfaceGenerator.kt → ...kotlinpoet/commands/InterfaceGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...eneration/commands/SetCommandGenerator.kt → ...otlinpoet/commands/SetCommandGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
processor/src/main/kotlin/com/bethibande/actors/generation/ActorGenerator.kt
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
processor/src/main/kotlin/com/bethibande/actors/struct/ActorStateField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
processor/src/main/kotlin/com/bethibande/actors/struct/ActorStateType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
processor/src/main/resources/META-INF/services/com.bethibande.actors.engine.GenerationEngine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.bethibande.actors.engine.kotlinpoet.KotlinPoetEngine |