Search in sources :

Example 1 with IgnoreWhen

use of org.androidannotations.annotations.IgnoreWhen in project androidannotations by androidannotations.

the class IgnoreWhenHandler method process.

@Override
public void process(Element element, EFragmentHolder holder) throws Exception {
    ExecutableElement executableElement = (ExecutableElement) element;
    JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
    JBlock previousMethodBody = codeModelHelper.removeBody(delegatingMethod);
    IgnoreWhen ignoreWhen = element.getAnnotation(IgnoreWhen.class);
    JBlock methodBody = delegatingMethod.body();
    JConditional conditional = null;
    switch(ignoreWhen.value()) {
        case VIEW_DESTROYED:
            conditional = methodBody._if(holder.getViewDestroyedField().not());
            break;
        case DETACHED:
            conditional = methodBody._if(invoke(holder.getGeneratedClass().staticRef("this"), "getActivity").ne(_null()));
            break;
    }
    conditional._then().add(previousMethodBody);
}
Also used : IgnoreWhen(org.androidannotations.annotations.IgnoreWhen) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JConditional(com.helger.jcodemodel.JConditional) JMethod(com.helger.jcodemodel.JMethod)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)1 JConditional (com.helger.jcodemodel.JConditional)1 JMethod (com.helger.jcodemodel.JMethod)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 IgnoreWhen (org.androidannotations.annotations.IgnoreWhen)1