use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EBeanHolder method setConstructor.
private void setConstructor() {
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);
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EBeanHolder method createFactoryMethod.
public void createFactoryMethod(boolean hasSingletonScope) {
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");
JBlock factoryMethodBody = factoryMethod.body();
/*
* Singletons are bound to the application context
*/
if (hasSingletonScope) {
JFieldVar instanceField = generatedClass.field(PRIVATE | STATIC, generatedClass, "instance" + generationSuffix());
JBlock creationBlock = //
factoryMethodBody._if(//
instanceField.eq(_null()))._then();
JVar previousNotifier = viewNotifierHelper.replacePreviousNotifierWithNull(creationBlock);
creationBlock.assign(instanceField, _new(narrowedGeneratedClass).arg(factoryMethodContextParam.invoke("getApplicationContext")));
creationBlock.invoke(instanceField, getInit());
viewNotifierHelper.resetPreviousNotifier(creationBlock, previousNotifier);
factoryMethodBody._return(instanceField);
} else {
factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam));
}
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EFragmentHolder method setFindViewById.
private void setFindViewById() {
JMethod findViewById = generatedClass.method(PUBLIC, getClasses().VIEW, "findViewById");
findViewById.annotate(Override.class);
JVar idParam = findViewById.param(getCodeModel().INT, "id");
JBlock body = findViewById.body();
JFieldVar contentView = getContentView();
//
body._if(contentView.eq(_null()))._then()._return(_null());
body._return(contentView.invoke(findViewById).arg(idParam));
}
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 RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineTryToCreateFunction.
/*
@Override
public Function tryToCreateFunction(MethodDescriptor methodDescriptor) {
if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK))) {
return new Function() {
@Override
public Object call(Object... args) {
presentationModel.onClick();
return null;
}
};
}
if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK_WITH_EVENT, AbstractViewEvent.class))){
return new Function() {
@Override
public Object call(Object... args) {
boolean result = presentationModel.onLongClickWithEvent((AbstractViewEvent)args[0]);
return (Boolean)result;
}
};
}
return null;
}
*/
public void defineTryToCreateFunction() {
JMethod method = declarePublicMethodOverride("tryToCreateFunction", Function.class);
JVar methodDescriptorParam = method.param(MethodDescriptor.class, "methodDescriptor");
JBlock body = method.body();
for (EventMethodInfo eventMethodInfo : presentationModelInfo.eventMethods()) {
JInvocation getMethod = JExpr.invoke("createMethodDescriptor").arg(eventMethodInfo.name());
if (eventMethodInfo.hasEventArg()) {
getMethod.arg(codeModel.ref(eventMethodInfo.eventArgType()).dotclass());
}
JConditional conditional = body._if(methodDescriptorParam.invoke("equals").arg(getMethod));
JBlock conditionalBody = conditional._then();
// create Function.
JDefinedClass anonymousFunction = codeModel.anonymousClass(Function.class);
JMethod call = declarePublicMethodOverride(anonymousFunction, "call", Object.class);
JVar argsVar = call.varParam(Object.class, "args");
JBlock callBody = call.body();
// call event method.
JInvocation onEvent = presentationModelFieldWithoutThis.invoke(eventMethodInfo.name());
if (eventMethodInfo.hasEventArg()) {
AbstractJClass eventArgClass = codeModel.ref(eventMethodInfo.eventArgType());
onEvent.arg(JExpr.cast(eventArgClass, argsVar.component(JExpr.lit(0))));
}
// call return.
if (eventMethodInfo.hasReturn()) {
JVar returnVar = callBody.decl(codeModel.ref(eventMethodInfo.nonPrimitiveReturnType()), "result", onEvent);
callBody._return(returnVar);
} else {
callBody.add(onEvent);
callBody._return(JExpr._null());
}
// return Function.
conditionalBody._return(JExpr._new(anonymousFunction));
}
body._return(JExpr._null());
}
Aggregations