Search in sources :

Example 6 with AdapterType

use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.

the class MapType method findMapTypeDeclaration.

public static DeclaredType findMapTypeDeclaration(TypeMirror typeMirror, EnunciateJaxbContext context) {
    if (!(typeMirror instanceof DeclaredType)) {
        return null;
    }
    DeclaredType declaredType = (DeclaredType) typeMirror;
    TypeElement element = (TypeElement) declaredType.asElement();
    String fqn = element.getQualifiedName().toString();
    if (Map.class.getName().equals(fqn)) {
        return declaredType;
    }
    AdapterType adapterType = JAXBUtil.findAdapterType(element, context);
    if (adapterType != null) {
        return findMapTypeDeclaration(adapterType.getAdaptingType(), context);
    }
    DeclaredType mapType = null;
    Types typeUtils = context.getContext().getProcessingEnvironment().getTypeUtils();
    List<? extends TypeMirror> supers = typeUtils.directSupertypes(declaredType);
    for (TypeMirror superInterface : supers) {
        mapType = findMapTypeDeclaration(superInterface, context);
        if (mapType != null) {
            break;
        }
    }
    return mapType;
}
Also used : Types(javax.lang.model.util.Types) TypeMirror(javax.lang.model.type.TypeMirror) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) AdapterType(com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType) HashMap(java.util.HashMap) Map(java.util.Map) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 7 with AdapterType

use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.

the class ClientClassnameForMethod method convert.

@Override
public String convert(TypeElement declaration) throws TemplateModelException {
    String fqn = declaration.getQualifiedName().toString();
    if (classConversions.containsKey(fqn)) {
        return classConversions.get(fqn);
    } else if (declaration.getKind() == ElementKind.ENUM) {
        return "String";
    } else if (isCollection(declaration) || isMap(declaration)) {
        return "Array";
    }
    AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
    if (adapterType != null) {
        return convert(adapterType.getAdaptingType());
    }
    String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
    ClientName specifiedName = declaration.getAnnotation(ClientName.class);
    String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
    return convertedPackage + getPackageSeparator() + simpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName) AdapterType(com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)

Example 8 with AdapterType

use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.

the class ClientClassnameForMethod method convert.

@Override
public String convert(TypeElement declaration) throws TemplateModelException {
    String fqn = declaration.getQualifiedName().toString();
    if (classConversions.containsKey(fqn)) {
        return classConversions.get(fqn);
    } else if (isCollection(declaration)) {
        return "NSArray";
    }
    AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
    if (adapterType != null) {
        return convert(adapterType.getAdaptingType());
    }
    if (declaration.getKind() == ElementKind.CLASS) {
        DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
        if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
            // for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
            return convert(superType);
        }
    }
    String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
    ClientName specifiedName = declaration.getAnnotation(ClientName.class);
    String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
    return convertedPackage + getPackageSeparator() + simpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) AdapterType(com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)

Example 9 with AdapterType

use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.

the class ClientClassnameForMethod method convert.

@Override
public String convert(TypeElement declaration) throws TemplateModelException {
    String fqn = declaration.getQualifiedName().toString();
    if (classConversions.containsKey(fqn)) {
        return classConversions.get(fqn);
    } else if (isCollection(declaration)) {
        return "xmlNode";
    }
    AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
    if (adapterType != null) {
        return convert(adapterType.getAdaptingType());
    }
    if (declaration.getKind() == ElementKind.CLASS) {
        DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
        if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
            // for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
            return convert(superType);
        }
    }
    String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
    ClientName specifiedName = declaration.getAnnotation(ClientName.class);
    String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
    return convertedPackage + getPackageSeparator() + simpleName;
}
Also used : ClientName(com.webcohesion.enunciate.metadata.ClientName) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) AdapterType(com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)

Aggregations

AdapterType (com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType)9 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)6 ClientName (com.webcohesion.enunciate.metadata.ClientName)6 TypeElement (javax.lang.model.element.TypeElement)3 DecoratedDeclaredType (com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)2 DeclaredType (javax.lang.model.type.DeclaredType)2 TypeMirror (javax.lang.model.type.TypeMirror)2 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 DecoratedProcessingEnvironment (com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment)1 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)1 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)1 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Element (javax.lang.model.element.Element)1 Types (javax.lang.model.util.Types)1 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)1