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));
}
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);
}
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;
}
}
Aggregations