use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class FragmentArgHandler method getOrCreateStaticArgField.
private JFieldVar getOrCreateStaticArgField(EFragmentHolder holder, String argKey, String fieldName) {
String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(null, fieldName, "Arg");
JFieldVar staticExtraField = holder.getGeneratedClass().fields().get(staticFieldName);
if (staticExtraField == null) {
staticExtraField = holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(argKey));
}
return staticExtraField;
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class FragmentArgHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EFragmentHolder holder, Element element, Element param) {
String fieldName = element.getSimpleName().toString();
String argKey = extractArgKey(element, fieldName);
if (element.getKind() != ElementKind.PARAMETER) {
createBuilderInjectionMethod(holder, element, new ArgHelper(param, argKey));
}
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, param);
AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(actualType);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JVar bundle = holder.getInjectBundleArgs();
JMethod injectExtrasMethod = holder.getInjectArgsMethod();
JFieldVar extraKeyStaticField = getOrCreateStaticArgField(holder, argKey, fieldName);
IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, bundle, extraKeyStaticField, injectExtrasMethod);
JConditional conditional = targetBlock._if(JExpr.invoke(bundle, "containsKey").arg(extraKeyStaticField));
conditional._then().add(fieldRef.assign(restoreMethodCall));
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class FragmentArgHandler method createBuilderInjectMethod.
public void createBuilderInjectMethod(EFragmentHolder holder, Element element, List<ArgHelper> argHelpers) {
JDefinedClass builderClass = holder.getBuilderClass();
JFieldRef builderArgsField = holder.getBuilderArgsField();
JMethod builderMethod = builderClass.method(PUBLIC, holder.narrow(builderClass), element.getSimpleName().toString());
String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element);
codeModelHelper.addTrimmedDocComment(builderMethod, docComment);
for (ArgHelper argHelper : argHelpers) {
String fieldName = argHelper.param.getSimpleName().toString();
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, argHelper.param);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JFieldVar argKeyStaticField = getOrCreateStaticArgField(holder, argHelper.argKey, fieldName);
AbstractJClass paramClass = codeModelHelper.typeMirrorToJClass(actualType);
JVar arg = builderMethod.param(paramClass, fieldName);
builderMethod.body().add(bundleHelper.getExpressionToSaveFromField(builderArgsField, argKeyStaticField, arg));
builderMethod.javadoc().addParam(fieldName).append("value for this Fragment argument");
}
builderMethod.javadoc().addReturn().append("the FragmentBuilder to chain calls");
builderMethod.body()._return(_this());
}
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));
}
}
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));
}
Aggregations