use of com.webcohesion.enunciate.modules.jackson1.model.types.JsonClassType in project enunciate by stoicflame.
the class JsonTypeVisitor method visitDeclared.
@Override
public JsonType visitDeclared(DeclaredType declaredType, Context context) {
JsonType jsonType = null;
Element declaredElement = declaredType.asElement();
DecoratedProcessingEnvironment env = context.getContext().getContext().getProcessingEnvironment();
DecoratedTypeMirror decoratedTypeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaredType, env);
String fqn = declaredElement instanceof TypeElement ? ((TypeElement) declaredElement).getQualifiedName().toString() : declaredType.toString();
if (context.getStack().contains(fqn) && !decoratedTypeMirror.isCollection() && !decoratedTypeMirror.isStream()) {
// break out of recursive loop.
return wrapAsNeeded(KnownJsonType.OBJECT, context);
}
context.getStack().push(fqn);
try {
TypeHint typeHint = declaredElement.getAnnotation(TypeHint.class);
if (typeHint != null) {
TypeMirror hint = TypeHintUtils.getTypeHint(typeHint, context.getContext().getContext().getProcessingEnvironment(), null);
if (hint != null) {
jsonType = hint.accept(this, new Context(context.context, false, false, context.stack));
}
}
final JsonSerialize serializeInfo = declaredElement.getAnnotation(JsonSerialize.class);
if (serializeInfo != null) {
DecoratedTypeMirror using = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return serializeInfo.using();
}
}, env, JsonSerializer.None.class);
if (using != null) {
// custom serializer; just say it's an object.
jsonType = KnownJsonType.OBJECT;
}
DecoratedTypeMirror as = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return serializeInfo.as();
}
}, env, Void.class);
if (as != null) {
jsonType = (JsonType) as.accept(this, new Context(context.context, false, false, context.stack));
}
}
AdapterType adapterType = JacksonUtil.findAdapterType(declaredElement, context.getContext());
if (adapterType != null) {
adapterType.getAdaptingType().accept(this, new Context(context.context, false, false, context.stack));
} else {
MapType mapType = MapType.findMapType(declaredType, context.getContext());
if (mapType != null) {
JsonType keyType = mapType.getKeyType().accept(this, new Context(context.getContext(), false, false, context.getStack()));
JsonType valueType = mapType.getValueType().accept(this, new Context(context.getContext(), false, false, context.getStack()));
jsonType = new JsonMapType(keyType, valueType);
} else {
TypeMirror componentType = getComponentType(decoratedTypeMirror, env);
if (componentType != null) {
return wrapAsNeeded(componentType.accept(this, new Context(context.context, false, true, context.stack)), context);
} else {
switch(declaredElement.getKind()) {
case ENUM:
case CLASS:
case INTERFACE:
JsonType knownType = context.getContext().getKnownType(declaredElement);
if (knownType != null) {
jsonType = knownType;
} else {
// type not known, not specified. Last chance: look for the type definition.
TypeDefinition typeDefinition = context.getContext().findTypeDefinition(declaredElement);
if (typeDefinition != null) {
jsonType = new JsonClassType(typeDefinition);
}
}
break;
}
}
}
}
if (jsonType == null) {
jsonType = super.visitDeclared(declaredType, context);
}
return wrapAsNeeded(jsonType, context);
} finally {
context.getStack().pop();
}
}
use of com.webcohesion.enunciate.modules.jackson1.model.types.JsonClassType in project enunciate by stoicflame.
the class ObjectDataTypeImpl method getSupertypes.
@Override
public List<DataTypeReference> getSupertypes() {
ArrayList<DataTypeReference> supertypes = null;
JsonType supertype = this.typeDefinition.getSupertype();
while (supertype != null) {
if (supertypes == null) {
supertypes = new ArrayList<DataTypeReference>();
}
supertypes.add(new DataTypeReferenceImpl(supertype, registrationContext));
supertype = supertype instanceof JsonClassType ? ((JsonClassType) supertype).getTypeDefinition() instanceof ObjectTypeDefinition ? ((ObjectTypeDefinition) ((JsonClassType) supertype).getTypeDefinition()).getSupertype() : null : null;
}
return supertypes;
}
use of com.webcohesion.enunciate.modules.jackson1.model.types.JsonClassType in project enunciate by stoicflame.
the class Member method getAccessorType.
/**
* The type of an element accessor can be specified by an annotation.
*
* @return The accessor type.
*/
@Override
public DecoratedTypeMirror getAccessorType() {
if (this.explicitType != null) {
return this.explicitType;
}
JsonType specifiedJsonType = JsonTypeFactory.findSpecifiedType(this, this.context);
DecoratedTypeMirror specifiedType = specifiedJsonType instanceof JsonClassType ? (DecoratedTypeMirror) ((JsonClassType) specifiedJsonType).getTypeDefinition().asType() : null;
if (specifiedType != null) {
return specifiedType;
}
return super.getAccessorType();
}
use of com.webcohesion.enunciate.modules.jackson1.model.types.JsonClassType in project enunciate by stoicflame.
the class ObjectDataTypeImpl method gatherInterfaces.
private void gatherInterfaces(TypeElement clazz, Set<DataTypeReference> interfaces) {
if (clazz == null) {
return;
}
if (clazz.getQualifiedName().contentEquals(Object.class.getName())) {
return;
}
List<? extends TypeMirror> ifaces = clazz.getInterfaces();
for (TypeMirror iface : ifaces) {
DecoratedTypeMirror decorated = (DecoratedTypeMirror) iface;
decorated = this.typeDefinition.getContext().resolveSyntheticType(decorated);
TypeDefinition typeDefinition = this.typeDefinition.getContext().findTypeDefinition(((DeclaredType) decorated).asElement());
if (typeDefinition != null) {
interfaces.add(new DataTypeReferenceImpl(new JsonClassType(typeDefinition), registrationContext));
}
}
TypeMirror superclass = clazz.getSuperclass();
if (superclass instanceof DeclaredType) {
gatherInterfaces((TypeElement) ((DeclaredType) superclass).asElement(), interfaces);
}
}
Aggregations