Skip to content

Commit 03252f5

Browse files
committed
Add KSP-based @Patch annotation processor
Add `patch-processor` dependency to build script
1 parent ed41c67 commit 03252f5

14 files changed

Lines changed: 181 additions & 24 deletions

File tree

app/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
alias(libs.plugins.kotlin.android)
44
alias(libs.plugins.kotlin.compose)
55
alias(libs.plugins.kotlin.parcelize)
6+
alias(libs.plugins.ksp)
67
}
78

89
android {
@@ -56,6 +57,12 @@ dependencies {
5657
implementation(libs.androidx.adaptive)
5758
implementation(libs.androidx.adaptive.layout)
5859
implementation(libs.androidx.adaptive.navigation)
60+
61+
// Patch annotations + processor
62+
implementation(project(":patch-annotations"))
63+
implementation(project(":patch-processor"))
64+
ksp(project(":patch-processor"))
65+
5966
testImplementation(libs.junit)
6067
androidTestImplementation(libs.androidx.junit)
6168
androidTestImplementation(libs.androidx.espresso.core)
Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package de.berlindroid.zepatch
22

3-
import androidx.compose.foundation.text.BasicText
4-
import androidx.compose.runtime.Composable
5-
import de.berlindroid.zepatch.patchable.Demo
3+
import de.berlindroid.zepatch.generated.PatchRegistry
64

75
/**
86
* It's like Dagger, but way worse.
@@ -11,24 +9,5 @@ import de.berlindroid.zepatch.patchable.Demo
119
* hand-witten.
1210
*/
1311

14-
val patchables = mapOf<String, @Composable () -> Unit>(
15-
"Testing1" to { BasicText("123") },
16-
"Testing2" to { BasicText("123") },
17-
"Testing3" to { BasicText("123") },
18-
"Testing4" to { BasicText("123") },
19-
"Testing5" to { BasicText("123") },
20-
"Testing6" to { BasicText("123") },
21-
"Testing7" to { BasicText("123") },
22-
"Testing8" to { BasicText("123") },
23-
"Testing9" to { BasicText("123") },
24-
"Testing10" to { BasicText("123") },
25-
"Testing11" to { BasicText("123") },
26-
"Testing12" to { BasicText("123") },
27-
"Testing13" to { BasicText("123") },
28-
"Testing14" to { BasicText("123") },
29-
"Testing15" to { BasicText("123") },
30-
"Testing16" to { BasicText("123") },
31-
"Testing17" to { BasicText("123") },
32-
"Testing19" to { BasicText("123") },
33-
"Demo" to { Demo() },
34-
)
12+
// Generated via @Patch + KSP
13+
val patchables = PatchRegistry.patchables

app/src/main/java/de/berlindroid/zepatch/patchable/Demo.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import androidx.compose.runtime.Composable
77
import androidx.compose.ui.Modifier
88
import androidx.compose.ui.tooling.preview.Preview
99
import androidx.compose.ui.unit.dp
10+
import de.berlindroid.zepatch.annotations.Patch
1011

12+
@Patch("Demo")
1113
@Composable
1214
fun Demo(
1315
modifier: Modifier = Modifier,
@@ -17,6 +19,16 @@ fun Demo(
1719
}
1820
}
1921

22+
@Patch("Demo2")
23+
@Composable
24+
fun Demo2(
25+
modifier: Modifier = Modifier,
26+
) {
27+
SafeArea {
28+
Text("Another Demo")
29+
}
30+
}
31+
2032
// TODO: share this?
2133
@Composable
2234
fun SafeArea(

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ plugins {
44
alias(libs.plugins.kotlin.android) apply false
55
alias(libs.plugins.kotlin.compose) apply false
66
alias(libs.plugins.kotlin.parcelize) apply false
7+
alias(libs.plugins.kotlin.jvm) apply false
78
}

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[versions]
22
agp = "8.11.0"
33
kotlin = "2.2.0"
4+
ksp = "2.2.0-2.0.2"
45
coreKtx = "1.16.0"
56
junit = "4.13.2"
67
junitVersion = "1.2.1"
@@ -10,6 +11,8 @@ activityCompose = "1.10.1"
1011
composeBom = "2025.06.01"
1112

1213
[libraries]
14+
kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version = "2.1.0" }
15+
symbol-processing-api = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" }
1316
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
1417
junit = { group = "junit", name = "junit", version.ref = "junit" }
1518
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
@@ -33,4 +36,6 @@ android-application = { id = "com.android.application", version.ref = "agp" }
3336
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3437
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
3538
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
39+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
40+
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
3641

patch-annotations/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

patch-annotations/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.jvm)
3+
}
4+
5+
kotlin {
6+
jvmToolchain(21)
7+
}
8+
9+
dependencies {
10+
// no runtime deps needed
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package de.berlindroid.zepatch.annotations
2+
3+
@Target(AnnotationTarget.FUNCTION)
4+
@Retention(AnnotationRetention.SOURCE)
5+
annotation class Patch(
6+
val name: String = ""
7+
)

patch-processor/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

patch-processor/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.jvm)
3+
}
4+
5+
kotlin {
6+
jvmToolchain(21)
7+
}
8+
9+
dependencies {
10+
implementation(project(":patch-annotations"))
11+
implementation(libs.symbol.processing.api)
12+
implementation(libs.kotlinpoet)
13+
}

0 commit comments

Comments
 (0)