Search in sources :

Example 6 with DecoratedDeclaredType

use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.

the class JacksonUtil method findAdapterType.

private static AdapterType findAdapterType(DecoratedTypeMirror maybeContainedAdaptedType, Element referer, EnunciateJacksonContext context) {
    DecoratedProcessingEnvironment env = context.getContext().getProcessingEnvironment();
    TypeMirror adaptedType = TypeMirrorUtils.getComponentType(maybeContainedAdaptedType, env);
    final boolean isContained = adaptedType != null;
    adaptedType = isContained ? adaptedType : maybeContainedAdaptedType;
    JsonSerialize serializationInfo = referer != null ? referer.getAnnotation(JsonSerialize.class) : null;
    if (serializationInfo == null && adaptedType instanceof DeclaredType) {
        serializationInfo = ((DeclaredType) adaptedType).asElement().getAnnotation(JsonSerialize.class);
    }
    if (serializationInfo != null) {
        final JsonSerialize finalInfo = serializationInfo;
        DecoratedTypeMirror adapterTypeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {

            @Override
            public Class<?> call() throws Exception {
                return isContained ? finalInfo.contentConverter() : finalInfo.converter();
            }
        }, env, Converter.None.class);
        if (adapterTypeMirror instanceof DeclaredType) {
            return new AdapterType((DeclaredType) adapterTypeMirror, context);
        }
    }
    if (context.isHonorJaxb()) {
        XmlJavaTypeAdapter typeAdapterInfo = referer != null ? referer.getAnnotation(XmlJavaTypeAdapter.class) : null;
        if (adaptedType instanceof DeclaredType) {
            if (typeAdapterInfo == null) {
                typeAdapterInfo = ((DeclaredType) adaptedType).asElement().getAnnotation(XmlJavaTypeAdapter.class);
            }
        }
        if (typeAdapterInfo != null) {
            final XmlJavaTypeAdapter finalInfo = typeAdapterInfo;
            DecoratedTypeMirror adapterTypeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {

                @Override
                public Class<?> call() throws Exception {
                    return finalInfo.value();
                }
            }, env);
            if (adapterTypeMirror instanceof DecoratedDeclaredType) {
                AdapterType adapterType = new AdapterType((DecoratedDeclaredType) adapterTypeMirror, context);
                if (!context.getContext().getProcessingEnvironment().getTypeUtils().isSameType(adapterType.getAdaptingType(), adaptedType)) {
                    return adapterType;
                }
            }
        }
    }
    return null;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) AdapterType(com.webcohesion.enunciate.modules.jackson.model.adapters.AdapterType) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) DecoratedProcessingEnvironment(com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment) EnunciateException(com.webcohesion.enunciate.EnunciateException) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) TypeMirror(javax.lang.model.type.TypeMirror) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) Converter(com.fasterxml.jackson.databind.util.Converter) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 7 with DecoratedDeclaredType

use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.

the class DataTypeExampleImpl method getDocumentationExampleTags.

private JavaDoc.JavaDocTagList getDocumentationExampleTags(Member member) {
    JavaDoc.JavaDocTagList tags = member.getJavaDoc().get("documentationExample");
    if (tags == null || tags.isEmpty()) {
        DecoratedTypeMirror accessorType = member.getBareAccessorType();
        if (accessorType instanceof DecoratedDeclaredType) {
            Element element = ((DecoratedDeclaredType) accessorType).asElement();
            tags = element instanceof DecoratedElement ? ((DecoratedElement) element).getJavaDoc().get("documentationExample") : null;
        }
    }
    return tags;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) Element(javax.lang.model.element.Element) JavaDoc(com.webcohesion.enunciate.javac.javadoc.JavaDoc)

Example 8 with DecoratedDeclaredType

use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.

the class DataTypeExampleImpl method getConfiguredExample.

private String getConfiguredExample(Member member) {
    String configuredExample = null;
    DecoratedTypeMirror accessorType = member.getBareAccessorType();
    if (accessorType instanceof DecoratedDeclaredType) {
        Element element = ((DecoratedDeclaredType) accessorType).asElement();
        if (element instanceof TypeElement) {
            configuredExample = member.getContext().lookupExternalExample((TypeElement) element);
        }
    }
    return configuredExample;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) Element(javax.lang.model.element.Element)

Example 9 with DecoratedDeclaredType

use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.

the class Accessor method getAccessorType.

/**
 * The type of the accessor.
 *
 * @return The type of the accessor.
 */
public DecoratedTypeMirror getAccessorType() {
    DecoratedTypeMirror accessorType = (DecoratedTypeMirror) asType();
    accessorType = OptionalUtils.stripOptional(accessorType, this.context.getContext().getProcessingEnvironment());
    accessorType = this.context.resolveSyntheticType(accessorType);
    DecoratedDeclaredType normalizedCollection = JacksonUtil.getNormalizedCollection(accessorType, this.context.getContext().getProcessingEnvironment());
    if (normalizedCollection != null) {
        accessorType = normalizedCollection;
    } else {
        MapType mapType = MapType.findMapType(accessorType, this.context);
        if (mapType != null) {
            accessorType = mapType;
        }
    }
    return accessorType;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) MapType(com.webcohesion.enunciate.modules.jackson1.model.util.MapType)

Example 10 with DecoratedDeclaredType

use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.

the class ComplexTypeExampleImpl method getConfiguredExample.

private String getConfiguredExample(Accessor member) {
    String configuredExample = null;
    DecoratedTypeMirror accessorType = member.getBareAccessorType();
    if (accessorType instanceof DecoratedDeclaredType) {
        javax.lang.model.element.Element element = ((DecoratedDeclaredType) accessorType).asElement();
        if (element instanceof TypeElement) {
            configuredExample = member.getContext().lookupExternalExample((TypeElement) element);
        }
    }
    return configuredExample;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement)

Aggregations

DecoratedDeclaredType (com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)20 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)19 TypeElement (javax.lang.model.element.TypeElement)8 EnunciateException (com.webcohesion.enunciate.EnunciateException)5 DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)5 DeclaredType (javax.lang.model.type.DeclaredType)5 Element (javax.lang.model.element.Element)4 TypeMirror (javax.lang.model.type.TypeMirror)4 DecoratedProcessingEnvironment (com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment)3 JavaDoc (com.webcohesion.enunciate.javac.javadoc.JavaDoc)3 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)3 JsonSerialize (com.fasterxml.jackson.databind.annotation.JsonSerialize)1 Converter (com.fasterxml.jackson.databind.util.Converter)1 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)1 ReturnDocComment (com.webcohesion.enunciate.javac.javadoc.ReturnDocComment)1 AdapterType (com.webcohesion.enunciate.modules.jackson.model.adapters.AdapterType)1 MapType (com.webcohesion.enunciate.modules.jackson.model.util.MapType)1 AdapterType (com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType)1 MapType (com.webcohesion.enunciate.modules.jackson1.model.util.MapType)1 AdapterType (com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)1