Skip to content

Commit

Permalink
Fix named accessor code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSrSouza committed Sep 15, 2024
1 parent b58cb3c commit 0dc8f21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "br.com.devsrsouza"
version = "0.10.0"
version = "0.11.0-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,24 @@ class AllIconAccessorGenerator(
// preventing that a asset has the name List and conflict with Kotlin List import
fileSpec.addAliasedImport(map, "____KtMap")

val allAssetsNamedPropertyName = "${allAssetsPropertyName}Named"

val allIconsType = map.parameterizedBy(STRING, ClassNames.ImageVector)
val allIconsBackingProperty = backingPropertySpec("__${allAssetsPropertyName}Named", allIconsType)
val allIconsBackingProperty = backingPropertySpec("__$allAssetsNamedPropertyName", allIconsType)

val allIconsParametersFromGroups = childGroups.map { "%M.${allAssetsPropertyName}Named.mapKeys { \"\${%M.groupName}.\${it.key}\"}" }
val allIconsParametersFromGroups = childGroups.map { "%M.$allAssetsNamedPropertyName.mapKeys { \"\${%M.groupName}.\${it.key}\"}" }

val allIconsParameters = iconProperties.map { "${it.simpleName.lowercase()} to %M" }
// adding import to `AllAssetsNamed`
childGroups.forEach {
fileSpec.addImport(it.groupPackage, allAssetsNamedPropertyName)
fileSpec.addImport(it.groupPackage, "groupName")
}

val allIconsParameters = iconProperties.map { "\"${it.simpleName.lowercase()}\" to %M" }
val parameters = allIconsParameters.joinToString(prefix = "(", postfix = ")")
val childGroupsParameters = allIconsParametersFromGroups.joinToString(" + ")

val allIconProperty = PropertySpec.builder(allAssetsPropertyName, allIconsType)
val allIconProperty = PropertySpec.builder(allAssetsNamedPropertyName, allIconsType)
.receiver(accessClass)
.getter(FunSpec.getterBuilder().withBackingProperty(allIconsBackingProperty) {
addStatement(
Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fun main() {
vectorsDirectory = iconTest,
iconNameTransformer = { name, group ->
name.removeSuffix(group, ignoreCase = true)
}
},
generatePreview = true,
generateStringAccessor = true,
)
}

Expand Down

0 comments on commit 0dc8f21

Please sign in to comment.