use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class OrmLiteHolder method injectReleaseInOnDestroy.
private void injectReleaseInOnDestroy(JFieldVar databaseHelperRef) {
if (holder() instanceof HasLifecycleMethods) {
JBlock destroyBody = ((HasLifecycleMethods) holder()).getOnDestroyBeforeSuperBlock();
destroyBody.staticInvoke(getJClass(OrmLiteClasses.OPEN_HELPER_MANAGER), "releaseHelper");
destroyBody.assign(databaseHelperRef, _null());
}
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class RoboGuiceHandler method onDestroyMethod.
private void onDestroyMethod(EActivityHolder holder, JFieldVar eventManager) {
JBlock onDestroyBlock = new JBlock().bracesRequired(false).indentRequired(false);
JTryBlock tryBlock = onDestroyBlock._try();
fireEvent(eventManager, tryBlock.body(), getJClass(RoboGuiceClasses.ON_DESTROY_EVENT));
JBlock finallyBody = tryBlock._finally();
JTryBlock tryInFinally = finallyBody._try();
tryInFinally.body().add(getJClass(RoboGuiceClasses.ROBO_GUICE).staticInvoke("destroyInjector").arg(_this()));
tryInFinally._finally().invoke(_super(), "onDestroy");
JMethod onDestroy = holder.getOnDestroy();
codeModelHelper.replaceSuperCall(onDestroy, onDestroyBlock);
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class RoboGuiceHandler method onStopMethod.
private void onStopMethod(EActivityHolder holder, JFieldVar eventManager) {
JBlock onStopBlock = new JBlock().bracesRequired(false).indentRequired(false);
JTryBlock tryBlock = onStopBlock._try();
fireEvent(eventManager, tryBlock.body(), getJClass(RoboGuiceClasses.ON_STOP_EVENT));
JBlock finallyBody = tryBlock._finally();
finallyBody.invoke(_super(), "onStop");
JMethod onStop = holder.getOnStop();
codeModelHelper.replaceSuperCall(onStop, onStopBlock);
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class RoboGuiceHolder method getCurrentConfig.
public JVar getCurrentConfig() {
if (currentConfig == null) {
AbstractJClass configurationClass = environment().getClasses().CONFIGURATION;
JBlock onConfigurationChangedBeforeSuperBlock = holder().getOnConfigurationChangedBeforeSuperBlock();
currentConfig = onConfigurationChangedBeforeSuperBlock.decl(configurationClass, "currentConfig", JExpr.invoke("getResources").invoke("getConfiguration"));
onConfigurationChangedBeforeSuperBlock.bracesRequired(false).indentRequired(false);
}
return currentConfig;
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class ReceiverActionHandler method addActionInOnReceive.
private void addActionInOnReceive(EReceiverHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionsField, JFieldVar dataSchemesField) {
String actionsInvoke = getInvocationName(actionsField);
IJExpression filterCondition = actionsField.invoke(actionsInvoke).arg(holder.getOnReceiveIntentAction());
if (dataSchemesField != null) {
String dataSchemesInvoke = getInvocationName(dataSchemesField);
filterCondition = filterCondition.cand(dataSchemesField.invoke(dataSchemesInvoke).arg(holder.getOnReceiveIntentDataScheme()));
}
JBlock callActionBlock = holder.getOnReceiveBody()._if(filterCondition)._then();
IJExpression receiverRef = holder.getGeneratedClass().staticRef("this");
JInvocation callActionInvocation = receiverRef.invoke(methodName);
JVar intent = holder.getOnReceiveIntent();
JVar extras = null;
List<? extends VariableElement> methodParameters = executableElement.getParameters();
for (VariableElement param : methodParameters) {
AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
if (extraParamClass.equals(getClasses().CONTEXT)) {
callActionInvocation.arg(holder.getOnReceiveContext());
} else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(ReceiverAction.Extra.class) == null) {
callActionInvocation.arg(intent);
} else if (param.getAnnotation(ReceiverAction.Extra.class) != null) {
if (extras == null) {
extras = callActionBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(//
intent.invoke("getExtras").ne(_null()), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
}
callActionInvocation.arg(extraHandler.getExtraValue(param, extras, callActionBlock, holder));
}
}
callActionBlock.add(callActionInvocation);
callActionBlock._return();
}
Aggregations