use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ExtraHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EActivityHolder holder, Element element, Element param) {
String fieldName = element.getSimpleName().toString();
String extraKey = extractExtraKey(element, fieldName);
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, param);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JFieldVar extraKeyStaticField = getOrCreateStaticExtraField(holder, extraKey, fieldName);
if (element.getKind() != ElementKind.PARAMETER) {
holder.getIntentBuilder().getPutExtraMethod(element, new IntentBuilder.IntentExtra(param.asType(), fieldName, extraKeyStaticField));
}
AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(param.asType());
JMethod injectExtrasMethod = holder.getInjectExtrasMethod();
JVar extras = holder.getInjectExtras();
IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, extras, extraKeyStaticField, injectExtrasMethod);
JBlock ifContainsKey = targetBlock._if(JExpr.invoke(extras, "containsKey").arg(extraKeyStaticField))._then();
ifContainsKey.assign(fieldRef, restoreMethodCall);
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ExtraHandler method getOrCreateStaticExtraField.
private JFieldVar getOrCreateStaticExtraField(EActivityHolder holder, String extraKey, String fieldName) {
String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(null, fieldName, "Extra");
JFieldVar staticExtraField = holder.getGeneratedClass().fields().get(staticFieldName);
if (staticExtraField == null) {
staticExtraField = holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(extraKey));
}
return staticExtraField;
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ExtraHandler method afterAllParametersInjected.
@Override
public void afterAllParametersInjected(EActivityHolder holder, ExecutableElement method, List<InjectHelper.ParamHelper> parameterList) {
List<IntentBuilder.IntentExtra> params = new ArrayList<>();
for (InjectHelper.ParamHelper paramHelper : parameterList) {
Element param = paramHelper.getParameterElement();
String fieldName = param.getSimpleName().toString();
String extraKey = extractExtraKey(param, fieldName);
JFieldVar extraKeyStaticField = getOrCreateStaticExtraField(holder, extraKey, fieldName);
params.add(new IntentBuilder.IntentExtra(param.asType(), fieldName, extraKeyStaticField));
}
holder.getIntentBuilder().getPutExtraMethod(method, params);
}
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));
}
Aggregations