summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 456e76c)
raw | patch | inline | side by side (parent: 456e76c)
author | fredboy <fredboy@protonmail.com> | |
Tue, 14 May 2024 21:44:26 +0000 (04:44 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Tue, 14 May 2024 21:44:26 +0000 (04:44 +0700) |
19 files changed:
diff --git a/core/build.gradle b/core/build.gradle
index 0cff94fb362992f6bfd232f3d9b802327fc97aff..7aff46869013359c2ca4852bfeddb3d84f7d9783 100644 (file)
--- a/core/build.gradle
+++ b/core/build.gradle
sourceSets.main.java.srcDirs = ["src/"]
dependencies {
- implementation project(':dagger-multibind-annotations')
- ksp project(':dagger-multibind-ksp')
+ implementation "ru.fredboy:automultibind-annotations:1.0.0"
+ ksp "ru.fredboy:automultibind-ksp:1.0.0"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.google.guava:guava:$guavaVersion-android"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindKeyboardInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindKeyboardInputHandler.kt
index 004012d33f2cb5ae37960149c2b069ba6d69fe30..558dc96a14c6f8a4e0d8ab36375b94af635f5c9b 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.input.IKeyboardInputHandler
-import ru.fredboy.cavedroid.ksp.annotations.GenerateSetMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoSet
-@GenerateSetMultibindingsModule(
+@BindsIntoSet(
interfaceClass = IKeyboardInputHandler::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "KeyboardInputHandlersModule"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindMouseInputHandler.kt
index 02b934c6401f9c5d57507f80ca21e7b04db374d4..af9b608ea05c656f26b349cc57a446f0436cbf18 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.input.IMouseInputHandler
-import ru.fredboy.cavedroid.ksp.annotations.GenerateSetMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoSet
-@GenerateSetMultibindingsModule(
+@BindsIntoSet(
interfaceClass = IMouseInputHandler::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "MouseInputHandlersModule"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindPlaceBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindPlaceBlockAction.kt
index 779835f70b601bba1b4bda5678566bf8b1a69ed2..89f2dd0bd44c45955b22209d6f84919b9435e298 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.actions.placeblock.IPlaceBlockAction
-import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoMapStringKey
-@GenerateMapMultibindingsModule(
+@BindsIntoMapStringKey(
interfaceClass = IPlaceBlockAction::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "PlaceBlockActionsModule"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindRenderer.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindRenderer.kt
index ae994ea1a156f3c6e351d9bf39e6c30ed75bfc59..c1d96a91033c05ae0989a79d4b52cf6906b8cb13 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.render.IGameRenderer
-import ru.fredboy.cavedroid.ksp.annotations.GenerateSetMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoSet
-@GenerateSetMultibindingsModule(
+@BindsIntoSet(
interfaceClass = IGameRenderer::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "RenderModule"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUpdateBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUpdateBlockAction.kt
index 8665ec1f9652fe3779d09ebea53394e23df21161..310d69eef74de04b5b7d6246acda46ad90917733 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.actions.updateblock.IUpdateBlockAction
-import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoMapStringKey
-@GenerateMapMultibindingsModule(
+@BindsIntoMapStringKey(
interfaceClass = IUpdateBlockAction::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "UpdateBlockActionsModule"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseBlockAction.kt
index b34214d3d21d57db75fc99b4764b235efa8ac057..46353ca6f9e073b9565d1128596a5db6937065e4 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.actions.useblock.IUseBlockAction
-import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoMapStringKey
-@GenerateMapMultibindingsModule(
+@BindsIntoMapStringKey(
interfaceClass = IUseBlockAction::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "UseBlockActionsModule"
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseItemAction.kt b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseItemAction.kt
index de2c74f65d9724a200fb213e98050b06400a45e1..7f17bfcb3199e116ce1030c4ee15fd2ba97b59a2 100644 (file)
package ru.deadsoftware.cavedroid.misc.annotations.multibinding
import ru.deadsoftware.cavedroid.game.actions.useitem.IUseItemAction
-import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+import ru.fredboy.automultibind.annotations.BindsIntoMapStringKey
-@GenerateMapMultibindingsModule(
+@BindsIntoMapStringKey(
interfaceClass = IUseItemAction::class,
modulePackage = MultibindingConfig.GENERATED_MODULES_PACKAGE,
moduleName = "UseItemActionsModule"
diff --git a/dagger-multibind-annotations/build.gradle b/dagger-multibind-annotations/build.gradle
+++ /dev/null
@@ -1,7 +0,0 @@
-plugins {
- id 'kotlin'
-}
-
-kotlin {
- jvmToolchain(17)
-}
diff --git a/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateMapMultibindingsModule.kt b/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateMapMultibindingsModule.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-package ru.fredboy.cavedroid.ksp.annotations
-
-import kotlin.reflect.KClass
-
-/**
- * Annotation annotated with this must include stringKey parameter for key selection in generated module
- */
-@Target(AnnotationTarget.ANNOTATION_CLASS)
-@Retention(AnnotationRetention.SOURCE)
-annotation class GenerateMapMultibindingsModule(
- val interfaceClass: KClass<*>,
- val modulePackage: String,
- val moduleName: String,
-)
diff --git a/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateSetMultibindingsModule.kt b/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateSetMultibindingsModule.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package ru.fredboy.cavedroid.ksp.annotations
-
-import kotlin.reflect.KClass
-
-@Target(AnnotationTarget.ANNOTATION_CLASS)
-@Retention(AnnotationRetention.SOURCE)
-annotation class GenerateSetMultibindingsModule(
- val interfaceClass: KClass<*>,
- val modulePackage: String,
- val moduleName: String,
-)
diff --git a/dagger-multibind-ksp/build.gradle b/dagger-multibind-ksp/build.gradle
+++ /dev/null
@@ -1,14 +0,0 @@
-plugins {
- id 'kotlin'
- id 'com.google.devtools.ksp' version "$kspVersion"
-}
-
-kotlin {
- jvmToolchain(17)
-}
-
-dependencies {
- implementation project(':dagger-multibind-annotations')
- implementation "com.squareup:kotlinpoet-ksp:$kotlinpoetKspVersion"
- implementation "com.google.devtools.ksp:symbol-processing-api:$kspVersion"
-}
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateMapMultibindingsSymbolProcessor.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateMapMultibindingsSymbolProcessor.kt
+++ /dev/null
@@ -1,103 +0,0 @@
-package ru.fredboy.cavedroid.ksp.processor
-
-import com.google.devtools.ksp.processing.*
-import com.google.devtools.ksp.symbol.KSAnnotated
-import com.google.devtools.ksp.symbol.KSClassDeclaration
-import com.google.devtools.ksp.symbol.KSType
-import com.squareup.kotlinpoet.*
-import com.squareup.kotlinpoet.ksp.toClassName
-import com.squareup.kotlinpoet.ksp.writeTo
-import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
-
-class GenerateMapMultibindingsSymbolProcessor(
- private val codeGenerator: CodeGenerator,
- private val logger: KSPLogger,
-) : SymbolProcessor {
-
- private fun generateModule(
- annotationName: String,
- interfaceName: ClassName,
- moduleName: ClassName,
- classes: List<KSClassDeclaration>
- ): FileSpec? {
- if (classes.isEmpty()) {
- return null
- }
-
- val bindings = classes.map { decl ->
- val stringKey = decl.annotations.first { declAnn ->
- declAnn.shortName.getShortName() == annotationName
- }.arguments.firstOrNull { arg ->
- arg.name!!.getShortName() == "stringKey"
- }?.value as? String ?: run {
- logger.error("@${annotationName} must include stringKey parameter for key selection in generated module")
- throw IllegalArgumentException()
- }
-
- val clazz = decl.toClassName()
-
- FunSpec.builder("bind${clazz.simpleName}")
- .addAnnotation(ClassName("dagger", "Binds"))
- .addAnnotation(ClassName("dagger.multibindings", "IntoMap"))
- .addAnnotation(
- AnnotationSpec.builder(ClassName("dagger.multibindings", "StringKey"))
- .addMember("\"$stringKey\"")
- .build()
- )
- .addParameter(ParameterSpec("impl", clazz))
- .returns(interfaceName)
- .addCode("return impl")
- .build()
- }
-
- val moduleObject = TypeSpec.objectBuilder(moduleName)
- .addAnnotation(ClassName("dagger", "Module"))
- .addAnnotation(
- AnnotationSpec.builder(ClassName("javax.annotation.processing", "Generated"))
- .addMember("value = [%S]", this::class.qualifiedName!!)
- .build()
- )
- .addFunctions(bindings)
- .build()
-
- return FileSpec.builder(moduleName)
- .addType(moduleObject)
- .build()
-
- }
-
- private fun processAnnotation(resolver: Resolver, annotation: KSClassDeclaration) {
- val args = annotation.annotations.first {
- it.shortName.getShortName() == "GenerateMapMultibindingsModule"
- }.arguments.takeIf { it.size == 3 } ?: run {
- logger.error("GenerateMapMultibindingsModule should have 3 arguments")
- throw IllegalArgumentException()
- }
-
- val interfaceName = args.first { it.name?.getShortName() == "interfaceClass" }.value as KSType
- val modulePackage = args.first { it.name?.getShortName() == "modulePackage" }.value as String
- val moduleName = args.first { it.name?.getShortName() == "moduleName" }.value as String
-
- val moduleClassName = ClassName(modulePackage, moduleName)
- val elements = resolver.getSymbolsWithAnnotation(annotation.qualifiedName!!.asString())
- .filterIsInstance<KSClassDeclaration>()
- .toList()
-
- logger.info("Found elements: ${elements.joinToString()}")
-
- generateModule(
- annotationName = annotation.qualifiedName!!.getShortName(),
- interfaceName = interfaceName.toClassName(),
- moduleName = moduleClassName,
- classes = elements
- )?.writeTo(codeGenerator, Dependencies(true))
- }
-
- override fun process(resolver: Resolver): List<KSAnnotated> {
- val annotations = resolver.getAnnotatedClasses(GenerateMapMultibindingsModule::class.qualifiedName!!, logger)
- logger.info("Found annotations: ${annotations.joinToString { it.qualifiedName!!.asString() }}")
- annotations.forEach { processAnnotation(resolver, it) }
- return emptyList()
- }
-
-}
\ No newline at end of file
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateSetMultibindingsSymbolProcessor.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateSetMultibindingsSymbolProcessor.kt
+++ /dev/null
@@ -1,86 +0,0 @@
-package ru.fredboy.cavedroid.ksp.processor
-
-import com.google.devtools.ksp.processing.*
-import com.google.devtools.ksp.symbol.KSAnnotated
-import com.google.devtools.ksp.symbol.KSClassDeclaration
-import com.google.devtools.ksp.symbol.KSType
-import com.squareup.kotlinpoet.*
-import com.squareup.kotlinpoet.ksp.toClassName
-import com.squareup.kotlinpoet.ksp.writeTo
-import ru.fredboy.cavedroid.ksp.annotations.GenerateSetMultibindingsModule
-
-class GenerateSetMultibindingsSymbolProcessor(
- private val codeGenerator: CodeGenerator,
- private val logger: KSPLogger,
-) : SymbolProcessor {
-
- private fun generateModule(
- interfaceName: ClassName,
- moduleName: ClassName,
- classes: List<ClassName>
- ): FileSpec? {
- if (classes.isEmpty()) {
- return null
- }
-
- val bindings = classes.map { clazz ->
- FunSpec.builder("bind${clazz.simpleName}")
- .addAnnotation(ClassName("dagger", "Binds"))
- .addAnnotation(ClassName("dagger.multibindings", "IntoSet"))
- .addParameter(ParameterSpec("impl", clazz))
- .returns(interfaceName)
- .addCode("return impl")
- .build()
- }
-
- val moduleObject = TypeSpec.objectBuilder(moduleName)
- .addAnnotation(ClassName("dagger", "Module"))
- .addAnnotation(
- AnnotationSpec.builder(ClassName("javax.annotation.processing", "Generated"))
- .addMember("value = [%S]", this::class.qualifiedName!!)
- .build()
- )
- .addFunctions(bindings)
- .build()
-
- return FileSpec.builder(moduleName)
- .addType(moduleObject)
- .build()
-
- }
-
- private fun processAnnotation(resolver: Resolver, annotation: KSClassDeclaration) {
- val args = annotation.annotations.first {
- it.shortName.getShortName() == "GenerateSetMultibindingsModule"
- }.arguments.takeIf { it.size == 3 } ?: run {
- logger.error("GenerateSetMultibindingsModule should have 3 arguments")
- throw IllegalArgumentException()
- }
-
- val interfaceName = args.first { it.name?.getShortName() == "interfaceClass" }.value as KSType
- val modulePackage = args.first { it.name?.getShortName() == "modulePackage" }.value as String
- val moduleName = args.first { it.name?.getShortName() == "moduleName" }.value as String
-
- val moduleClassName = ClassName(modulePackage, moduleName)
- val elements = resolver.getSymbolsWithAnnotation(annotation.qualifiedName!!.asString())
- .filterIsInstance<KSClassDeclaration>()
- .map(KSClassDeclaration::toClassName)
- .toList()
-
- logger.info("Found elements: ${elements.joinToString()}")
-
- generateModule(
- interfaceName = interfaceName.toClassName(),
- moduleName = moduleClassName,
- classes = elements
- )?.writeTo(codeGenerator, Dependencies(true))
- }
-
- override fun process(resolver: Resolver): List<KSAnnotated> {
- val annotations = resolver.getAnnotatedClasses(GenerateSetMultibindingsModule::class.qualifiedName!!, logger)
- logger.info("Found annotations: ${annotations.joinToString { it.qualifiedName!!.asString() }}")
- annotations.forEach { processAnnotation(resolver, it) }
- return emptyList()
- }
-
-}
\ No newline at end of file
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/SymbolProcessorUtils.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/SymbolProcessorUtils.kt
--- a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/SymbolProcessorUtils.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package ru.fredboy.cavedroid.ksp.processor
-
-import com.google.devtools.ksp.processing.KSPLogger
-import com.google.devtools.ksp.processing.Resolver
-import com.google.devtools.ksp.symbol.KSClassDeclaration
-import com.google.devtools.ksp.symbol.KSNode
-import com.google.devtools.ksp.validate
-import kotlin.reflect.KClass
-
-internal fun Resolver.getAnnotatedClasses(
- annotation: String,
- logger: KSPLogger,
-): Sequence<KSClassDeclaration> {
- logger.info("Resolving annotation $annotation")
- return getSymbolsWithAnnotation(annotation)
- .filterIsInstance<KSClassDeclaration>()
- .filter(KSNode::validate)
-}
\ No newline at end of file
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateMapMultibindingsSymbolProcessorProvider.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateMapMultibindingsSymbolProcessorProvider.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package ru.fredboy.cavedroid.ksp.provider
-
-import com.google.devtools.ksp.processing.SymbolProcessor
-import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
-import com.google.devtools.ksp.processing.SymbolProcessorProvider
-import ru.fredboy.cavedroid.ksp.processor.GenerateMapMultibindingsSymbolProcessor
-
-internal class GenerateMapMultibindingsSymbolProcessorProvider : SymbolProcessorProvider {
-
- override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
- return GenerateMapMultibindingsSymbolProcessor(
- codeGenerator = environment.codeGenerator,
- logger = environment.logger,
- )
- }
-
-}
\ No newline at end of file
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateSetMultibindingsSymbolProcessorProvider.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateSetMultibindingsSymbolProcessorProvider.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package ru.fredboy.cavedroid.ksp.provider
-
-import com.google.devtools.ksp.processing.SymbolProcessor
-import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
-import com.google.devtools.ksp.processing.SymbolProcessorProvider
-import ru.fredboy.cavedroid.ksp.processor.GenerateSetMultibindingsSymbolProcessor
-
-internal class GenerateSetMultibindingsSymbolProcessorProvider : SymbolProcessorProvider {
-
- override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
- return GenerateSetMultibindingsSymbolProcessor(
- codeGenerator = environment.codeGenerator,
- logger = environment.logger,
- )
- }
-
-}
\ No newline at end of file
diff --git a/dagger-multibind-ksp/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/dagger-multibind-ksp/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
+++ /dev/null
@@ -1,2 +0,0 @@
-ru.fredboy.cavedroid.ksp.provider.GenerateSetMultibindingsSymbolProcessorProvider
-ru.fredboy.cavedroid.ksp.provider.GenerateMapMultibindingsSymbolProcessorProvider
diff --git a/settings.gradle b/settings.gradle
index c441146968383ca2536e679ad206c33dd4fac27a..99367dfdf5483f85e79b409e35994d0e70fa1892 100644 (file)
--- a/settings.gradle
+++ b/settings.gradle
-plugins {
- id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
-}
-
include 'desktop', 'android', 'core'
-include 'dagger-multibind-annotations'
-include 'dagger-multibind-ksp'