Skip to content

Commit

Permalink
Refactor EasyStore API (#6)
Browse files Browse the repository at this point in the history
* Improved EasyStore API

* Improved EasyStore API (2)

* Code cleanup
  • Loading branch information
kasem-sm authored Aug 22, 2022
1 parent b40d5ba commit c52eb9b
Show file tree
Hide file tree
Showing 20 changed files with 606 additions and 237 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea
.DS_Store
/build
/captures
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ subprojects {
kotlin {
licenseHeaderFile project.rootProject.file('spotless/copyright.kt')
target "**/*.kt"
ktlint().editorConfigOverride(['android': 'true', 'max_line_length': '200'])
}
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
Expand Down
1 change: 1 addition & 0 deletions buildSrc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/LibraryConfigs.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object LibraryConfigs {
const val groupId = "com.kasem-sm.easystore"
const val version = "0.0.1-alpha"
const val version = "0.0.2-alpha"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ package kasem.sm.easystore.core

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class EasyStore()
annotation class EasyStore
11 changes: 11 additions & 0 deletions easystore-core/src/main/java/kasem/sm/easystore/core/Retrieve.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (C) 2022, Kasem S.M
* All rights reserved.
*/
package kasem.sm.easystore.core

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.SOURCE)
annotation class Retrieve(
val preferenceKeyName: String
)
5 changes: 2 additions & 3 deletions easystore-core/src/main/java/kasem/sm/easystore/core/Store.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
*/
package kasem.sm.easystore.core

@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class Store(
val preferenceKeyName: String,
val getterFunctionName: String
val preferenceKeyName: String
)
12 changes: 9 additions & 3 deletions easystore-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ sourceSets.main {
java.srcDirs("src/main/kotlin")
}

dependencies {
implementation("androidx.datastore:datastore-preferences-core:1.0.0")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}

dependencies {
implementation(project(":easystore-core"))
implementation("com.google.devtools.ksp:symbol-processing-api:1.7.10-1.0.6")

implementation("androidx.datastore:datastore-preferences-core:1.0.0")
implementation("com.google.devtools.ksp:symbol-processing-api:1.7.10-1.0.6")

implementation("com.squareup:kotlinpoet:1.12.0")
implementation("com.squareup:kotlinpoet-ksp:1.12.0")

implementation("com.google.auto.service:auto-service-annotations:1.0")
ksp("dev.zacsweers.autoservice:auto-service-ksp:1.0.0")

testImplementation("junit:junit:4.13.2")
}

rootProject.extra.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ class StoreProcessor(
.forEach {
visitor = StoreVisitor(logger)
it.accept(visitor, Unit)
storeFileGenerator = StoreFileGenerator(visitor)
try {
storeFileGenerator.fileSpec.build()
.writeTo(codeGenerator = codeGenerator, aggregating = false)
} catch (e: FileAlreadyExistsException) {
logger.logging(e.message.toString())
} catch (e: Exception) {
logger.error(e.message.toString())
}
}

if (::visitor.isInitialized) {
storeFileGenerator = StoreFileGenerator(visitor)

try {
storeFileGenerator.fileSpec.build().writeTo(codeGenerator = codeGenerator, aggregating = false)
} catch (e: FileAlreadyExistsException) {
logger.logging(e.message.toString())
} catch (e: Exception) {
logger.error(e.message.toString())
}

unresolvedSymbols = resolved - validatedSymbols.toSet()
}
unresolvedSymbols = resolved - validatedSymbols.toSet()
}
return unresolvedSymbols
}
Expand Down
Loading

0 comments on commit c52eb9b

Please sign in to comment.