@Override
  public void process(Element element, EComponentHolder holder) throws Exception {
    ExecutableElement executableElement = (ExecutableElement) element;
    JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
    JBlock previousBody = codeModelHelper.removeBody(delegatingMethod);
    JDefinedClass anonymousRunnableClass =
        codeModelHelper.createDelegatingAnonymousRunnableClass(holder, previousBody);

    UiThread annotation = element.getAnnotation(UiThread.class);
    long delay = annotation.delay();
    UiThread.Propagation propagation = annotation.propagation();

    if (delay == 0) {
      if (propagation == UiThread.Propagation.REUSE) {
        // Put in the check for the UI thread.
        addUIThreadCheck(delegatingMethod, previousBody, holder);
      }

      delegatingMethod.body().invoke(holder.getHandler(), "post").arg(_new(anonymousRunnableClass));
    } else {
      delegatingMethod
          .body()
          .invoke(holder.getHandler(), "postDelayed")
          .arg(_new(anonymousRunnableClass))
          .arg(lit(delay));
    }
  }
  /**
   * Add the pre-check to see if we are already in the UI thread.
   *
   * @param delegatingMethod
   * @param holder
   * @throws JClassAlreadyExistsException
   */
  private void addUIThreadCheck(
      JMethod delegatingMethod, JBlock previousBody, EComponentHolder holder)
      throws JClassAlreadyExistsException {
    // Get the Thread and Looper class.
    JClass tClass = holder.classes().THREAD;
    JClass lClass = holder.classes().LOOPER;

    // invoke the methods.
    JExpression lhs = tClass.staticInvoke(METHOD_CUR_THREAD);
    JExpression rhs = lClass.staticInvoke(METHOD_MAIN_LOOPER).invoke(METHOD_GET_THREAD);

    // create the conditional and the block.
    JConditional con = delegatingMethod.body()._if(JOp.eq(lhs, rhs));
    JBlock thenBlock = con._then().add(previousBody);
    thenBlock._return();
  }
 /** Checks whether the Activity extends one of the ActionBarSherlock Activity types */
 public boolean usesActionBarSherlock(EComponentHolder holder) {
   TypeElement typeElement =
       annotationHelper.typeElementFromQualifiedName(
           holder.getGeneratedClass()._extends().fullName());
   return usesActionBarSherlock(typeElement);
 }