use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class EActivityHandler method process.
@Override
public void process(Element element, EActivityHolder holder) {
List<JFieldRef> fieldRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.LAYOUT, false);
JFieldRef contentViewId = null;
if (fieldRefs.size() == 1) {
contentViewId = fieldRefs.get(0);
}
if (contentViewId != null) {
JBlock onCreateBody = holder.getOnCreate().body();
JMethod setContentView = holder.getSetContentViewLayout();
onCreateBody.invoke(setContentView).arg(contentViewId);
}
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class EFragmentHandler method process.
@Override
public void process(Element element, EFragmentHolder holder) {
JFieldRef contentViewId = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.LAYOUT, false);
if (contentViewId != null) {
JBlock block = holder.getSetContentViewBlock();
JVar inflater = holder.getInflater();
JVar container = holder.getContainer();
JFieldVar contentView = holder.getContentView();
boolean forceInjection = element.getAnnotation(EFragment.class).forceLayoutInjection();
if (!forceInjection) {
//
block._if(contentView.eq(_null()))._then().assign(contentView, inflater.invoke("inflate").arg(contentViewId).arg(container).arg(FALSE));
} else {
block.assign(contentView, inflater.invoke("inflate").arg(contentViewId).arg(container).arg(FALSE));
}
}
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class SharedPrefHandler method createFieldMethod.
private IJExpression createFieldMethod(SharedPrefHolder holder, ExecutableElement method, Class<? extends Annotation> annotationClass, Class<? extends AbstractPrefField<?>> prefFieldClass, Object defaultValue, Res resType, String fieldHelperMethodName) {
Annotation annotation = method.getAnnotation(annotationClass);
IJExpression defaultValueExpr;
Object value = null;
if (annotation != null) {
value = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "value");
}
if (annotation != null && method.getAnnotation(DefaultStringSet.class) == null) {
defaultValueExpr = codeModelHelper.litObject(value);
} else if (method.getAnnotation(DefaultRes.class) != null) {
defaultValueExpr = extractResValue(holder, method, resType);
annotationClass = DefaultRes.class;
} else if (method.getAnnotation(DefaultStringSet.class) != null) {
if (value != null) {
Set<String> arrayValues = new HashSet<>(Arrays.asList((String[]) value));
value = arrayValues;
if (arrayValues.isEmpty()) {
defaultValueExpr = newEmptyStringHashSet();
} else {
JInvocation arrayAsList = getClasses().ARRAYS.staticInvoke("asList");
for (String arrayValue : arrayValues) {
arrayAsList.arg(lit(arrayValue));
}
defaultValueExpr = JExpr._new(getClasses().HASH_SET.narrow(getClasses().STRING)).arg(arrayAsList);
}
} else {
defaultValueExpr = newEmptyStringHashSet();
}
annotationClass = DefaultStringSet.class;
} else {
defaultValueExpr = defaultValue != null ? codeModelHelper.litObject(defaultValue) : newEmptyStringHashSet();
annotationClass = null;
}
Integer keyResId = ResId.DEFAULT_VALUE;
if (annotationClass != null) {
keyResId = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "keyRes");
}
IJExpression keyExpression;
String fieldName = method.getSimpleName().toString();
if (keyResId == ResId.DEFAULT_VALUE) {
keyExpression = lit(fieldName);
} else {
IRInnerClass idClass = getEnvironment().getRClass().get(IRClass.Res.STRING);
JFieldRef idRef = idClass.getIdStaticRef(keyResId, getEnvironment());
keyExpression = holder.getEditorContextField().invoke("getString").arg(idRef);
}
String docComment = getProcessingEnvironment().getElementUtils().getDocComment(method);
String defaultValueStr = value == null ? null : value.toString();
if (defaultValueStr == null) {
defaultValueStr = defaultValue == null ? null : defaultValue.toString();
}
holder.createFieldMethod(prefFieldClass, keyExpression, fieldName, fieldHelperMethodName, defaultValueExpr, docComment, defaultValueStr);
return keyExpression;
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class SharedPrefHandler method extractResValue.
private IJExpression extractResValue(SharedPrefHolder holder, Element method, IRClass.Res res) {
JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(method, DefaultRes.class.getCanonicalName(), res, true);
String resourceGetMethodName = null;
switch(res) {
case BOOL:
resourceGetMethodName = "getBoolean";
break;
case INTEGER:
resourceGetMethodName = "getInteger";
break;
case STRING:
resourceGetMethodName = "getString";
break;
case ARRAY:
resourceGetMethodName = "getStringArray";
break;
default:
break;
}
JInvocation resourceInvocation = holder.getContextField().invoke("getResources").invoke(resourceGetMethodName).arg(idRef);
if (IRClass.Res.ARRAY.equals(res)) {
JInvocation asList = getClasses().ARRAYS.staticInvoke("asList");
JInvocation newHashMap = JExpr._new(getClasses().HASH_SET.narrow(getClasses().STRING));
resourceInvocation = newHashMap.arg(asList.arg(resourceInvocation));
}
return resourceInvocation;
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class SystemServiceHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) {
TypeMirror serviceType = param.asType();
String fieldTypeQualifiedName = serviceType.toString();
JFieldRef serviceRef = new AndroidSystemServices(getEnvironment()).getServiceConstantRef(serviceType);
if (CanonicalNameConstants.APP_WIDGET_MANAGER.equals(fieldTypeQualifiedName)) {
targetBlock.add(fieldRef.assign(createSpecialInjection(holder, fieldTypeQualifiedName, serviceRef, 21, "LOLLIPOP", getClasses().APP_WIDGET_MANAGER, "getInstance", true)));
} else {
targetBlock.add(fieldRef.assign(createNormalInjection(holder, fieldTypeQualifiedName, serviceRef)));
}
}
Aggregations