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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations