use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class EBeanHolder method setConstructor.
private void setConstructor() {
constructor = generatedClass.constructor(PRIVATE);
JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
JBlock constructorBody = constructor.body();
List<ExecutableElement> constructors = ElementFilter.constructorsIn(annotatedElement.getEnclosedElements());
ExecutableElement superConstructor = constructors.get(0);
if (superConstructor.getParameters().size() == 1) {
constructorBody.invoke("super").arg(constructorContextParam);
}
constructorBody.assign(getContextField(), constructorContextParam);
}
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));
}
}
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));
}
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));
}
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);
}
Aggregations