|
18 | 18 | import static com.sun.codemodel.JExpr._new; |
19 | 19 | import static com.sun.codemodel.JExpr.lit; |
20 | 20 |
|
21 | | -import java.lang.annotation.Annotation; |
22 | 21 | import javax.lang.model.element.Element; |
23 | 22 | import javax.lang.model.element.ExecutableElement; |
24 | 23 |
|
|
30 | 29 | import com.sun.codemodel.JClassAlreadyExistsException; |
31 | 30 | import com.sun.codemodel.JCodeModel; |
32 | 31 | import com.sun.codemodel.JDefinedClass; |
33 | | -import com.sun.codemodel.JExpr; |
34 | 32 | import com.sun.codemodel.JInvocation; |
35 | 33 | import com.sun.codemodel.JMethod; |
36 | | -import com.sun.codemodel.JMod; |
37 | 34 |
|
38 | 35 | public class BackgroundProcessor implements DecoratingElementProcessor { |
39 | 36 |
|
@@ -61,19 +58,16 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t |
61 | 58 | long delay = annotation.delay(); |
62 | 59 |
|
63 | 60 | JClass backgroundExecutorClass = holder.refClass(BackgroundExecutor.class); |
64 | | - JInvocation executeCall = backgroundExecutorClass.staticInvoke("execute").arg(_new(anonymousRunnableClass)); |
| 61 | + JInvocation executeCall; |
65 | 62 |
|
66 | 63 | if (delay == 0) { |
67 | | - delegatingMethod.body().add(executeCall); |
| 64 | + executeCall = backgroundExecutorClass.staticInvoke("execute").arg(_new(anonymousRunnableClass)); |
68 | 65 | } else { |
69 | | - JDefinedClass anonymousExecutorRunnableClass = helper.createAnonymousRunnableClass(holder, executeCall); |
70 | | - if (holder.handler == null) { |
71 | | - JClass handlerClass = holder.classes().HANDLER; |
72 | | - holder.handler = holder.generatedClass.field(JMod.PRIVATE, handlerClass, "handler_", _new(handlerClass)); |
73 | | - } |
74 | | - delegatingMethod.body().invoke(holder.handler, "postDelayed").arg(_new(anonymousExecutorRunnableClass)).arg(lit(delay)); |
| 66 | + executeCall = backgroundExecutorClass.staticInvoke("executeDelayed").arg(_new(anonymousRunnableClass)).arg(lit(delay)); |
75 | 67 | } |
76 | 68 |
|
| 69 | + delegatingMethod.body().add(executeCall); |
| 70 | + |
77 | 71 | } |
78 | 72 |
|
79 | 73 | } |
|
0 commit comments