Search in sources :

Example 36 with JFieldVar

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

the class EActivityHolder method setGetLastNonConfigurationInstance.

private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
    AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
    TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper);
    TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
    String getLastNonConfigurationInstanceName = "getLastNonConfigurationInstance";
    if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
        getLastNonConfigurationInstanceName = "getLastCustomNonConfigurationInstance";
    }
    NonConfigurationHolder ncHolder = getNonConfigurationHolder();
    JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
    JFieldVar superNonConfigurationInstanceField = ncHolder.getSuperNonConfigurationInstanceField();
    getLastNonConfigurationInstance = generatedClass.method(PUBLIC, Object.class, getLastNonConfigurationInstanceName);
    getLastNonConfigurationInstance.annotate(Override.class);
    JBlock body = getLastNonConfigurationInstance.body();
    JVar nonConfigurationInstance = body.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getLastNonConfigurationInstance)));
    body._if(nonConfigurationInstance.eq(_null()))._then()._return(_null());
    body._return(nonConfigurationInstance.ref(superNonConfigurationInstanceField));
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JFieldVar(com.helger.jcodemodel.JFieldVar) AnnotationHelper(org.androidannotations.helper.AnnotationHelper) TypeElement(javax.lang.model.element.TypeElement) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 37 with JFieldVar

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

the class EFragmentHolder method getFindViewByIdExpression.

@Override
public IJExpression getFindViewByIdExpression(JVar idParam) {
    JFieldVar contentView = getContentView();
    JInvocation invocation = contentView.invoke("findViewById").arg(idParam);
    return cond(contentView.eq(_null()), _null(), invocation);
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JInvocation(com.helger.jcodemodel.JInvocation)

Example 38 with JFieldVar

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

the class EBeanHolder method createFactoryMethod.

public void createFactoryMethod(EBean.Scope scope) {
    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();
    switch(scope) {
        case Default:
            factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam));
            createOverloadedFactoryMethod(scope);
            break;
        case Fragment:
            JVar beanVar = factoryMethodBody.decl(getGeneratedClass(), "bean", _new(narrowedGeneratedClass).arg(factoryMethodContextParam));
            factoryMethodBody.invoke(beanVar, getInit());
            factoryMethodBody._return(beanVar);
            createOverloadedFactoryMethod(scope);
            break;
        case Activity:
            requestInstanceFromBeanHolder(factoryMethodContextParam, factoryMethodContextParam, factoryMethodBody);
            beanVar = factoryMethodBody.decl(getGeneratedClass(), "bean", _new(narrowedGeneratedClass).arg(factoryMethodContextParam));
            factoryMethodBody.invoke(beanVar, getInit());
            factoryMethodBody._return(beanVar);
            break;
        case Singleton:
            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);
            break;
    }
}
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)

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