@@ -27,13 +27,17 @@ import kotlin.reflect.KClass
2727class KElementConverter (
2828 private val logger : KSPLogger ,
2929 private val builtIns : KSBuiltIns ,
30- private val byteArrayType : KSType
30+ private val byteArrayType : KSType ,
3131) : KSDefaultVisitor<Service.Builder, Unit>() {
3232 companion object {
3333 private val SUPPORTED_CLASS_KIND : Set <ClassKind > = setOf (ClassKind .CLASS , ClassKind .INTERFACE )
3434 private val EMPTY_PAYLOAD : PayloadType =
3535 PayloadType (
36- true , " " , " Unit" , " dev.restate.serde.kotlinx.KotlinSerializationSerdeFactory.UNIT" )
36+ true ,
37+ " " ,
38+ " Unit" ,
39+ " dev.restate.serde.kotlinx.KotlinSerializationSerdeFactory.UNIT" ,
40+ )
3741 private const val RAW_SERDE : String = " dev.restate.serde.Serde.RAW"
3842 }
3943
@@ -42,7 +46,8 @@ class KElementConverter(
4246 override fun visitAnnotated (annotated : KSAnnotated , data : Service .Builder ) {
4347 if (annotated !is KSClassDeclaration ) {
4448 logger.error(
45- " Only classes or interfaces can be annotated with @Service or @VirtualObject or @Workflow" )
49+ " Only classes or interfaces can be annotated with @Service or @VirtualObject or @Workflow"
50+ )
4651 }
4752 visitClassDeclaration(annotated as KSClassDeclaration , data)
4853 }
@@ -56,7 +61,8 @@ class KElementConverter(
5661 if (! SUPPORTED_CLASS_KIND .contains(classDeclaration.classKind)) {
5762 logger.error(
5863 " The ServiceProcessor supports only class declarations of kind $SUPPORTED_CLASS_KIND " ,
59- classDeclaration)
64+ classDeclaration,
65+ )
6066 }
6167 if (classDeclaration.getVisibility() == Visibility .PRIVATE ) {
6268 logger.error(" The annotated class is private" , classDeclaration)
@@ -94,7 +100,8 @@ class KElementConverter(
94100 if (data.handlers.isEmpty()) {
95101 logger.warn(
96102 " The class declaration $targetFqcn has no methods annotated as handlers" ,
97- classDeclaration)
103+ classDeclaration,
104+ )
98105 }
99106
100107 var serdeFactoryDecl = " dev.restate.serde.kotlinx.KotlinSerializationSerdeFactory()"
@@ -134,7 +141,8 @@ class KElementConverter(
134141 if (! (! hasAnyAnnotation || hasExactlyOneAnnotation)) {
135142 logger.error(
136143 " You can have only one annotation between @Shared and @Exclusive and @Workflow to a method" ,
137- function)
144+ function,
145+ )
138146 }
139147
140148 val handlerBuilder = Handler .builder()
@@ -158,7 +166,8 @@ class KElementConverter(
158166 .withInputAccept(inputAcceptFromParameterList(function.parameters))
159167 .withInputType(inputPayloadFromParameterList(function.parameters))
160168 .withOutputType(outputPayloadFromExecutableElement(function))
161- .validateAndBuild())
169+ .validateAndBuild()
170+ )
162171 } catch (e: Exception ) {
163172 logger.error(" Error when building handler: $e " , function)
164173 }
@@ -184,7 +193,8 @@ class KElementConverter(
184193 parameterElement.type.resolve(),
185194 parameterElement.getAnnotationsByType(Json ::class ).firstOrNull(),
186195 parameterElement.getAnnotationsByType(Raw ::class ).firstOrNull(),
187- parameterElement)
196+ parameterElement,
197+ )
188198 }
189199
190200 @OptIn(KspExperimental ::class )
@@ -193,14 +203,15 @@ class KElementConverter(
193203 fn.returnType?.resolve() ? : builtIns.unitType,
194204 fn.getAnnotationsByType(Json ::class ).firstOrNull(),
195205 fn.getAnnotationsByType(Raw ::class ).firstOrNull(),
196- fn)
206+ fn,
207+ )
197208 }
198209
199210 private fun payloadFromTypeMirrorAndAnnotations (
200211 ty : KSType ,
201212 jsonAnnotation : Json ? ,
202213 rawAnnotation : Raw ? ,
203- relatedNode : KSNode
214+ relatedNode : KSNode ,
204215 ): PayloadType {
205216 if (ty == builtIns.unitType) {
206217 if (rawAnnotation != null || jsonAnnotation != null ) {
@@ -222,12 +233,16 @@ class KElementConverter(
222233 val qualifiedTypeName = qualifiedTypeName(ty)
223234 var serdeDecl: String =
224235 if (rawAnnotation != null ) RAW_SERDE else jsonSerdeDecl(ty, qualifiedTypeName)
225- if (rawAnnotation != null &&
226- rawAnnotation.contentType != getAnnotationDefaultValue(Raw ::class .java, " contentType" )) {
236+ if (
237+ rawAnnotation != null &&
238+ rawAnnotation.contentType != getAnnotationDefaultValue(Raw ::class .java, " contentType" )
239+ ) {
227240 serdeDecl = contentTypeDecoratedSerdeDecl(serdeDecl, rawAnnotation.contentType)
228241 }
229- if (jsonAnnotation != null &&
230- jsonAnnotation.contentType != getAnnotationDefaultValue(Json ::class .java, " contentType" )) {
242+ if (
243+ jsonAnnotation != null &&
244+ jsonAnnotation.contentType != getAnnotationDefaultValue(Json ::class .java, " contentType" )
245+ ) {
231246 serdeDecl = contentTypeDecoratedSerdeDecl(serdeDecl, jsonAnnotation.contentType)
232247 }
233248
@@ -249,12 +264,13 @@ class KElementConverter(
249264 private fun validateMethodSignature (
250265 serviceType : ServiceType ,
251266 handlerType : HandlerType ,
252- function : KSFunctionDeclaration
267+ function : KSFunctionDeclaration ,
253268 ) {
254269 if (function.parameters.isEmpty()) {
255270 logger.error(
256271 " The annotated method has no parameters. There must be at least the context parameter as first parameter" ,
257- function)
272+ function,
273+ )
258274 }
259275 when (handlerType) {
260276 HandlerType .SHARED ->
@@ -265,15 +281,17 @@ class KElementConverter(
265281 } else {
266282 logger.error(
267283 " The annotation @Shared is not supported by the service type $serviceType " ,
268- function)
284+ function,
285+ )
269286 }
270287 HandlerType .EXCLUSIVE ->
271288 if (serviceType == ServiceType .VIRTUAL_OBJECT ) {
272289 validateFirstParameterType(ObjectContext ::class , function)
273290 } else {
274291 logger.error(
275292 " The annotation @Exclusive is not supported by the service type $serviceType " ,
276- function)
293+ function,
294+ )
277295 }
278296 HandlerType .STATELESS -> validateFirstParameterType(Context ::class , function)
279297 HandlerType .WORKFLOW ->
@@ -282,17 +300,21 @@ class KElementConverter(
282300 } else {
283301 logger.error(
284302 " The annotation @Workflow is not supported by the service type $serviceType " ,
285- function)
303+ function,
304+ )
286305 }
287306 }
288307 }
289308
290309 private fun validateFirstParameterType (clazz : KClass <* >, function : KSFunctionDeclaration ) {
291- if (function.parameters[0 ].type.resolve().declaration.qualifiedName!! .asString() !=
292- clazz.qualifiedName) {
310+ if (
311+ function.parameters[0 ].type.resolve().declaration.qualifiedName!! .asString() !=
312+ clazz.qualifiedName
313+ ) {
293314 logger.error(
294315 " The method signature must have ${clazz.qualifiedName} as first parameter, was ${function.parameters[0 ].type.resolve().declaration.qualifiedName!! .asString()} " ,
295- function)
316+ function,
317+ )
296318 }
297319 }
298320
0 commit comments