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()); } } } }
@Override public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) { TypeMirror typeMirror = annotationHelper.extractAnnotationClassParameter(element); if (typeMirror == null) { typeMirror = param.asType(); typeMirror = getProcessingEnvironment().getTypeUtils().erasure(typeMirror); } String typeQualifiedName = typeMirror.toString(); AbstractJClass injectedClass = getJClass(annotationHelper.generatedClassQualifiedNameFromQualifiedName(typeQualifiedName)); JInvocation beanInstance = injectedClass.staticInvoke(EBeanHolder.GET_INSTANCE_METHOD_NAME).arg(holder.getContextRef()); IJStatement assignment = fieldRef.assign(beanInstance); if (param.getKind() == ElementKind.FIELD) { boolean hasNonConfigurationInstanceAnnotation = element.getAnnotation(NonConfigurationInstance.class) != null; if (hasNonConfigurationInstanceAnnotation) { JConditional conditional = targetBlock._if(fieldRef.eq(_null())); conditional._then().add(assignment); assignment = conditional; } } targetBlock.add(assignment); }
private void setRequestFactory(Element element, RestHolder holder) { DeclaredType requestFactoryType = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "requestFactory"); if (requestFactoryType != null) { JInvocation requestFactory = codeModelHelper.newBeanOrEBean(requestFactoryType, holder.getInitContextParam()); holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setRequestFactory").arg(requestFactory)); } }
private void setResponseErrorHandler(Element element, RestHolder holder) { DeclaredType responseErrorHandler = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "responseErrorHandler"); if (responseErrorHandler != null) { JInvocation errorHandler = codeModelHelper.newBeanOrEBean(responseErrorHandler, holder.getInitContextParam()); holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setErrorHandler").arg(errorHandler)); } } }
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()); } } } }
@Override public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) { TypeMirror typeMirror = annotationHelper.extractAnnotationClassParameter(element); if (typeMirror == null) { typeMirror = param.asType(); typeMirror = getProcessingEnvironment().getTypeUtils().erasure(typeMirror); } String typeQualifiedName = typeMirror.toString(); AbstractJClass injectedClass = getJClass(annotationHelper.generatedClassQualifiedNameFromQualifiedName(typeQualifiedName)); JInvocation beanInstance = injectedClass.staticInvoke(EBeanHolder.GET_INSTANCE_METHOD_NAME).arg(holder.getContextRef()); IJStatement assignment = fieldRef.assign(beanInstance); if (param.getKind() == ElementKind.FIELD) { boolean hasNonConfigurationInstanceAnnotation = element.getAnnotation(NonConfigurationInstance.class) != null; if (hasNonConfigurationInstanceAnnotation) { JConditional conditional = targetBlock._if(fieldRef.eq(_null())); conditional._then().add(assignment); assignment = conditional; } } targetBlock.add(assignment); }