use of com.helger.jcodemodel.JFieldVar 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);
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ReceiverHandler method process.
@Override
public void process(Element element, HasReceiverRegistration holder) throws Exception {
String methodName = element.getSimpleName().toString();
String receiverName = methodName + "Receiver" + generationSuffix();
Receiver annotation = element.getAnnotation(Receiver.class);
String[] actions = annotation.actions();
String[] dataSchemes = annotation.dataSchemes();
Receiver.RegisterAt registerAt = annotation.registerAt();
boolean local = annotation.local();
JFieldVar intentFilterField = holder.getIntentFilterField(new IntentFilterData(actions, dataSchemes, registerAt));
JFieldVar receiverField = createReceiverField(holder, receiverName, methodName, (ExecutableElement) element);
registerAndUnregisterReceiver(holder, registerAt, intentFilterField, receiverField, local);
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ServiceActionHandler method addActionToIntentBuilder.
private void addActionToIntentBuilder(EIntentServiceHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionKeyField) {
JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), methodName);
JBlock body = method.body();
String docComment = getProcessingEnvironment().getElementUtils().getDocComment(executableElement);
codeModelHelper.addTrimmedDocComment(method, docComment);
method.javadoc().addReturn().append("the IntentBuilder to chain calls");
// setAction
body.invoke("action").arg(actionKeyField);
for (VariableElement param : executableElement.getParameters()) {
String paramName = param.getSimpleName().toString();
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(param.asType());
JFieldVar paramVar = getStaticExtraField(holder, paramName);
JVar methodParam = method.param(parameterClass, paramName);
JInvocation putExtraInvocation = holder.getIntentBuilder().getSuperPutExtraInvocation(param.asType(), methodParam, paramVar);
body.add(putExtraInvocation);
}
body._return(JExpr._this());
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ServiceActionHandler method getStaticExtraField.
private JFieldVar getStaticExtraField(EIntentServiceHolder holder, String extraName) {
String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(null, extraName, "Extra");
JFieldVar staticExtraField = holder.getGeneratedClass().fields().get(staticFieldName);
if (staticExtraField == null) {
staticExtraField = holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(extraName));
}
return staticExtraField;
}
Aggregations