Search in sources :

Example 1 with EBean

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());
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Element(javax.lang.model.element.Element) AbstractJClass(com.helger.jcodemodel.AbstractJClass) EBean(org.androidannotations.annotations.EBean) EBean(org.androidannotations.annotations.EBean) Bean(org.androidannotations.annotations.Bean)

Example 2 with EBean

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();
    }
}
Also used : EBean(org.androidannotations.annotations.EBean)

Example 3 with EBean

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);
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) EBean(org.androidannotations.annotations.EBean) DeclaredType(javax.lang.model.type.DeclaredType)

Example 4 with EBean

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);
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) EBean(org.androidannotations.annotations.EBean) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

EBean (org.androidannotations.annotations.EBean)4 Element (javax.lang.model.element.Element)3 TypeMirror (javax.lang.model.type.TypeMirror)3 ExecutableElement (javax.lang.model.element.ExecutableElement)2 TypeElement (javax.lang.model.element.TypeElement)2 VariableElement (javax.lang.model.element.VariableElement)2 DeclaredType (javax.lang.model.type.DeclaredType)2 AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 Bean (org.androidannotations.annotations.Bean)1