Search in sources :

Example 1 with JFieldVar

use of com.helger.jcodemodel.JFieldVar 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 2 with JFieldVar

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

Example 3 with JFieldVar

use of com.helger.jcodemodel.JFieldVar in project RoboBinding by RoboBinding.

the class PresentationModelObjectClassGen method defineFields.

/**
 * Note: not private in order to improve performance.
 *
 * final PresentationModelType presentationModel;
 */
@Override
public void defineFields() {
    JFieldVar var = definedClass.field(JMod.FINAL, presentationModelClass, "presentationModel");
    presentationModelField = JExpr.refthis(var.name());
    presentationModelFieldWithoutThis = JExpr.ref(var.name());
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

Example 4 with JFieldVar

use of com.helger.jcodemodel.JFieldVar in project RoboBinding by RoboBinding.

the class ItemPresentationModelObjectClassGen method defineFields.

/**
 * Note: not private in order to improve performance.
 *
 * final ItemPresentationModelType itemPresentationModel;
 */
@Override
public void defineFields() {
    JFieldVar var = definedClass.field(JMod.FINAL, presentationModelClass, "itemPresentationModel");
    presentationModelField = JExpr.refthis(var.name());
    presentationModelFieldWithoutThis = JExpr.ref(var.name());
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

Example 5 with JFieldVar

use of com.helger.jcodemodel.JFieldVar in project RoboBinding by RoboBinding.

the class ViewBindingObjectClassGen method defineFields.

/**
 * Note: not private in order to improve performance.
 *
 * final CustomViewBindingType customViewBinding;
 */
public void defineFields() {
    JFieldVar var = definedClass.field(JMod.FINAL, customViewBindingClass, "customViewBinding");
    customViewBindingField = JExpr.refthis(var.name());
    customViewBindingFieldWithoutThis = JExpr.ref(var.name());
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

Aggregations

JFieldVar (com.helger.jcodemodel.JFieldVar)38 JVar (com.helger.jcodemodel.JVar)15 AbstractJClass (com.helger.jcodemodel.AbstractJClass)14 JBlock (com.helger.jcodemodel.JBlock)13 JMethod (com.helger.jcodemodel.JMethod)13 IJExpression (com.helger.jcodemodel.IJExpression)7 JInvocation (com.helger.jcodemodel.JInvocation)6 JDefinedClass (com.helger.jcodemodel.JDefinedClass)5 TypeMirror (javax.lang.model.type.TypeMirror)5 BundleHelper (org.androidannotations.helper.BundleHelper)4 JFieldRef (com.helger.jcodemodel.JFieldRef)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 JTypeVar (com.helger.jcodemodel.JTypeVar)2 VariableElement (javax.lang.model.element.VariableElement)2 DeclaredType (javax.lang.model.type.DeclaredType)2 DataBound (org.androidannotations.annotations.DataBound)2 IntentBuilder (org.androidannotations.internal.core.helper.IntentBuilder)2 Caching (com.github.sviperll.adt4j.Caching)1 VariableDeclaration (com.github.sviperll.adt4j.model.config.VariableDeclaration)1 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)1