-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
26 changed files
with
127 additions
and
172 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -119,3 +119,5 @@ Thumbs.db | |
|
||
release-*/ | ||
keystore.properties | ||
|
||
*/build/ |
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
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
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
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
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
10 changes: 10 additions & 0 deletions
10
core/src/ru/deadsoftware/cavedroid/game/render/GameRenderer.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 ru.deadsoftware.cavedroid.game.render | ||
|
||
import ru.fredboy.cavedroid.ksp.annotations.GenerateSetMultibindingsModule | ||
|
||
@GenerateSetMultibindingsModule( | ||
interfaceClass = IGameRenderer::class, | ||
modulePackage = "ru.deadsoftware.cavedroid.game.render", | ||
moduleName = "RenderModule" | ||
) | ||
annotation class GameRenderer |
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
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
59 changes: 0 additions & 59 deletions
59
core/src/ru/deadsoftware/cavedroid/game/render/RenderModule.kt
This file was deleted.
Oops, something went wrong.
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
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
11 changes: 11 additions & 0 deletions
11
...ns/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateSetMultibindingsModule.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,11 @@ | ||
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, | ||
) |
5 changes: 0 additions & 5 deletions
5
...otations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/actions/PlaceBlockAction.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...tations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/actions/UpdateBlockAction.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...nnotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/actions/UseBlockAction.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/actions/UseItemAction.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...ations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/input/KeyboardInputHandler.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...notations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/input/MouseInputHandler.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...ibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/render/Renderer.kt
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
...main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateSetMultibindingsSymbolProcessor.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,81 @@ | ||
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")) | ||
.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() | ||
} | ||
|
||
} |
66 changes: 0 additions & 66 deletions
66
...ltibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/RendererSymbolProcessor.kt
This file was deleted.
Oops, something went wrong.
9 changes: 5 additions & 4 deletions
9
...-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/SymbolProcessorUtils.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,17 +1,18 @@ | ||
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( | ||
packageName: String, | ||
annotationClass: KClass<*> | ||
annotation: String, | ||
logger: KSPLogger, | ||
): Sequence<KSClassDeclaration> { | ||
return getSymbolsWithAnnotation(annotationClass.qualifiedName.orEmpty()) | ||
logger.info("Resolving annotation $annotation") | ||
return getSymbolsWithAnnotation(annotation) | ||
.filterIsInstance<KSClassDeclaration>() | ||
.filter { it.packageName.getShortName() == packageName } | ||
.filter(KSNode::validate) | ||
} |
Oops, something went wrong.