Search in sources :

Example 31 with JBlock

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);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JVar(com.helger.jcodemodel.JVar)

Example 32 with JBlock

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));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 33 with JBlock

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");
}
Also used : JBlock(com.helger.jcodemodel.JBlock)

Example 34 with JBlock

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);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JVar(com.helger.jcodemodel.JVar)

Example 35 with JBlock

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());
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)155 JVar (com.helger.jcodemodel.JVar)86 JMethod (com.helger.jcodemodel.JMethod)75 AbstractJClass (com.helger.jcodemodel.AbstractJClass)40 JInvocation (com.helger.jcodemodel.JInvocation)38 IJExpression (com.helger.jcodemodel.IJExpression)31 ExecutableElement (javax.lang.model.element.ExecutableElement)26 JFieldRef (com.helger.jcodemodel.JFieldRef)19 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 VariableElement (javax.lang.model.element.VariableElement)15 JFieldVar (com.helger.jcodemodel.JFieldVar)13 TypeMirror (javax.lang.model.type.TypeMirror)13 JConditional (com.helger.jcodemodel.JConditional)10 JTryBlock (com.helger.jcodemodel.JTryBlock)9 JCatchBlock (com.helger.jcodemodel.JCatchBlock)4 TypeElement (javax.lang.model.element.TypeElement)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 AbstractJType (com.helger.jcodemodel.AbstractJType)2 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 IJStatement (com.helger.jcodemodel.IJStatement)2