use of org.androidannotations.annotations.EBean in project androidannotations by androidannotations.
the class NonConfigurationInstanceHandler method rebindContextIfBean.
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());
}
}
}
use of org.androidannotations.annotations.EBean in project androidannotations by androidannotations.
the class EBeanHandler method process.
@Override
public void process(Element element, EBeanHolder holder) {
EBean eBeanAnnotation = element.getAnnotation(EBean.class);
EBean.Scope eBeanScope = eBeanAnnotation.scope();
boolean hasSingletonScope = eBeanScope == EBean.Scope.Singleton;
holder.createFactoryMethod(hasSingletonScope);
if (!hasSingletonScope) {
holder.invokeInitInConstructor();
holder.createRebindMethod();
}
}
use of org.androidannotations.annotations.EBean in project androidannotations by androidannotations.
the class RestSpringValidatorHelper method validateRestSimpleParameter.
public void validateRestSimpleParameter(Element element, String requiredClass, String parameterName, ElementValidation validation) {
TypeMirror requiredType = annotationHelper.typeElementFromQualifiedName(requiredClass).asType();
DeclaredType paramterType = annotationHelper.extractAnnotationClassParameter(element, annotationHelper.getTarget(), parameterName);
if (paramterType != null) {
if (annotationHelper.isSubtype(paramterType, requiredType)) {
Element parameterElement = paramterType.asElement();
if (parameterElement.getKind().isClass()) {
if (!annotationHelper.isAbstract(parameterElement)) {
if (parameterElement.getAnnotation(EBean.class) != null) {
return;
}
List<ExecutableElement> constructors = ElementFilter.constructorsIn(parameterElement.getEnclosedElements());
for (ExecutableElement constructor : constructors) {
if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) {
return;
}
}
validation.addError(element, "The " + parameterName + " class must have a public no argument constructor or must be annotated with @EBean");
} else {
validation.addError(element, "The " + parameterName + " class must not be abstract");
}
} else {
validation.addError(element, "The " + parameterName + " class must be a class");
}
} else {
validation.addError(element, "The " + parameterName + " class must be a subtype of " + requiredClass);
}
}
}
use of org.androidannotations.annotations.EBean in project androidannotations by androidannotations.
the class RestSpringValidatorHelper method validateInterceptors.
public void validateInterceptors(Element element, ElementValidation valid) {
TypeMirror clientHttpRequestInterceptorType = annotationHelper.typeElementFromQualifiedName(CLIENT_HTTP_REQUEST_INTERCEPTOR).asType();
TypeMirror clientHttpRequestInterceptorTypeErased = annotationHelper.getTypeUtils().erasure(clientHttpRequestInterceptorType);
List<DeclaredType> interceptors = annotationHelper.extractAnnotationClassArrayParameter(element, annotationHelper.getTarget(), "interceptors");
if (interceptors == null) {
return;
}
for (DeclaredType interceptorType : interceptors) {
TypeMirror erasedInterceptorType = annotationHelper.getTypeUtils().erasure(interceptorType);
if (annotationHelper.isSubtype(erasedInterceptorType, clientHttpRequestInterceptorTypeErased)) {
Element interceptorElement = interceptorType.asElement();
if (interceptorElement.getKind().isClass()) {
if (!annotationHelper.isAbstract(interceptorElement)) {
if (interceptorElement.getAnnotation(EBean.class) == null) {
List<ExecutableElement> constructors = ElementFilter.constructorsIn(interceptorElement.getEnclosedElements());
boolean hasPublicWithNoArgumentConstructor = false;
for (ExecutableElement constructor : constructors) {
if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) {
hasPublicWithNoArgumentConstructor = true;
}
}
if (!hasPublicWithNoArgumentConstructor) {
valid.addError("The interceptor class must have a public no argument constructor or be annotated with @EBean");
}
}
} else {
valid.addError("The interceptor class must not be abstract");
}
} else {
valid.addError("The interceptor class must be a class");
}
} else {
valid.addError("The interceptor class must be a subtype of " + CLIENT_HTTP_REQUEST_INTERCEPTOR);
}
}
}
Aggregations