@@ -12,6 +12,7 @@ import com.google.devtools.ksp.processing.SymbolProcessorProvider
12
12
import com.google.devtools.ksp.symbol.KSAnnotated
13
13
import com.google.devtools.ksp.symbol.KSClassDeclaration
14
14
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
15
+ import com.google.devtools.ksp.symbol.Modifier
15
16
import com.squareup.kotlinpoet.ARRAY
16
17
import com.squareup.kotlinpoet.AnnotationSpec
17
18
import com.squareup.kotlinpoet.ClassName
@@ -118,7 +119,28 @@ class MainProcessor(
118
119
FunSpec .builder(it.simpleName.asString())
119
120
.addAnnotation(ClassName (" kotlinx.benchmark" , " Benchmark" ))
120
121
.returns(it.returnType?.resolve()?.toTypeName() ? : UNIT )
121
- .addStatement(" return %T(lines).%N()" , container.toClassName(), it.simpleName.asString())
122
+ .addCode(
123
+ buildCodeBlock {
124
+ if (Modifier .SUSPEND in it.modifiers) {
125
+ beginControlFlow(
126
+ " return %M" ,
127
+ MemberName (" kotlinx.coroutines" , " runBlocking" )
128
+ )
129
+ addStatement(
130
+ " %T(lines).%N()" ,
131
+ container.toClassName(),
132
+ it.simpleName.asString(),
133
+ )
134
+ endControlFlow()
135
+ } else {
136
+ addStatement(
137
+ " return %T(lines).%N()" ,
138
+ container.toClassName(),
139
+ it.simpleName.asString(),
140
+ )
141
+ }
142
+ }
143
+ )
122
144
.build()
123
145
}.orEmpty()
124
146
)
0 commit comments