@@ -5,6 +5,7 @@ import com.google.devtools.ksp.processing.Dependencies
5
5
import com.google.devtools.ksp.processing.KSPLogger
6
6
import com.google.devtools.ksp.impl.symbol.kotlin.KSPropertyDeclarationImpl
7
7
import com.google.devtools.ksp.symbol.KSAnnotation
8
+ import com.google.devtools.ksp.symbol.KSFile
8
9
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
9
10
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
10
11
import com.google.devtools.ksp.symbol.KSValueArgument
@@ -33,6 +34,8 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
33
34
private val componentFunctions = mutableMapOf<String , MutableList <Pair <KSAnnotation , KSFunctionDeclaration >>>()
34
35
private val componentGroups = mutableMapOf<String , Pair <KSAnnotation , KSPropertyDeclarationImpl >>()
35
36
private val componentPackageMap = mutableMapOf<String , String >()
37
+ private val componentPackageProperty = mutableSetOf<KSFile >()
38
+ private val componentScreenFile = mutableSetOf<KSFile >()
36
39
37
40
private val componentPackage = " io.github.jpy.wangposefluent.gallery.component"
38
41
private val componentItemClass = ClassName (componentPackage, " ComponentItem" )
@@ -52,19 +55,12 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
52
55
private fun arrangeComponentGroup () {
53
56
val mapPackage = componentFunctions.remove(" /_Auto" ) ? : emptyList()
54
57
mapPackage.forEach { pair ->
55
- val group = componentPackageMap[pair.second.packageName.asString()]
56
- if (! group.isNullOrEmpty()) {
57
- val list =
58
- componentFunctions[group] ? : mutableListOf<Pair <KSAnnotation , KSFunctionDeclaration >>().apply {
59
- componentFunctions[group] = this
60
- }
61
- list.add(pair)
62
- } else {
63
- val list = componentFunctions[" /" ] ? : mutableListOf<Pair <KSAnnotation , KSFunctionDeclaration >>().apply {
64
- componentFunctions[" /" ] = this
65
- }
66
- list.add(pair)
58
+ val group = componentPackageMap[pair.second.packageName.asString()].let {
59
+ if (it.isNullOrEmpty()) " /" else it
67
60
}
61
+ componentFunctions
62
+ .getOrPut(group) { mutableListOf () }
63
+ .add(pair)
68
64
}
69
65
}
70
66
@@ -79,11 +75,10 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
79
75
}
80
76
}
81
77
val group = (groupArg?.value as ? String )?.prefixIfNot(" /" ) ? : return @forEach
82
- val list =
83
- componentFunctions[group] ? : mutableListOf<Pair <KSAnnotation , KSFunctionDeclaration >>().apply {
84
- componentFunctions[group] = this
85
- }
86
- list.add(annotation to function)
78
+ componentFunctions
79
+ .getOrPut(group) { mutableListOf () }
80
+ .add(annotation to function)
81
+ componentScreenFile.add(function.containingFile ? : return )
87
82
return
88
83
}
89
84
}
@@ -99,6 +94,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
99
94
if (psi is KtProperty ) {
100
95
val groupName = psi.initializer?.text?.removePrefix(" \" " )?.removeSuffix(" \" " )?.prefixIfNot(" /" )
101
96
? : return
97
+ property.containingFile?.let { componentPackageProperty.add(it) }
102
98
componentGroups[groupName] = annotation to property
103
99
val packageNameValue =
104
100
annotation.arguments.firstOrNull { it.name?.asString() == " packageMap" }?.value as ? String
@@ -200,15 +196,15 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
200
196
.build()
201
197
)
202
198
val file = codeGenerator.createNewFile(
203
- Dependencies (true ),
199
+ Dependencies (aggregating = true , sources = componentPackageProperty.toTypedArray() ),
204
200
fileSpecBuilder.packageName,
205
201
fileSpecBuilder.name
206
202
)
207
203
val pathFileSpec = FileSpec .builder(
208
204
componentPackage, " ComponentPagePath"
209
205
).addType(componentPagePathType.build()).build()
210
206
val pathFile = codeGenerator.createNewFile(
211
- Dependencies (true ),
207
+ Dependencies (true , sources = componentScreenFile.toTypedArray() ),
212
208
componentPackage,
213
209
pathFileSpec.name
214
210
)
0 commit comments