From: fredboy Date: Tue, 14 May 2024 21:44:26 +0000 (+0700) Subject: Use my automultibind lib X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=d01792885c45d3c027e96bf5bf51f00492f600de;p=cavedroid.git Use my automultibind lib --- diff --git a/core/build.gradle b/core/build.gradle index 0cff94f..7aff468 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -13,8 +13,8 @@ java.sourceCompatibility = JavaVersion.VERSION_17 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 004012d..558dc96 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindKeyboardInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindKeyboardInputHandler.kt @@ -1,9 +1,9 @@ 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 02b934c..af9b608 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindMouseInputHandler.kt @@ -1,9 +1,9 @@ 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 779835f..89f2dd0 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindPlaceBlockAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindPlaceBlockAction.kt @@ -1,9 +1,9 @@ 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 ae994ea..c1d96a9 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindRenderer.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindRenderer.kt @@ -1,9 +1,9 @@ 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 8665ec1..310d69e 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUpdateBlockAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUpdateBlockAction.kt @@ -1,9 +1,9 @@ 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 b34214d..46353ca 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseBlockAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseBlockAction.kt @@ -1,9 +1,9 @@ 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 de2c74f..7f17bfc 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseItemAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/annotations/multibinding/BindUseItemAction.kt @@ -1,9 +1,9 @@ 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 deleted file mode 100644 index 27133f0..0000000 --- a/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 deleted file mode 100644 index 7a5b023..0000000 --- a/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 deleted file mode 100644 index 2fb4915..0000000 --- a/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 deleted file mode 100644 index e73405d..0000000 --- a/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 deleted file mode 100644 index 860653f..0000000 --- a/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 - ): 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() - .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 { - 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 deleted file mode 100644 index 6bcb60c..0000000 --- a/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 - ): 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() - .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 { - 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 deleted file mode 100644 index 1ac8a6a..0000000 --- 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 { - logger.info("Resolving annotation $annotation") - return getSymbolsWithAnnotation(annotation) - .filterIsInstance() - .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 deleted file mode 100644 index 49ea948..0000000 --- a/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 deleted file mode 100644 index c8f4e15..0000000 --- a/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 deleted file mode 100644 index b646e9d..0000000 --- a/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 c441146..99367df 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,2 @@ -plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' -} - include 'desktop', 'android', 'core' -include 'dagger-multibind-annotations' -include 'dagger-multibind-ksp'