use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class RoboGuiceHolder method getCurrentConfig.
public JVar getCurrentConfig() {
if (currentConfig == null) {
AbstractJClass configurationClass = environment().getClasses().CONFIGURATION;
JBlock onConfigurationChangedBeforeSuperBlock = holder().getOnConfigurationChangedBeforeSuperBlock();
currentConfig = onConfigurationChangedBeforeSuperBlock.decl(configurationClass, "currentConfig", JExpr.invoke("getResources").invoke("getConfiguration"));
onConfigurationChangedBeforeSuperBlock.bracesRequired(false).indentRequired(false);
}
return currentConfig;
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class NonConfigurationInstanceHandler method process.
@Override
public void process(Element element, EActivityHolder holder) throws JClassAlreadyExistsException {
String fieldName = element.getSimpleName().toString();
AbstractJClass fieldType = codeModelHelper.typeMirrorToJClass(element.asType());
NonConfigurationHolder ncHolder = holder.getNonConfigurationHolder();
JFieldVar ncHolderField = ncHolder.createField(fieldName, fieldType);
injectInInit(element, holder, fieldName, ncHolderField);
retainInOnRetain(holder, fieldName, ncHolderField);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class NonConfigurationInstanceHandler method rebindContextIfBean.
private void rebindContextIfBean(Element element, JBlock initIfNonConfigurationNotNullBlock, JFieldVar field) {
boolean hasBeanAnnotation = element.getAnnotation(Bean.class) != null;
if (hasBeanAnnotation) {
TypeMirror elementType = annotationHelper.extractAnnotationClassParameter(element, Bean.class.getName());
if (elementType == null) {
elementType = element.asType();
}
String typeQualifiedName = elementType.toString();
AbstractJClass fieldGeneratedBeanClass = getJClass(typeQualifiedName + classSuffix());
// do not generate rebind call for singleton beans
Element eBeanTypeElement = annotationHelper.getTypeUtils().asElement(elementType);
EBean eBean = eBeanTypeElement.getAnnotation(EBean.class);
if (eBean != null && eBean.scope() != EBean.Scope.Singleton) {
initIfNonConfigurationNotNullBlock.invoke(cast(fieldGeneratedBeanClass, field), "rebind").arg(_this());
}
}
}
use of com.helger.jcodemodel.AbstractJClass 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.AbstractJClass 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