Search in sources :

Example 31 with JVar

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

Example 32 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class EComponentWithViewSupportHolder method setFindSupportFragmentByTag.

protected void setFindSupportFragmentByTag() {
    findSupportFragmentByTag = getGeneratedClass().method(PRIVATE, getClasses().SUPPORT_V4_FRAGMENT, "findSupportFragmentByTag");
    JVar tagParam = findSupportFragmentByTag.param(getClasses().STRING, "tag");
    JBlock body = findSupportFragmentByTag.body();
    body._if(getContextRef()._instanceof(getClasses().FRAGMENT_ACTIVITY).not())._then()._return(_null());
    JVar activityVar = body.decl(getClasses().FRAGMENT_ACTIVITY, "activity_", cast(getClasses().FRAGMENT_ACTIVITY, getContextRef()));
    body._return(activityVar.invoke("getSupportFragmentManager").invoke("findFragmentByTag").arg(tagParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 33 with JVar

use of com.helger.jcodemodel.JVar 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 34 with JVar

use of com.helger.jcodemodel.JVar 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 35 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class EFragmentHolder method setOnAttach.

private void setOnAttach() {
    JMethod onAttach = generatedClass.method(PUBLIC, getCodeModel().VOID, "onAttach");
    onAttach.annotate(Override.class);
    JVar activityParam = onAttach.param(getClasses().ACTIVITY, "activity");
    JBlock onAttachBody = onAttach.body();
    onAttachBody.invoke(_super(), onAttach).arg(activityParam);
    onAttachAfterSuperBlock = onAttachBody.blockSimple();
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

JVar (com.helger.jcodemodel.JVar)119 JBlock (com.helger.jcodemodel.JBlock)81 JMethod (com.helger.jcodemodel.JMethod)56 AbstractJClass (com.helger.jcodemodel.AbstractJClass)48 JInvocation (com.helger.jcodemodel.JInvocation)38 IJExpression (com.helger.jcodemodel.IJExpression)32 VariableElement (javax.lang.model.element.VariableElement)25 ExecutableElement (javax.lang.model.element.ExecutableElement)18 TypeMirror (javax.lang.model.type.TypeMirror)16 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 JFieldRef (com.helger.jcodemodel.JFieldRef)15 JFieldVar (com.helger.jcodemodel.JFieldVar)12 JConditional (com.helger.jcodemodel.JConditional)9 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JCatchBlock (com.helger.jcodemodel.JCatchBlock)5 AbstractJType (com.helger.jcodemodel.AbstractJType)4 ArrayList (java.util.ArrayList)4 BundleHelper (org.androidannotations.helper.BundleHelper)4 JTypeVar (com.helger.jcodemodel.JTypeVar)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3