use of com.helger.jcodemodel.IJExpression 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.IJExpression in project androidannotations by androidannotations.
the class AfterTextChangeHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int editableParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.EDITABLE.equals(parameterType.toString())) {
editableParameterPosition = i;
} else {
TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
if (annotationHelper.isSubtype(parameterType, textViewType)) {
viewParameterPosition = i;
viewParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
JBlock methodBody = textWatcherHolder.getAfterTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == editableParameterPosition) {
JVar afterTextChangeEditableParam = textWatcherHolder.getAfterTextChangedEditableParam();
textChangeCall.arg(afterTextChangeEditableParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class OrmLiteHolder method setDatabaseHelperRef.
private JFieldVar setDatabaseHelperRef(TypeMirror databaseHelperTypeMirror) {
AbstractJClass databaseHelperClass = getJClass(databaseHelperTypeMirror.toString());
String fieldName = CaseHelper.lowerCaseFirst(databaseHelperClass.name()) + ModelConstants.generationSuffix();
JFieldVar databaseHelperRef = getGeneratedClass().field(PRIVATE, databaseHelperClass, fieldName);
databaseHelperRefs.put(databaseHelperTypeMirror, databaseHelperRef);
IJExpression dbHelperClass = databaseHelperClass.dotclass();
//
holder().getInitBodyInjectionBlock().assign(//
databaseHelperRef, getJClass(OrmLiteClasses.OPEN_HELPER_MANAGER).staticInvoke("getHelper").arg(holder().getContextRef()).arg(dbHelperClass));
return databaseHelperRef;
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class IntentBuilder method getSuperPutExtraInvocation.
public JInvocation getSuperPutExtraInvocation(TypeMirror elementType, JVar extraParam, JFieldVar extraKeyField) {
IJExpression extraParameterArg = extraParam;
// Cast to Parcelable, wrap with Parcels.wrap or cast Serializable if needed
if (elementType.getKind() == TypeKind.DECLARED) {
Elements elementUtils = environment.getProcessingEnvironment().getElementUtils();
TypeMirror parcelableType = elementUtils.getTypeElement(PARCELABLE).asType();
if (typeUtils.isSubtype(elementType, parcelableType)) {
TypeMirror serializableType = elementUtils.getTypeElement(SERIALIZABLE).asType();
if (typeUtils.isSubtype(elementType, serializableType)) {
extraParameterArg = cast(environment.getClasses().PARCELABLE, extraParameterArg);
}
} else if (!BundleHelper.METHOD_SUFFIX_BY_TYPE_NAME.containsKey(elementType.toString()) && parcelerHelper.isParcelType(elementType)) {
extraParameterArg = environment.getJClass(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("wrap").arg(extraParameterArg);
} else {
TypeMirror stringType = elementUtils.getTypeElement(STRING).asType();
if (!typeUtils.isSubtype(elementType, stringType)) {
extraParameterArg = cast(environment.getClasses().SERIALIZABLE, extraParameterArg);
}
}
}
return _super().invoke("extra").arg(extraKeyField).arg(extraParameterArg);
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class OrmLiteDaoHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) {
OrmLiteHolder ormLiteHolder = holder.getPluginHolder(new OrmLiteHolder(holder));
AbstractJClass modelClass = getJClass(ormLiteHelper.getEntityType(param).toString());
AbstractJClass idClass = getJClass(ormLiteHelper.getEntityIdType(param).toString());
IJExpression modelClassDotClass = modelClass.dotclass();
AbstractJClass daoClass = getJClass(OrmLiteClasses.DAO).narrow(modelClass, idClass);
AbstractJClass daoImplClass = codeModelHelper.typeMirrorToJClass(param.asType());
TypeMirror databaseHelperTypeMirror = annotationHelper.extractAnnotationParameter(element, "helper");
JFieldVar databaseHelperRef = ormLiteHolder.getDatabaseHelperRef(databaseHelperTypeMirror);
IJExpression injectExpr = databaseHelperRef.invoke("getDao").arg(modelClassDotClass);
if (elementExtendsRuntimeExceptionDao(param)) {
injectExpr = _new(daoImplClass).arg(cast(daoClass, injectExpr));
}
JTryBlock tryBlock = targetBlock._try();
tryBlock.body().add(fieldRef.assign(injectExpr));
JCatchBlock catchBlock = tryBlock._catch(getClasses().SQL_EXCEPTION);
JVar exception = catchBlock.param("e");
String fieldName = param.getSimpleName().toString();
//
catchBlock.body().staticInvoke(getClasses().LOG, //
"e").arg(//
logTagForClassHolder(holder)).arg(//
"Could not create DAO " + fieldName).arg(exception);
}
Aggregations