Search in sources :

Example 51 with JBlock

use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.

the class RoboGuiceHandler method onRestartMethod.

private void onRestartMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onRestartAfterSuperBlock = holder.getOnRestartAfterSuperBlock();
    fireEvent(eventManager, onRestartAfterSuperBlock, getJClass(RoboGuiceClasses.ON_RESTART_EVENT));
}
Also used : JBlock(com.helger.jcodemodel.JBlock)

Example 52 with JBlock

use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.

the class RoboGuiceHandler method onActivityResultMethod.

private void onActivityResultMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onActivityResultAfterSuperBlock = holder.getOnActivityResultAfterSuperBlock();
    JVar requestCode = holder.getOnActivityResultRequestCodeParam();
    JVar resultCode = holder.getOnActivityResultResultCodeParam();
    JVar data = holder.getOnActivityResultDataParam();
    fireEvent(eventManager, onActivityResultAfterSuperBlock, getJClass(RoboGuiceClasses.ON_ACTIVITY_RESULT_EVENT), requestCode, resultCode, data);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 53 with JBlock

use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.

the class RoboGuiceHandler method onResumeMethod.

private void onResumeMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onResumeAfterSuperBlock = holder.getOnResumeAfterSuperBlock();
    fireEvent(eventManager, onResumeAfterSuperBlock, getJClass(RoboGuiceClasses.ON_RESUME_EVENT));
}
Also used : JBlock(com.helger.jcodemodel.JBlock)

Example 54 with JBlock

use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.

the class RestHandler method setConverters.

private void setConverters(Element element, RestHolder holder) {
    List<DeclaredType> converters = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "converters");
    JFieldVar restTemplateField = holder.getRestTemplateField();
    JBlock init = holder.getInit().body();
    init.add(invoke(restTemplateField, "getMessageConverters").invoke("clear"));
    for (DeclaredType converterType : converters) {
        JInvocation newConverter = codeModelHelper.newBeanOrEBean(converterType, holder.getInitContextParam());
        init.add(invoke(restTemplateField, "getMessageConverters").invoke("add").arg(newConverter));
    }
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Example 55 with JBlock

use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.

the class RestMethodHandler method surroundWithRestTryCatch.

/**
	 * Adds the try/catch around the rest execution code.
	 *
	 * If an exception is caught, it will first check if the handler is set. If
	 * the handler is set, it will call the handler and return null (or nothing
	 * if void). If the handler isn't set, it will re-throw the exception so
	 * that it behaves as it did previous to this feature.
	 */
private JBlock surroundWithRestTryCatch(RestHolder holder, JBlock block, boolean methodReturnVoid) {
    if (holder.getRestErrorHandlerField() != null) {
        JBlock newBlock = new JBlock().bracesRequired(false).indentRequired(false);
        JTryBlock tryBlock = newBlock._try();
        codeModelHelper.copy(block, tryBlock.body());
        JCatchBlock jCatch = tryBlock._catch(getJClass(NESTED_RUNTIME_EXCEPTION));
        JBlock catchBlock = jCatch.body();
        JConditional conditional = catchBlock._if(JOp.ne(holder.getRestErrorHandlerField(), JExpr._null()));
        JVar exceptionParam = jCatch.param("e");
        JBlock thenBlock = conditional._then();
        // call the handler method if it was set.
        thenBlock.add(holder.getRestErrorHandlerField().invoke("onRestClientExceptionThrown").arg(exceptionParam));
        // return null if exception was caught and handled.
        if (!methodReturnVoid) {
            thenBlock._return(JExpr._null());
        }
        // re-throw the exception if handler wasn't set.
        conditional._else()._throw(exceptionParam);
        return newBlock;
    }
    return block;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JConditional(com.helger.jcodemodel.JConditional) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)148 JVar (com.helger.jcodemodel.JVar)81 JMethod (com.helger.jcodemodel.JMethod)73 JInvocation (com.helger.jcodemodel.JInvocation)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)35 IJExpression (com.helger.jcodemodel.IJExpression)31 ExecutableElement (javax.lang.model.element.ExecutableElement)25 JFieldRef (com.helger.jcodemodel.JFieldRef)19 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 VariableElement (javax.lang.model.element.VariableElement)15 TypeMirror (javax.lang.model.type.TypeMirror)13 JFieldVar (com.helger.jcodemodel.JFieldVar)11 JConditional (com.helger.jcodemodel.JConditional)10 JTryBlock (com.helger.jcodemodel.JTryBlock)9 JCatchBlock (com.helger.jcodemodel.JCatchBlock)4 TypeElement (javax.lang.model.element.TypeElement)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 AbstractJType (com.helger.jcodemodel.AbstractJType)2 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2