/** * Narrows the existing declaration down to its adapting declaration, if it's being adapted. Otherwise, the original declaration will be returned. * * @param declaration The declaration to narrow. * @return The narrowed declaration. */ protected TypeElement narrowToAdaptingType(TypeElement declaration) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this); if (adapterType != null) { TypeMirror adaptingType = adapterType.getAdaptingType(); if (adaptingType.getKind() != TypeKind.DECLARED) { return declaration; } else { TypeElement adaptingDeclaration = (TypeElement) ((DeclaredType) adaptingType).asElement(); if (adaptingDeclaration == null) { throw new EnunciateException(String.format("Class %s is being adapted by a type (%s) that doesn't seem to be on the classpath.", declaration.getQualifiedName(), adaptingType)); } return adaptingDeclaration; } } return declaration; }
typeAdapterInfo = getAdaptersOfPackage(pckg, context).get(typeDeclaration.getQualifiedName().toString());
/** * 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; }
/** * 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; }
/** * Narrows the existing declaration down to its adapting declaration, if it's being adapted. Otherwise, the original declaration will be returned. * * @param declaration The declaration to narrow. * @return The narrowed declaration. */ protected TypeElement narrowToAdaptingType(TypeElement declaration) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this); if (adapterType != null) { TypeMirror adaptingType = adapterType.getAdaptingType(); if (adaptingType.getKind() != TypeKind.DECLARED) { return declaration; } else { TypeElement adaptingDeclaration = (TypeElement) ((DeclaredType) adaptingType).asElement(); if (adaptingDeclaration == null) { throw new EnunciateException(String.format("Class %s is being adapted by a type (%s) that doesn't seem to be on the classpath.", declaration.getQualifiedName(), adaptingType)); } return adaptingDeclaration; } } return declaration; }
typeAdapterInfo = getAdaptersOfPackage(pckg, context).get(typeDeclaration.getQualifiedName().toString());
/** * Finds the adapter type for the specified declaration, if any. * * @param declaration The declaration for which to find that adapter type. * @param context The context. * @return The adapter type, or null if none was specified. */ public static AdapterType findAdapterType(Element declaration, EnunciateJackson1Context context) { DecoratedProcessingEnvironment env = context.getContext().getProcessingEnvironment(); if (declaration instanceof Accessor) { //jaxb accessor can be adapted. Accessor accessor = ((Accessor) declaration); return findAdapterType(accessor.getAccessorType(), accessor, env.getElementUtils().getPackageOf(accessor.getTypeDefinition()), context); } else if (declaration instanceof ExecutableElement) { //assume the return type of the method is adaptable (e.g. web results, fault bean getters). ExecutableElement method = ((ExecutableElement) declaration); return findAdapterType((DecoratedTypeMirror) method.getReturnType(), method, env.getElementUtils().getPackageOf(method), context); } else if (declaration instanceof TypeElement) { return findAdapterType((DecoratedDeclaredType) declaration.asType(), null, null, context); } else { throw new IllegalArgumentException("A " + declaration.getClass().getSimpleName() + " is not an adaptable declaration according to the JAXB spec."); } }
/** * Finds the adapter type for the specified declaration, if any. * * @param declaration The declaration for which to find that adapter type. * @param context The context. * @return The adapter type, or null if none was specified. */ public static AdapterType findAdapterType(Element declaration, EnunciateJackson1Context context) { DecoratedProcessingEnvironment env = context.getContext().getProcessingEnvironment(); if (declaration instanceof Accessor) { //jaxb accessor can be adapted. Accessor accessor = ((Accessor) declaration); return findAdapterType(accessor.getAccessorType(), accessor, env.getElementUtils().getPackageOf(accessor.getTypeDefinition()), context); } else if (declaration instanceof ExecutableElement) { //assume the return type of the method is adaptable (e.g. web results, fault bean getters). ExecutableElement method = ((ExecutableElement) declaration); return findAdapterType((DecoratedTypeMirror) method.getReturnType(), method, env.getElementUtils().getPackageOf(method), context); } else if (declaration instanceof TypeElement) { return findAdapterType((DecoratedDeclaredType) declaration.asType(), null, null, context); } else { throw new IllegalArgumentException("A " + declaration.getClass().getSimpleName() + " is not an adaptable declaration according to the JAXB spec."); } }
public Accessor(javax.lang.model.element.Element delegate, TypeDefinition typeDef, EnunciateJackson1Context context) { super(delegate, context.getContext().getProcessingEnvironment()); this.typeDefinition = typeDef; this.facets.addAll(Facet.gatherFacets(delegate, context.getContext())); this.facets.addAll(typeDef.getFacets()); this.context = context; this.adapterType = JacksonUtil.findAdapterType(this, context); }
public Accessor(javax.lang.model.element.Element delegate, TypeDefinition typeDef, EnunciateJackson1Context context) { super(delegate, context.getContext().getProcessingEnvironment()); this.typeDefinition = typeDef; this.facets.addAll(Facet.gatherFacets(delegate, context.getContext())); this.facets.addAll(typeDef.getFacets()); this.context = context; this.adapterType = JacksonUtil.findAdapterType(this, context); }
public TypeMirror findAdaptingType(TypeElement declaration) { if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return adapterType.getAdaptingType(); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType otherAdapterType = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (otherAdapterType != null) { return otherAdapterType.getAdaptingType(); } } return null; }
public TypeMirror findAdaptingType(TypeElement declaration) { if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return adapterType.getAdaptingType(); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType otherAdapterType = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (otherAdapterType != null) { return otherAdapterType.getAdaptingType(); } } return null; }
public TypeMirror findAdaptingType(TypeElement declaration) { if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return adapterType.getAdaptingType(); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType otherAdapterType = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (otherAdapterType != null) { return otherAdapterType.getAdaptingType(); } } return null; }
public static DeclaredType findMapTypeDeclaration(TypeMirror typeMirror, EnunciateJackson1Context 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 = JacksonUtil.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; }
public static DeclaredType findMapTypeDeclaration(TypeMirror typeMirror, EnunciateJackson1Context 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 = JacksonUtil.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; }
@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"; } if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType adapter1Type = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (adapter1Type != null) { return convert(adapter1Type.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; }
@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"; } if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType adapter1Type = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (adapter1Type != null) { return convert(adapter1Type.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; }
@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"; } if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType adapter1Type = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (adapter1Type != null) { return convert(adapter1Type.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; }
@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"; } if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType adapter1Type = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (adapter1Type != null) { return convert(adapter1Type.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; }
@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"; } if (this.jacksonContext != null) { AdapterType adapterType = JacksonUtil.findAdapterType(declaration, this.jacksonContext); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } } if (this.jackson1Context != null) { com.webcohesion.enunciate.modules.jackson1.model.adapters.AdapterType adapter1Type = com.webcohesion.enunciate.modules.jackson1.model.util.JacksonUtil.findAdapterType(declaration, this.jackson1Context); if (adapter1Type != null) { return convert(adapter1Type.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; }