1515 */
1616package org .androidannotations .handler ;
1717
18- import static com .sun .codemodel .JExpr ._new ;
19- import static com .sun .codemodel .JExpr .lit ;
18+ import com .sun .codemodel .*;
19+ import org .androidannotations .annotations .UiThread ;
20+ import org .androidannotations .helper .APTCodeModelHelper ;
21+ import org .androidannotations .holder .EComponentHolder ;
2022
2123import javax .annotation .processing .ProcessingEnvironment ;
2224import javax .lang .model .element .Element ;
2325import javax .lang .model .element .ExecutableElement ;
2426
25- import org .androidannotations .annotations .UiThread ;
26- import org .androidannotations .helper .APTCodeModelHelper ;
27- import org .androidannotations .holder .EComponentHolder ;
28-
29- import com .sun .codemodel .JBlock ;
30- import com .sun .codemodel .JClass ;
31- import com .sun .codemodel .JClassAlreadyExistsException ;
32- import com .sun .codemodel .JConditional ;
33- import com .sun .codemodel .JDefinedClass ;
34- import com .sun .codemodel .JExpression ;
35- import com .sun .codemodel .JMethod ;
36- import com .sun .codemodel .JOp ;
27+ import static com .sun .codemodel .JExpr ._new ;
28+ import static com .sun .codemodel .JExpr .lit ;
3729
3830public class UiThreadHandler extends AbstractRunnableHandler {
3931
@@ -51,7 +43,8 @@ public UiThreadHandler(ProcessingEnvironment processingEnvironment) {
5143 public void process (Element element , EComponentHolder holder ) throws Exception {
5244 ExecutableElement executableElement = (ExecutableElement ) element ;
5345 JMethod delegatingMethod = codeModelHelper .overrideAnnotatedMethod (executableElement , holder );
54- JDefinedClass anonymousRunnableClass = codeModelHelper .createDelegatingAnonymousRunnableClass (holder , delegatingMethod );
46+ JBlock previousBody = codeModelHelper .removeBody (delegatingMethod );
47+ JDefinedClass anonymousRunnableClass = codeModelHelper .createDelegatingAnonymousRunnableClass (holder , previousBody );
5548
5649 UiThread annotation = element .getAnnotation (UiThread .class );
5750 long delay = annotation .delay ();
@@ -60,7 +53,7 @@ public void process(Element element, EComponentHolder holder) throws Exception {
6053 if (delay == 0 ) {
6154 if (propagation == UiThread .Propagation .REUSE ) {
6255 // Put in the check for the UI thread.
63- addUIThreadCheck (delegatingMethod , holder );
56+ addUIThreadCheck (delegatingMethod , previousBody , holder );
6457 }
6558
6659 delegatingMethod .body ().invoke (holder .getHandler (), "post" ).arg (_new (anonymousRunnableClass ));
@@ -76,7 +69,7 @@ public void process(Element element, EComponentHolder holder) throws Exception {
7669 * @param holder
7770 * @throws JClassAlreadyExistsException
7871 */
79- private void addUIThreadCheck (JMethod delegatingMethod , EComponentHolder holder ) throws JClassAlreadyExistsException {
72+ private void addUIThreadCheck (JMethod delegatingMethod , JBlock previousBody , EComponentHolder holder ) throws JClassAlreadyExistsException {
8073 // Get the Thread and Looper class.
8174 JClass tClass = holder .classes ().THREAD ;
8275 JClass lClass = holder .classes ().LOOPER ;
@@ -87,10 +80,7 @@ private void addUIThreadCheck(JMethod delegatingMethod, EComponentHolder holder)
8780
8881 // create the conditional and the block.
8982 JConditional con = delegatingMethod .body ()._if (JOp .eq (lhs , rhs ));
90- JBlock thenBlock = con ._then ();
91-
92- codeModelHelper .callSuperMethod (delegatingMethod , holder , thenBlock );
93-
83+ JBlock thenBlock = con ._then ().add (previousBody );
9484 thenBlock ._return ();
9585 }
9686}
0 commit comments