Search in sources :

Example 16 with DecoratedDeclaredType

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

the class ElementRef method loadRef.

/**
 * Load the qname of the referenced root element declaration.
 *
 * @return the qname of the referenced root element declaration.
 */
protected ReferencedElement loadRef() {
    DecoratedTypeMirror refType = null;
    if (xmlElementRef != null) {
        refType = Annotations.mirrorOf(new Callable<Class<?>>() {

            @Override
            public Class<?> call() throws Exception {
                return xmlElementRef.type();
            }
        }, this.env, XmlElementRef.DEFAULT.class);
    }
    if (refType == null) {
        refType = getBareAccessorType();
    }
    TypeElement declaration = null;
    if (refType.isDeclared()) {
        declaration = (TypeElement) ((DeclaredType) refType).asElement();
    }
    ReferencedElement referencedElement = null;
    if (refType.isInstanceOf(JAXBElement.class)) {
        String localName = xmlElementRef != null && !"##default".equals(xmlElementRef.name()) ? xmlElementRef.name() : null;
        String namespace = xmlElementRef != null ? xmlElementRef.namespace() : "";
        if (localName == null) {
            throw new EnunciateException("Member " + getName() + " of " + getTypeDefinition().getQualifiedName() + ": @XmlElementRef annotates a type JAXBElement without specifying the name of the JAXB element.");
        }
        QName refQname = new QName(namespace, localName);
        List<? extends TypeMirror> elementTypeArguments = ((DecoratedDeclaredType) refType).getTypeArguments();
        DecoratedTypeMirror elementOf = elementTypeArguments == null || elementTypeArguments.size() != 1 ? TypeMirrorUtils.objectType(context.getContext().getProcessingEnvironment()) : (DecoratedTypeMirror) elementTypeArguments.get(0);
        referencedElement = new TypeReferencedElement(refQname, elementOf);
    } else if (declaration != null && declaration.getAnnotation(XmlRootElement.class) != null) {
        RootElementDeclaration refElement = new RootElementDeclaration(declaration, null, this.context);
        referencedElement = new DeclarationReferencedElement(new QName(refElement.getNamespace(), refElement.getName()), declaration);
    }
    if (referencedElement == null) {
        throw new EnunciateException("Member " + getSimpleName() + " of " + getTypeDefinition().getQualifiedName() + ": " + refType + " is neither JAXBElement nor a root element declaration.");
    }
    return referencedElement;
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) QName(javax.xml.namespace.QName) Callable(java.util.concurrent.Callable) EnunciateException(com.webcohesion.enunciate.EnunciateException) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 17 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 18 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 19 with DecoratedDeclaredType

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

the class JacksonUtil method getNormalizedCollection.

public static DecoratedDeclaredType getNormalizedCollection(DecoratedTypeMirror typeMirror, DecoratedProcessingEnvironment env) {
    DecoratedDeclaredType base = typeMirror.isList() ? TypeMirrorUtils.listType(env) : typeMirror.isCollection() || typeMirror.isStream() ? TypeMirrorUtils.collectionType(env) : null;
    if (base != null) {
        // now narrow the component type to what can be valid json.
        List<? extends DecoratedTypeMirror> typeArgs = (List<? extends DecoratedTypeMirror>) ((DeclaredType) typeMirror).getTypeArguments();
        if (typeArgs.size() == 1) {
            DecoratedTypeMirror componentType = typeArgs.get(0);
            base = (DecoratedDeclaredType) env.getTypeUtils().getDeclaredType((TypeElement) base.asElement(), componentType);
        }
    }
    return base;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) List(java.util.List)

Example 20 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.jackson.model.util.MapType)

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