use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class EApplicationHolder method createSingleton.
private void createSingleton() {
AbstractJClass annotatedComponent = generatedClass._extends();
staticInstanceField = generatedClass.field(PRIVATE | STATIC, annotatedComponent, "INSTANCE" + generationSuffix());
// Static singleton getter and setter
JMethod getInstance = generatedClass.method(PUBLIC | STATIC, annotatedComponent, GET_APPLICATION_INSTANCE);
getInstance.body()._return(staticInstanceField);
JMethod setInstance = generatedClass.method(PUBLIC | STATIC, getCodeModel().VOID, "setForTesting");
setInstance.javadoc().append("Visible for testing purposes");
JVar applicationParam = setInstance.param(annotatedComponent, "application");
setInstance.body().assign(staticInstanceField, applicationParam);
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class RoboGuiceHandler method onConfigurationChangedMethod.
private void onConfigurationChangedMethod(EActivityHolder holder, RoboGuiceHolder roboGuiceHolder, JFieldVar eventManager) {
JVar currentConfig = roboGuiceHolder.getCurrentConfig();
IJExpression newConfig = holder.getOnConfigurationChangedNewConfigParam();
JBlock onConfigurationChangedAfterSuperBlock = holder.getOnConfigurationChangedAfterSuperBlock();
fireEvent(eventManager, onConfigurationChangedAfterSuperBlock, getJClass(RoboGuiceClasses.ON_CONFIGURATION_CHANGED_EVENT), currentConfig, newConfig);
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class RoboGuiceHandler method beforeCreateMethod.
private void beforeCreateMethod(EActivityHolder holder, JFieldVar scope, JFieldVar scopedObjects, JFieldVar eventManager) {
JBlock body = holder.getInitBody();
AbstractJClass keyWildCard = getJClass(RoboGuiceClasses.KEY).narrow(getCodeModel().wildcard());
AbstractJClass scopedHashMap = getClasses().HASH_MAP.narrow(keyWildCard, getClasses().OBJECT);
body.assign(scopedObjects, JExpr._new(scopedHashMap));
JVar injector = body.decl(getJClass(RoboGuiceClasses.ROBO_INJECTOR), "injector_", getJClass(RoboGuiceClasses.ROBO_GUICE).staticInvoke("getInjector").arg(_this()));
body.assign(scope, invoke(injector, "getInstance").arg(getJClass(RoboGuiceClasses.CONTEXT_SCOPE).dotclass()));
body.assign(eventManager, invoke(injector, "getInstance").arg(getJClass(RoboGuiceClasses.EVENT_MANAGER).dotclass()));
body.add(injector.invoke("injectMembersWithoutViews").arg(_this()));
fireEvent(eventManager, body, getJClass(RoboGuiceClasses.ON_CREATE_EVENT), holder.getInitSavedInstanceParam());
}
use of com.helger.jcodemodel.JVar 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.JVar 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