This file contains hidden or 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
| plugins { | |
| //... | |
| id("com.google.devtools.ksp") version "1.6.10-1.0.2" | |
| //... | |
| } | |
| android { | |
| //... | |
| sourceSets { | |
| val main by getting |
This file contains hidden or 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
| class StickyStateVisitor( | |
| private val saveCodeList: MutableList<String>, | |
| private val restoreCodeList: MutableList<String>, | |
| private val logger: KSPLogger, | |
| ): KSVisitorVoid() { | |
| override fun visitPropertyDeclaration(property: KSPropertyDeclaration, data: Unit) { | |
| val propertyName = property.simpleName.asString() | |
| val resolvedType = property.type.resolve() | |
| val propertyType = resolvedType.declaration.simpleName.asString() |
This file contains hidden or 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
| private fun generateBinding( | |
| ownerClassName: String, | |
| sourceFiles: Array<KSFile>, | |
| propertyDeclarations: List<KSPropertyDeclaration> | |
| ): List<KSPropertyDeclaration> { | |
| // ... | |
| outputStream.use { | |
| with(CodeLoom(it)) { |
This file contains hidden or 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
| private fun generateBinding( | |
| ownerClassName: String, | |
| propertyDeclarations: List<KSPropertyDeclaration>, | |
| sourceFiles: Array<KSFile>, | |
| ): List<KSPropertyDeclaration> { | |
| val ownerPackageName = ownerClassName.substringBeforeLast(".") | |
| val ownerClassSimpleName = ownerClassName.substringAfterLast(".") | |
| val bindingClassName = "${ownerClassSimpleName}StateBinding" | |
| val saveCodeList = mutableListOf<String>() |
This file contains hidden or 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
| override fun process(resolver: Resolver): List<KSAnnotated> { | |
| // ... | |
| return symbolMap.flatMap { (ownerClassName, propertyDeclarations) -> | |
| val containingFile = symbolMap[ownerClassName]?.getOrNull(0)?.containingFile | |
| generateBinding(resolver, ownerClassName, containingFile, propertyDeclarations) | |
| } | |
| } |
This file contains hidden or 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
| override fun process(resolver: Resolver): List<KSAnnotated> { | |
| val symbolMap = resolver | |
| .getSymbolsWithAnnotation(STICKY_ANNOTATION_NAME) | |
| .filterIsInstance<KSPropertyDeclaration>() | |
| .groupBy { | |
| resolver.getOwnerJvmClassName(it) ?: run { | |
| logger.warn("Failed to find class name of property $it") | |
| return emptyList() | |
| } | |
| } |
This file contains hidden or 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
| class StickyStateProcessorProvider: SymbolProcessorProvider { | |
| override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { | |
| return StickyStateProcessor( | |
| codeGenerator = environment.codeGenerator, | |
| logger = environment.logger, | |
| options = environment.options, | |
| ) | |
| } | |
| } |
This file contains hidden or 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
| plugins { | |
| kotlin("jvm") | |
| } | |
| dependencies { | |
| implementation(project(":core")) | |
| implementation("com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2") | |
| } |
This file contains hidden or 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
| buildscript { | |
| repositories { | |
| gradlePluginPortal() | |
| google() | |
| mavenCentral() | |
| } | |
| dependencies { | |
| classpath("com.android.tools.build:gradle:7.0.4") | |
| classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10") |
This file contains hidden or 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
| class StickyStateProcessor( | |
| private val codeGenerator: CodeGenerator, | |
| private val logger: KSPLogger, | |
| private val options: Map<String, String>, | |
| ) : SymbolProcessor { | |
| override fun process(resolver: Resolver): List<KSAnnotated> { | |
| return emptyList() | |
| } | |
| } |