11package com.flyjingfish.module_communication_ksp
22
33import com.flyjingfish.module_communication_annotation.BindClass
4- import com.flyjingfish.module_communication_annotation.CommunicationPackage
54import com.flyjingfish.module_communication_annotation.ExposeBean
65import com.flyjingfish.module_communication_annotation.ExposeInterface
76import 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()
0 commit comments