Skip to content

Commit 7f04d01

Browse files
committed
完善生成帮助类位置,避免类名重复造成的问题
1 parent fd988a4 commit 7f04d01

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

module-communication-annotation/src/main/java/com/flyjingfish/module_communication_annotation/CommunicationPackage.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

module-communication-annotation/src/main/java/com/flyjingfish/module_communication_annotation/ImplementClassUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object ImplementClassUtils {
77
private val singleBean = ConcurrentHashMap<Class<out Any>,Any>()
88

99
fun <T> getNewInstance(key:Class<out Any>):T{
10-
val clazzName = "${CommunicationPackage.BIND_CLASS_PACKAGE}.${key.simpleName}\$\$BindClass"
10+
val clazzName = "${key.name}\$\$BindClass"
1111
val clazz = try {
1212
Class.forName(clazzName) as Class<out Any>
1313
} catch (e: ClassNotFoundException) {

module-communication-ksp/src/main/java/com/flyjingfish/module_communication_ksp/CommunicationKspSymbolProcessor.kt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.flyjingfish.module_communication_ksp
22

33
import com.flyjingfish.module_communication_annotation.BindClass
4-
import com.flyjingfish.module_communication_annotation.CommunicationPackage
54
import com.flyjingfish.module_communication_annotation.ExposeBean
65
import com.flyjingfish.module_communication_annotation.ExposeInterface
76
import com.flyjingfish.module_communication_annotation.ImplementClass
@@ -49,8 +48,9 @@ class CommunicationKspSymbolProcessor(
4948
val classMethodMap: MutableMap<String, Any?> =
5049
annotationMap["@ImplementClass"] ?: continue
5150

52-
val value: KSType? =
53-
if (classMethodMap["value"] != null) classMethodMap["value"] as KSType else null
51+
val value: KSType =
52+
(if (classMethodMap["value"] != null) classMethodMap["value"] as KSType else null)
53+
?: continue
5454
val targetClassName: String =
5555
(if (value != null) value.declaration.packageName.asString() + "." + value.toString() else null)
5656
?: continue
@@ -75,7 +75,7 @@ class CommunicationKspSymbolProcessor(
7575
.addStatement("return $symbol()")
7676

7777
typeBuilder.addFunction(whatsMyName1.build())
78-
writeToFile(typeBuilder, fileName, symbol)
78+
writeToFile(typeBuilder, value.declaration.packageName.asString(),fileName, symbol)
7979
}
8080
return symbols.filter { !it.validate() }.toList()
8181
}
@@ -157,22 +157,6 @@ class CommunicationKspSymbolProcessor(
157157
return isContainImplementClass
158158
}
159159

160-
private fun writeToFile(
161-
fileName: String, symbol: KSAnnotated, packageName: String, file: File
162-
) {
163-
FileInputStream(file).use { inputs ->
164-
val bytes = inputs.readAllBytes()
165-
codeGenerator
166-
.createNewFile(
167-
Dependencies(false, symbol.containingFile!!),
168-
packageName,
169-
fileName,
170-
"api"
171-
).write(bytes)
172-
}
173-
174-
}
175-
176160
private fun isImplementClass(
177161
symbol: KSAnnotated,
178162
className: String
@@ -217,18 +201,35 @@ class CommunicationKspSymbolProcessor(
217201
private fun whatsMyName(name: String): FunSpec.Builder {
218202
return FunSpec.builder(name).addModifiers(KModifier.FINAL)
219203
}
204+
205+
private fun writeToFile(
206+
fileName: String, symbol: KSAnnotated, packageName: String, file: File
207+
) {
208+
FileInputStream(file).use { inputs ->
209+
val bytes = inputs.readAllBytes()
210+
codeGenerator
211+
.createNewFile(
212+
Dependencies(false, symbol.containingFile!!),
213+
packageName,
214+
fileName,
215+
"api"
216+
).write(bytes)
217+
}
218+
219+
}
220220
private fun writeToFile(
221221
typeBuilder: TypeSpec.Builder,
222+
packageName: String,
222223
fileName: String,
223224
symbol: KSAnnotated
224225
) {
225226
val typeSpec = typeBuilder.build()
226-
val kotlinFile = FileSpec.builder(CommunicationPackage.BIND_CLASS_PACKAGE, fileName).addType(typeSpec)
227+
val kotlinFile = FileSpec.builder(packageName, fileName).addType(typeSpec)
227228
.build()
228229
codeGenerator
229230
.createNewFile(
230231
Dependencies(false, symbol.containingFile!!),
231-
CommunicationPackage.BIND_CLASS_PACKAGE,
232+
packageName,
232233
fileName
233234
)
234235
.writer()

module-communication-plugin/src/main/kotlin/com/flyjingfish/module_communication_plugin/Dom4jData.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ object Dom4jData {
111111
fun deleteElementLabel(xmlFile: File, resValue: ResValue) {
112112

113113
try {
114+
if (!xmlFile.exists()){
115+
return
116+
}
114117
//读取XML文件,获得document对象
115118
val reader = SAXReader()
116119
val document: Document = reader.read(xmlFile)

0 commit comments

Comments
 (0)