use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class EActivityHolder method setGetLastNonConfigurationInstance.
private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
String getLastNonConfigurationInstanceName = "getLastNonConfigurationInstance";
if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
getLastNonConfigurationInstanceName = "getLastCustomNonConfigurationInstance";
}
NonConfigurationHolder ncHolder = getNonConfigurationHolder();
JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
JFieldVar superNonConfigurationInstanceField = ncHolder.getSuperNonConfigurationInstanceField();
getLastNonConfigurationInstance = generatedClass.method(PUBLIC, Object.class, getLastNonConfigurationInstanceName);
getLastNonConfigurationInstance.annotate(Override.class);
JBlock body = getLastNonConfigurationInstance.body();
JVar nonConfigurationInstance = body.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getLastNonConfigurationInstance)));
body._if(nonConfigurationInstance.eq(_null()))._then()._return(_null());
body._return(nonConfigurationInstance.ref(superNonConfigurationInstanceField));
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class RestHandler method setInterceptors.
private void setInterceptors(Element element, RestHolder holder) {
List<DeclaredType> interceptors = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "interceptors");
if (interceptors != null) {
AbstractJClass listClass = getJClass(ARRAYLIST);
AbstractJClass clientInterceptorClass = getJClass(CLIENT_HTTP_REQUEST_INTERCEPTOR);
listClass = listClass.narrow(clientInterceptorClass);
JFieldVar restTemplateField = holder.getRestTemplateField();
JBlock init = holder.getInit().body();
init.add(invoke(restTemplateField, "setInterceptors").arg(_new(listClass)));
for (DeclaredType interceptorType : interceptors) {
JInvocation newInterceptor = codeModelHelper.newBeanOrEBean(interceptorType, holder.getInitContextParam());
init.add(invoke(restTemplateField, "getInterceptors").invoke("add").arg(newInterceptor));
}
}
}
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 ReceiverRegistrationDelegate method createIntentFilterField.
private JFieldVar createIntentFilterField(IntentFilterData intentFilterData) {
String intentFilterName = "intentFilter" + (intentFilterFields.size() + 1) + generationSuffix();
IJExpression newIntentFilterExpr = _new(getClasses().INTENT_FILTER);
JFieldVar intentFilterField = getGeneratedClass().field(PRIVATE | FINAL, getClasses().INTENT_FILTER, intentFilterName, newIntentFilterExpr);
JBlock intentFilterTarget = holder.getIntentFilterInitializationBlock(intentFilterData);
for (String action : intentFilterData.getActionSet()) {
intentFilterTarget.invoke(intentFilterField, "addAction").arg(action);
}
for (String dataScheme : intentFilterData.getDataSchemeSet()) {
intentFilterTarget.invoke(intentFilterField, "addDataScheme").arg(dataScheme);
}
return intentFilterField;
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ReceiverRegistrationDelegate method getIntentFilterField.
public JFieldVar getIntentFilterField(IntentFilterData intentFilterData) {
JFieldVar intentFilterField = intentFilterFields.get(intentFilterData);
if (intentFilterField == null) {
intentFilterField = createIntentFilterField(intentFilterData);
intentFilterFields.put(intentFilterData, intentFilterField);
}
return intentFilterField;
}
Aggregations