Source:
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: case Fragment: factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam)); createOverloadedFactoryMethod(scope); break; case Activity: createFactoryMethodForBeanHolder(factoryMethodContextParam, factoryMethodContextParam, factoryMethodBody); factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam)); 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; } }

Target:
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; } }