use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method createTextWatcherHolder.
private TextWatcherHolder createTextWatcherHolder(JFieldRef idRef, TypeMirror viewParameterType) {
JDefinedClass onTextChangeListenerClass = getCodeModel().anonymousClass(getClasses().TEXT_WATCHER);
AbstractJClass viewClass = getClasses().TEXT_VIEW;
if (viewParameterType != null) {
viewClass = getJClass(viewParameterType.toString());
}
JBlock onViewChangedBody = getOnViewChangedBodyInjectionBlock().blockSimple();
JVar viewVariable = onViewChangedBody.decl(FINAL, viewClass, "view", cast(viewClass, findViewById(idRef)));
//
onViewChangedBody._if(viewVariable.ne(JExpr._null()))._then().invoke(viewVariable, "addTextChangedListener").arg(_new(onTextChangeListenerClass));
return new TextWatcherHolder(this, viewVariable, onTextChangeListenerClass);
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method setFindNativeFragmentById.
protected void setFindNativeFragmentById() {
findNativeFragmentById = getGeneratedClass().method(PRIVATE, getClasses().FRAGMENT, "findNativeFragmentById");
JVar idParam = findNativeFragmentById.param(getCodeModel().INT, "id");
JBlock body = findNativeFragmentById.body();
body._if(getContextRef()._instanceof(getClasses().ACTIVITY).not())._then()._return(_null());
JVar activityVar = body.decl(getClasses().ACTIVITY, "activity_", cast(getClasses().ACTIVITY, getContextRef()));
body._return(activityVar.invoke("getFragmentManager").invoke("findFragmentById").arg(idParam));
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EViewGroupHolder method setOnFinishInflate.
protected void setOnFinishInflate() {
onFinishInflate = generatedClass.method(PUBLIC, getCodeModel().VOID, "onFinishInflate");
onFinishInflate.annotate(Override.class);
onFinishInflate.javadoc().append(ALREADY_INFLATED_COMMENT);
JBlock ifNotInflated = onFinishInflate.body()._if(getAlreadyInflated().not())._then();
ifNotInflated.assign(getAlreadyInflated(), JExpr.TRUE);
setContentViewBlock = ifNotInflated.blockSimple();
getInit();
viewNotifierHelper.invokeViewChanged(ifNotInflated);
onFinishInflate.body().invoke(JExpr._super(), "onFinishInflate");
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EBeanHolder method requestInstanceFromBeanHolder.
private void requestInstanceFromBeanHolder(IJExpression fieldRef, IJExpression contextRef, JBlock block) {
AbstractJClass beanHolderClass = getJClass(BeanHolder.class);
JBlock ifBlock = block._if(fieldRef._instanceof(beanHolderClass))._then();
JVar beanHolderVar = ifBlock.decl(beanHolderClass, "beanHolder", cast(beanHolderClass, fieldRef));
JVar beanVar = ifBlock.decl(getGeneratedClass(), "bean", beanHolderVar.invoke("getBean").arg(getGeneratedClass().dotclass()));
JInvocation newBeanExpression = _new(getGeneratedClass()).arg(contextRef);
if (fieldRef != contextRef) {
newBeanExpression = newBeanExpression.arg(fieldRef);
}
JBlock ifBeanNullBlock = ifBlock._if(beanVar.eq(_null()))._then();
ifBeanNullBlock.assign(beanVar, newBeanExpression);
ifBeanNullBlock.add(beanHolderVar.invoke("putBean").arg(getGeneratedClass().dotclass()).arg(beanVar));
ifBeanNullBlock.invoke(beanVar, getInit());
ifBlock._return(beanVar);
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EBeanHolder method createRebindMethod.
public void createRebindMethod() {
JMethod rebindMethod = generatedClass.method(PUBLIC, getCodeModel().VOID, "rebind");
JVar contextParam = rebindMethod.param(getClasses().CONTEXT, "context");
JBlock body = rebindMethod.body();
body.assign(getContextField(), contextParam);
body.invoke(getInit());
}
Aggregations