Skip to content

Commit

Permalink
Merge pull request #27
Browse files Browse the repository at this point in the history
Support immutable collections (#19)
  • Loading branch information
jayasuryat authored Apr 13, 2024
2 parents 5948252 + 3b39f29 commit 05fb3f5
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 126 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.activity:activity-compose:1.5.1'

implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")

// Dowel
implementation project(":dowel")
ksp project(":dowel-processor")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import com.jayasuryat.dowel.sample.ui.home.model.meta.SomeStaticInfo
import com.jayasuryat.dowel.sample.ui.home.model.sealed.Vehicle
import com.jayasuryat.dowel.sample.ui.home.model.status.Status
import com.jayasuryat.dowel.sample.ui.home.model.unsupported.UnsupportedType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.PersistentSet
import kotlinx.coroutines.flow.Flow

@DowelList(count = 5)
Expand Down Expand Up @@ -59,6 +65,12 @@ data class Person(
@Size(value = 1) val mutablePreferences: MutableMap<Long, Location>,
@Size(value = 2) val preferredLocations: Map<Long, Set<Location>>,
@Size(value = 2) val mutablePreferredLocations: Map<Long, MutableSet<Location>>,
@Size(value = 2) val immutableList: ImmutableList<Int>,
@Size(value = 2) val immutableSet: ImmutableSet<Int>,
@Size(value = 2) val immutableMap: ImmutableMap<Int, Int>,
@Size(value = 2) val persistentList: PersistentList<Int>,
@Size(value = 2) val persistentSet: PersistentSet<Int>,
@Size(value = 2) val persistentMap: PersistentMap<Int, Int>,
val title: Char,
@Size(value = 1) val interests: List<Float>,
val onClick: suspend (a: Person, b: Int) -> Unit,
Expand Down
31 changes: 0 additions & 31 deletions app/src/test/java/com/jayasuryat/dowel/sample/ExampleUnitTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.jayasuryat.dowel.annotation.Dowel
import com.jayasuryat.dowel.annotation.DowelList
import com.jayasuryat.dowel.processor.generator.DowelGenerator
import com.jayasuryat.dowel.processor.generator.DowelListGenerator
import com.jayasuryat.dowel.processor.model.ExistingDeclarations
import com.jayasuryat.dowel.processor.model.UserPredefinedParamProviderMapper
import com.jayasuryat.dowel.processor.model.UserPredefinedParamProviderMapper.ProcessedConsiderForDowelSymbols
import com.jayasuryat.dowel.processor.model.UserPredefinedParamProviders
Expand Down Expand Up @@ -69,6 +70,11 @@ internal class DowelSymbolProcessor(
codeGenerator = codeGenerator,
)
}
private val declarations: ExistingDeclarations by unsafeLazy {
ExistingDeclarations(
resolver = resolver,
)
}

/**
* Entry point into processing of symbols, called by Kotlin Symbol Processing to run the processing task.
Expand All @@ -81,7 +87,8 @@ internal class DowelSymbolProcessor(
resolver.processConsiderForDowelSymbols()

val invalidDowelSymbols: List<KSAnnotated> = resolver.processDowelSymbols(
predefinedProviders = considerForDowelSymbols.providers
predefinedProviders = considerForDowelSymbols.providers,
declarations = declarations,
)

val invalidDowelListSymbols: List<KSAnnotated> = resolver.processDowelListSymbols()
Expand All @@ -95,6 +102,7 @@ internal class DowelSymbolProcessor(
*/
private fun Resolver.processDowelSymbols(
predefinedProviders: UserPredefinedParamProviders,
declarations: ExistingDeclarations,
): List<KSAnnotated> {

val resolver = this
Expand All @@ -108,6 +116,7 @@ internal class DowelSymbolProcessor(

val dowelGenerator: DowelGenerator = DowelGenerator.createInstance(
predefinedProviders = predefinedProviders,
declarations = declarations,
)

// Triggering code generation for valid symbols
Expand Down Expand Up @@ -169,12 +178,14 @@ internal class DowelSymbolProcessor(
*/
private fun DowelGenerator.Companion.createInstance(
predefinedProviders: UserPredefinedParamProviders,
declarations: ExistingDeclarations,
): DowelGenerator {
return DowelGenerator(
resolver = resolver,
codeGenerator = codeGenerator,
logger = logger,
predefinedProviders = predefinedProviders
predefinedProviders = predefinedProviders,
declarations = declarations,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ internal object Names {
"MutableMap"
)

val persistentList: ClassName = ClassName(
packageName = "kotlinx.collections.immutable",
"PersistentList",
)

val persistentSet: ClassName = ClassName(
packageName = "kotlinx.collections.immutable",
"PersistentSet",
)

val persistentMap: ClassName = ClassName(
packageName = "kotlinx.collections.immutable",
"PersistentMap",
)

val sequenceName: ClassName = Sequence::class.asTypeName()

val previewParamProvider: ClassName = ClassName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.jayasuryat.dowel.processor.model.ClassRepresentation
import com.jayasuryat.dowel.processor.model.ClassRepresentation.ParameterSpec.DowelSpec
import com.jayasuryat.dowel.processor.model.ClassRepresentation.ParameterSpec.PreDefinedProviderSpec
import com.jayasuryat.dowel.processor.model.ClassRepresentationMapper
import com.jayasuryat.dowel.processor.model.ExistingDeclarations
import com.jayasuryat.dowel.processor.model.UserPredefinedParamProviders
import com.jayasuryat.dowel.processor.util.getEffectiveModuleVisibility
import com.jayasuryat.dowel.processor.util.unsafeLazy
Expand All @@ -54,13 +55,15 @@ internal class DowelGenerator(
private val codeGenerator: CodeGenerator,
private val logger: KSPLogger,
private val predefinedProviders: UserPredefinedParamProviders,
private val declarations: ExistingDeclarations,
) {

private val mapper: ClassRepresentationMapper by unsafeLazy {
ClassRepresentationMapper(
resolver = resolver,
logger = logger,
predefinedProviders = predefinedProviders,
declarations = declarations,
)
}
private val objectConstructor: ObjectConstructor by unsafeLazy { ObjectConstructor() }
Expand Down Expand Up @@ -265,6 +268,16 @@ internal class DowelGenerator(
spec.keySpec.getAllSupportingProvidersRecursively() +
spec.valueSpec.getAllSupportingProvidersRecursively()

is ClassRepresentation.ParameterSpec.PersistentListSpec ->
spec.elementSpec.getAllSupportingProvidersRecursively()

is ClassRepresentation.ParameterSpec.PersistentSetSpec ->
spec.elementSpec.getAllSupportingProvidersRecursively()

is ClassRepresentation.ParameterSpec.PersistentMapSpec ->
spec.keySpec.getAllSupportingProvidersRecursively() +
spec.valueSpec.getAllSupportingProvidersRecursively()

is ClassRepresentation.ParameterSpec.FlowSpec ->
spec.elementSpec.getAllSupportingProvidersRecursively()

Expand Down
Loading

0 comments on commit 05fb3f5

Please sign in to comment.