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));
}
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);
}
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));
}
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));
}
}
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;
}
Aggregations