|
25 | 25 |
|
26 | 26 | import javax.annotation.processing.ProcessingEnvironment; |
27 | 27 | import javax.inject.Provider; |
| 28 | +import javax.lang.model.element.AnnotationMirror; |
28 | 29 | import javax.lang.model.element.Element; |
29 | 30 | import javax.lang.model.element.ExecutableElement; |
30 | 31 | import javax.lang.model.element.TypeElement; |
@@ -177,16 +178,36 @@ private void apply(ClassWriter writer) throws Exception { |
177 | 178 | apply.visitEnd(); |
178 | 179 | } |
179 | 180 |
|
180 | | - private void processArguments(ClassWriter classWriter, MethodVisitor visitor) throws Exception { |
181 | | - for (VariableElement var : executable.getParameters()) { |
182 | | - visitor.visitVarInsn(ALOAD, 1); |
183 | | - ParamDefinition param = ParamDefinition.create(environment, var); |
184 | | - ParamWriter writer = param.newWriter(); |
185 | | - writer.accept(classWriter, getGeneratedInternalClass(), visitor, param); |
| 181 | + public boolean isSuspendFunction() { |
| 182 | + List<? extends VariableElement> parameters = executable.getParameters(); |
| 183 | + if (parameters.isEmpty()) { |
| 184 | + return false; |
186 | 185 | } |
| 186 | + VariableElement last = parameters.get(parameters.size() - 1); |
| 187 | + return isSuspendFunction(last); |
187 | 188 | } |
188 | 189 |
|
| 190 | + private boolean isSuspendFunction(VariableElement parameter) { |
| 191 | + String type = ParamDefinition.create(environment, parameter).getType().getRawType().toString(); |
| 192 | + return type.equals("kotlin.coroutines.Continuation"); |
| 193 | + } |
189 | 194 |
|
| 195 | + private void processArguments(ClassWriter classWriter, MethodVisitor visitor) throws Exception { |
| 196 | + for (VariableElement var : executable.getParameters()) { |
| 197 | + if (isSuspendFunction(var)) { |
| 198 | + visitor.visitVarInsn(ALOAD, 1); |
| 199 | + visitor.visitMethodInsn(INVOKEINTERFACE, "io/jooby/Context", "getAttributes", "()Ljava/util/Map;", true); |
| 200 | + visitor.visitLdcInsn("___continuation"); |
| 201 | + visitor.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "remove", "(Ljava/lang/Object;)Ljava/lang/Object;", true); |
| 202 | + visitor.visitTypeInsn(CHECKCAST, "kotlin/coroutines/Continuation"); |
| 203 | + } else { |
| 204 | + visitor.visitVarInsn(ALOAD, 1); |
| 205 | + ParamDefinition param = ParamDefinition.create(environment, var); |
| 206 | + ParamWriter writer = param.newWriter(); |
| 207 | + writer.accept(classWriter, getGeneratedInternalClass(), visitor, param); |
| 208 | + } |
| 209 | + } |
| 210 | + } |
190 | 211 |
|
191 | 212 | private void processReturnType(MethodVisitor visitor) throws Exception { |
192 | 213 | TypeKind kind = executable.getReturnType().getKind(); |
|
0 commit comments