use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EBeanHolder method setConstructors.
private void setConstructors() {
constructor = generatedClass.constructor(PRIVATE);
JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
JBlock constructorBody = constructor.body();
List<ExecutableElement> constructors = ElementFilter.constructorsIn(annotatedElement.getEnclosedElements());
ExecutableElement superConstructor = constructors.get(0);
if (superConstructor.getParameters().size() == 1) {
constructorBody.invoke("super").arg(constructorContextParam);
}
constructorBody.assign(getContextField(), constructorContextParam);
overloadedConstructor = generatedClass.constructor(PRIVATE);
JVar overloadedConstructorContextParam = overloadedConstructor.param(getClasses().CONTEXT, "context");
JVar overloadedConstructorRootFragmentParam = overloadedConstructor.param(getClasses().OBJECT, "rootFragment");
JBlock overloadedConstructorBody = overloadedConstructor.body();
if (superConstructor.getParameters().size() == 1) {
overloadedConstructorBody.invokeSuper().arg(constructorContextParam);
}
overloadedConstructorBody.assign(getContextField(), overloadedConstructorContextParam);
overloadedConstructorBody.assign(getRootFragmentField(), overloadedConstructorRootFragmentParam);
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EBeanHolder method createOverloadedFactoryMethod.
private void createOverloadedFactoryMethod(EBean.Scope scope) {
AbstractJClass narrowedGeneratedClass = codeModelHelper.narrowGeneratedClass(generatedClass, annotatedElement.asType());
JMethod factoryMethod = generatedClass.method(PUBLIC | STATIC, narrowedGeneratedClass, GET_INSTANCE_METHOD_NAME);
codeModelHelper.generify(factoryMethod, annotatedElement);
JVar factoryMethodContextParam = factoryMethod.param(getClasses().CONTEXT, "context");
JVar factoryMethodRootFragmentParam = factoryMethod.param(getClasses().OBJECT, "rootFragment");
JBlock factoryMethodBody = factoryMethod.body();
if (scope == EBean.Scope.Fragment) {
requestInstanceFromBeanHolder(factoryMethodRootFragmentParam, factoryMethodContextParam, factoryMethodBody);
}
factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam).arg(factoryMethodRootFragmentParam));
}
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 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 onResumeMethod.
private void onResumeMethod(EActivityHolder holder, JFieldVar eventManager) {
JBlock onResumeAfterSuperBlock = holder.getOnResumeAfterSuperBlock();
fireEvent(eventManager, onResumeAfterSuperBlock, getJClass(RoboGuiceClasses.ON_RESUME_EVENT));
}
Aggregations