Search in sources :

Example 1 with DecoratedVariableElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement in project enunciate by stoicflame.

the class AccessorFilter method accept.

/**
 * Whether to accept the given member declaration as an accessor.
 *
 * @param element The declaration to filter.
 * @return Whether to accept the given member declaration as an accessor.
 */
public boolean accept(DecoratedElement<?> element) {
    if (context.isIgnored(element)) {
        return false;
    }
    if (element.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class) != null) {
        // if there's an explicit json property annotation, we'll include it.
        return true;
    }
    if (this.honorJaxb) {
        if (element.getAnnotation(XmlTransient.class) != null) {
            return false;
        }
        for (String annotationName : element.getAnnotations().keySet()) {
            if (annotationName.startsWith("javax.xml.bind.annotation")) {
                // if the property has an explicit annotation, we'll include it.
                return true;
            }
        }
    }
    String name = element.getSimpleName().toString();
    if ("".equals(name)) {
        return false;
    }
    if (this.propertiesToIgnore.contains(name)) {
        return false;
    }
    if (element instanceof PropertyElement) {
        PropertyElement property = ((PropertyElement) element);
        DecoratedExecutableElement getter = property.getGetter();
        if (getter == null) {
            // needs a getter.
            return false;
        }
        if (!isVisible(findGetterVisibility(getter), getter)) {
            return false;
        }
        DecoratedExecutableElement setter = property.getSetter();
        if (setter != null && !isVisible(findSetterVisibility(), setter)) {
            return false;
        }
        return true;
    } else if (element instanceof DecoratedVariableElement) {
        if (!isVisible(findFieldVisibility(), element)) {
            return false;
        }
        if (element.isStatic() || element.isTransient()) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) XmlTransient(javax.xml.bind.annotation.XmlTransient) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Example 2 with DecoratedVariableElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement in project enunciate by stoicflame.

the class AccessorFilter method accept.

/**
 * Whether to accept the given member declaration as an accessor.
 *
 * @param element The declaration to filter.
 * @return Whether to accept the given member declaration as an accessor.
 */
public boolean accept(DecoratedElement<?> element) {
    if (AnnotationUtils.isIgnored(element)) {
        return false;
    }
    if (element.getAnnotation(XmlTransient.class) != null) {
        return false;
    }
    if (element instanceof PropertyElement) {
        PropertyElement property = ((PropertyElement) element);
        if ("".equals(property.getPropertyName())) {
            return false;
        }
        for (String annotationName : property.getAnnotations().keySet()) {
            if (annotationName.startsWith("javax.xml.bind.annotation")) {
                // if the property has an explicit annotation, we'll include it.
                return true;
            }
        }
        DecoratedExecutableElement getter = property.getGetter();
        if (getter == null) {
            // needs a getter.
            return false;
        }
        DecoratedExecutableElement setter = property.getSetter();
        if (setter == null) {
            // needs a setter.
            return false;
        }
        if (!getter.isPublic()) {
            // we only have to worry about public methods ("properties" are only defined by public accessor methods).
            return false;
        }
        if (!setter.isPublic()) {
            // we only have to worry about public methods ("properties" are only defined by public accessor methods).
            return false;
        }
        return (((accessType != XmlAccessType.NONE) && (accessType != XmlAccessType.FIELD)) || (explicitlyDeclaredAccessor(element)));
    } else if (element instanceof DecoratedVariableElement) {
        if (element.isStatic() || element.isTransient()) {
            return false;
        }
        if ((accessType == XmlAccessType.NONE) || (accessType == XmlAccessType.PROPERTY)) {
            return explicitlyDeclaredAccessor(element);
        }
        if (accessType == XmlAccessType.PUBLIC_MEMBER) {
            return (element.isPublic() || (explicitlyDeclaredAccessor(element)));
        }
        // the accessType is FIELD.  Include it.
        return true;
    }
    return false;
}
Also used : DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) XmlTransient(javax.xml.bind.annotation.XmlTransient) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Example 3 with DecoratedVariableElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement in project enunciate by stoicflame.

the class RequestParameterFactory method gatherFormObjectParameters.

private static void gatherFormObjectParameters(TypeMirror type, ArrayList<RequestParameter> params, RequestMapping context) {
    if (type instanceof DeclaredType) {
        Set<String> methods = context.getHttpMethods();
        ResourceParameterType defaultType = methods.contains("POST") ? ResourceParameterType.FORM : ResourceParameterType.QUERY;
        DecoratedTypeElement typeDeclaration = (DecoratedTypeElement) ElementDecorator.decorate(((DeclaredType) type).asElement(), context.getContext().getContext().getProcessingEnvironment());
        for (VariableElement field : ElementFilter.fieldsIn(typeDeclaration.getEnclosedElements())) {
            DecoratedVariableElement decorated = (DecoratedVariableElement) field;
            if (!decorated.isFinal() && !decorated.isTransient() && decorated.isPublic()) {
                params.add(new SimpleRequestParameter(decorated, context, defaultType));
            }
        }
        for (PropertyElement property : typeDeclaration.getProperties()) {
            if (property.getSetter() != null) {
                params.add(new SimpleRequestParameter(property, context, defaultType));
            }
        }
        if (typeDeclaration.getKind() == ElementKind.CLASS) {
            gatherFormObjectParameters(typeDeclaration.getSuperclass(), params, context);
        }
    }
}
Also used : DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) DeclaredType(javax.lang.model.type.DeclaredType) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Example 4 with DecoratedVariableElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement in project enunciate by stoicflame.

the class AccessorFilter method accept.

/**
 * Whether to accept the given member declaration as an accessor.
 *
 * @param element The declaration to filter.
 * @return Whether to accept the given member declaration as an accessor.
 */
public boolean accept(DecoratedElement<?> element) {
    if (context.isIgnored(element)) {
        return false;
    }
    if (element.getAnnotation(JsonProperty.class) != null) {
        // if there's an explicit json property annotation, we'll include it.
        return true;
    }
    if (this.honorJaxb) {
        if (element.getAnnotation(XmlTransient.class) != null) {
            return false;
        }
        for (String annotationName : element.getAnnotations().keySet()) {
            if (annotationName.startsWith("javax.xml.bind.annotation")) {
                // if the property has an explicit annotation, we'll include it.
                return true;
            }
        }
    }
    String name = element.getSimpleName().toString();
    if ("".equals(name)) {
        return false;
    }
    if (this.propertiesToIgnore.contains(name)) {
        return false;
    }
    if (element instanceof PropertyElement) {
        PropertyElement property = ((PropertyElement) element);
        DecoratedExecutableElement getter = property.getGetter();
        if (getter == null) {
            // needs a getter.
            return false;
        }
        if (!isVisible(findGetterVisibility(getter), getter)) {
            return false;
        }
        DecoratedExecutableElement setter = property.getSetter();
        if (setter != null && !isVisible(findSetterVisibility(), setter)) {
            return false;
        }
        return true;
    } else if (element instanceof DecoratedVariableElement) {
        if (!isVisible(findFieldVisibility(), element)) {
            return false;
        }
        if (element.isStatic() || element.isTransient()) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : JsonProperty(org.codehaus.jackson.annotate.JsonProperty) DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) XmlTransient(javax.xml.bind.annotation.XmlTransient) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Aggregations

DecoratedVariableElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement)4 PropertyElement (com.webcohesion.enunciate.javac.decorations.element.PropertyElement)4 DecoratedExecutableElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement)3 XmlTransient (javax.xml.bind.annotation.XmlTransient)3 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 JsonProperty (org.codehaus.jackson.annotate.JsonProperty)1