use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.
the class JAXBUtil method findAdapterType.
protected static AdapterType findAdapterType(DecoratedTypeMirror maybeContainedAdaptedType, Element referer, PackageElement pckg, EnunciateJaxbContext context) {
DecoratedProcessingEnvironment env = context.getContext().getProcessingEnvironment();
TypeMirror adaptedType = TypeMirrorUtils.getComponentType(maybeContainedAdaptedType, env);
adaptedType = adaptedType == null ? maybeContainedAdaptedType : adaptedType;
XmlJavaTypeAdapter typeAdapterInfo = referer != null ? referer.getAnnotation(XmlJavaTypeAdapter.class) : null;
if (adaptedType instanceof DeclaredType) {
if (typeAdapterInfo == null) {
typeAdapterInfo = ((DeclaredType) adaptedType).asElement().getAnnotation(XmlJavaTypeAdapter.class);
}
if ((typeAdapterInfo == null) && (pckg != null)) {
TypeElement typeDeclaration = (TypeElement) ((DeclaredType) adaptedType).asElement();
typeAdapterInfo = getAdaptersOfPackage(pckg, context).get(typeDeclaration.getQualifiedName().toString());
}
}
if (typeAdapterInfo != null) {
final XmlJavaTypeAdapter finalInfo = typeAdapterInfo;
DecoratedTypeMirror adapterTypeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return finalInfo.value();
}
}, env);
if (adapterTypeMirror instanceof DecoratedDeclaredType) {
AdapterType adapterType = new AdapterType((DecoratedDeclaredType) adapterTypeMirror, context.getContext());
if (!context.getContext().getProcessingEnvironment().getTypeUtils().isSameType(adapterType.getAdaptingType(), adaptedType)) {
return adapterType;
}
}
}
return null;
}
use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.
the class JAXBUtil method getNormalizedCollection.
public static DecoratedDeclaredType getNormalizedCollection(DecoratedTypeMirror typeMirror, DecoratedProcessingEnvironment env) {
DecoratedDeclaredType base = typeMirror.isList() ? TypeMirrorUtils.listType(env) : typeMirror.isCollection() ? TypeMirrorUtils.collectionType(env) : null;
if (base != null) {
// now narrow the component type to what can be valid xml.
DecoratedTypeMirror componentType = findCollectionComponentType((DeclaredType) typeMirror, env);
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 ResourceMethod method loadReturnType.
protected DecoratedTypeMirror loadReturnType() {
DecoratedTypeMirror returnType;
TypeHint hintInfo = getAnnotation(TypeHint.class);
if (hintInfo != null) {
returnType = (DecoratedTypeMirror) TypeHintUtils.getTypeHint(hintInfo, this.env, getReturnType());
returnType.setDeferredDocComment(new ReturnDocComment(this));
} else {
returnType = (DecoratedTypeMirror) getReturnType();
// we can use the type argument to get the entity type
if (returnType.isClass() && returnType.isInstanceOf("com.sun.jersey.api.JResponse")) {
DecoratedDeclaredType jresponse = (DecoratedDeclaredType) returnType;
if (!jresponse.getTypeArguments().isEmpty()) {
DecoratedTypeMirror responseType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(jresponse.getTypeArguments().get(0), this.env);
if (responseType.isDeclared()) {
responseType.setDeferredDocComment(new ReturnDocComment(this));
returnType = responseType;
}
}
} else if ((returnType.isInstanceOf(javax.ws.rs.core.Response.class) || returnType.isInstanceOf(jakarta.ws.rs.core.Response.class)) || returnType.isInstanceOf(java.io.InputStream.class)) {
// generic response that doesn't have a type hint; we'll just have to assume return type of "object"
DecoratedDeclaredType objectType = (DecoratedDeclaredType) TypeMirrorDecorator.decorate(this.env.getElementUtils().getTypeElement(Object.class.getName()).asType(), this.env);
objectType.setDeferredDocComment(new ReturnDocComment(this));
returnType = objectType;
}
}
final ApiOperation apiOperation = getAnnotation(ApiOperation.class);
if (apiOperation != null) {
DecoratedTypeMirror swaggerReturnType = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return apiOperation.response();
}
}, this.env, Void.class);
if (swaggerReturnType != null) {
if (!apiOperation.responseContainer().isEmpty()) {
swaggerReturnType = (DecoratedTypeMirror) this.env.getTypeUtils().getArrayType(swaggerReturnType);
swaggerReturnType.setDeferredDocComment(new ReturnDocComment(this));
}
returnType = swaggerReturnType;
}
}
DecoratedTypeMirror returnWrapped = JAXDocletUtil.getReturnWrapped(getDocComment(), this.env, getContext().getContext().getLogger());
if (returnWrapped != null) {
returnWrapped.setDeferredDocComment(new ReturnWrappedDocComment(this));
returnType = returnWrapped;
}
return returnType;
}
use of com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType in project enunciate by stoicflame.
the class ClientClassnameForMethod method convert.
@Override
public String convert(TypeMirror typeMirror) throws TemplateModelException {
DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror, this.context.getProcessingEnvironment());
if (decorated.isArray()) {
DecoratedTypeMirror componentType = (DecoratedTypeMirror) ((ArrayType) decorated).getComponentType();
if (componentType.isPrimitive()) {
switch(componentType.getKind()) {
case BOOLEAN:
return "com.google.gwt.core.client.JsArrayBoolean";
case BYTE:
// byte arrays serialized as base64-encoded strings.
return "java.lang.String";
case CHAR:
case INT:
case SHORT:
return "com.google.gwt.core.client.JsArrayInteger";
case DOUBLE:
case FLOAT:
case LONG:
return "com.google.gwt.core.client.JsArrayNumber";
default:
return "com.google.gwt.core.client.JsArray";
}
} else if (componentType.isInstanceOf(String.class.getName())) {
return "com.google.gwt.core.client.JsArrayString";
} else {
return "com.google.gwt.core.client.JsArray<" + convert(componentType) + ">";
}
} else if (decorated.isCollection()) {
List<? extends TypeMirror> typeArgs = ((DecoratedDeclaredType) decorated).getTypeArguments();
if (typeArgs != null && typeArgs.size() == 1) {
DecoratedTypeMirror componentType = (DecoratedTypeMirror) typeArgs.iterator().next();
if (componentType.isInstanceOf(String.class.getName())) {
return "com.google.gwt.core.client.JsArrayString";
} else if (componentType.isInstanceOf(Boolean.class.getName())) {
return "com.google.gwt.core.client.JsArrayBoolean";
} else if (componentType.isInstanceOf(Integer.class.getName()) || componentType.isInstanceOf(Character.class.getName()) || componentType.isInstanceOf(Short.class.getName())) {
return "com.google.gwt.core.client.JsArrayInteger";
} else if (componentType.isInstanceOf(Double.class.getName()) || componentType.isInstanceOf(Float.class.getName()) || componentType.isInstanceOf(Long.class.getName())) {
return "com.google.gwt.core.client.JsArrayNumber";
} else {
return "com.google.gwt.core.client.JsArray<" + convert(componentType) + ">";
}
}
return "com.google.gwt.core.client.JsArray";
} else if (decorated.isDeclared()) {
DeclaredType declaredType = ((DeclaredType) decorated);
String fqn = ((TypeElement) declaredType.asElement()).getQualifiedName().toString();
if (classConversions.containsKey(fqn)) {
return classConversions.get(fqn);
}
} else if (decorated.isPrimitive()) {
if (decorated.getKind() == TypeKind.LONG) {
return Long.class.getName();
}
}
return super.convert(typeMirror);
}
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;
}
Aggregations