/** * Finds the interface type that declares that the specified declaration implements XmlAdapter. * * @param declaredType The declaration. * @return The interface type, or null if none found. */ private static DeclaredType findXmlAdapterType(DeclaredType declaredType, TypeVariableContext variableContext, DecoratedProcessingEnvironment env) { TypeElement element = (TypeElement) declaredType.asElement(); if (element == null) { return null; } else if (Object.class.getName().equals(element.getQualifiedName().toString())) { return null; } else if (XmlAdapter.class.getName().equals(element.getQualifiedName().toString())) { return (DeclaredType) variableContext.resolveTypeVariables(declaredType, env); } else { DeclaredType superclass = (DeclaredType) element.getSuperclass(); if (superclass == null || superclass.getKind() == TypeKind.NONE) { return null; } else { return findXmlAdapterType(superclass, variableContext.push(element.getTypeParameters(), declaredType.getTypeArguments()), env); } } }
/** * Finds the interface type that declares that the specified declaration implements XmlAdapter. * * @param declaredType The declaration. * @return The interface type, or null if none found. */ private static DeclaredType findXmlAdapterType(DeclaredType declaredType, TypeVariableContext variableContext, DecoratedProcessingEnvironment env) { TypeElement element = (TypeElement) declaredType.asElement(); if (element == null) { return null; } else if (Object.class.getName().equals(element.getQualifiedName().toString())) { return null; } else if (XmlAdapter.class.getName().equals(element.getQualifiedName().toString())) { return (DeclaredType) variableContext.resolveTypeVariables(declaredType, env); } else { DeclaredType superclass = (DeclaredType) element.getSuperclass(); if (superclass == null || superclass.getKind() == TypeKind.NONE) { return null; } else { return findXmlAdapterType(superclass, variableContext.push(element.getTypeParameters(), declaredType.getTypeArguments()), env); } } }
public AdapterType(DeclaredType adapterType, EnunciateJackson1Context context) { super(adapterType, context.getContext().getProcessingEnvironment()); if (context.isHonorJaxb()) { DeclaredType adaptorInterfaceType = findXmlAdapterType(adapterType, new TypeVariableContext(), context.getContext().getProcessingEnvironment()); if (adaptorInterfaceType == null) { throw new EnunciateException(adapterType + " is not an instance of javax.xml.bind.annotation.adapters.XmlAdapter."); } List<? extends TypeMirror> adaptorTypeArgs = adaptorInterfaceType.getTypeArguments(); if ((adaptorTypeArgs == null) || (adaptorTypeArgs.size() != 2)) { throw new EnunciateException(adapterType + " must specify both a value type and a bound type."); } this.adaptingType = adaptorTypeArgs.get(0); this.adaptedType = context.getContext().getProcessingEnvironment().getTypeUtils().erasure(adaptorTypeArgs.get(1)); } else { throw new EnunciateException(adapterType + " is not an instance of javax.xml.bind.annotation.adapters.XmlAdapter."); } }
public AdapterType(DeclaredType adapterType, EnunciateJackson1Context context) { super(adapterType, context.getContext().getProcessingEnvironment()); if (context.isHonorJaxb()) { DeclaredType adaptorInterfaceType = findXmlAdapterType(adapterType, new TypeVariableContext(), context.getContext().getProcessingEnvironment()); if (adaptorInterfaceType == null) { throw new EnunciateException(adapterType + " is not an instance of javax.xml.bind.annotation.adapters.XmlAdapter."); } List<? extends TypeMirror> adaptorTypeArgs = adaptorInterfaceType.getTypeArguments(); if ((adaptorTypeArgs == null) || (adaptorTypeArgs.size() != 2)) { throw new EnunciateException(adapterType + " must specify both a value type and a bound type."); } this.adaptingType = adaptorTypeArgs.get(0); this.adaptedType = context.getContext().getProcessingEnvironment().getTypeUtils().erasure(adaptorTypeArgs.get(1)); } else { throw new EnunciateException(adapterType + " is not an instance of javax.xml.bind.annotation.adapters.XmlAdapter."); } }