final GeneratorContext context = this.getGeneratorContext();
context.debug(type.getName());
final String newTypeName = this.getGeneratedTypeName(type, SerializationConstants.OBJECT_READER_GENERATED_TYPE_SUFFIX,
"rocket.serialization.client.reader");
final NewConcreteType newConcreteType = context.newConcreteType(newTypeName);
newConcreteType.setAbstract(false);
newConcreteType.setFinal(false);
context.debug(newTypeName);
// pick the right super type.
Type objectReaderSuperType = null;
while (true) {
// if its an array simply extend ObjectArrayReader
if (type.isArray()) {
objectReaderSuperType = this.getArrayReader();
break;
}
// if super type is object extend ObjectReaderImpl
Type superType = type.getSuperType();
if (superType.equals(context.getObject())) {
objectReaderSuperType = this.getObjectReaderImpl();
break;
}
// find the super types object reader and extend that...
objectReaderSuperType = (Type) typesToReaders.get(superType);
if (null == objectReaderSuperType) {
throw new IllegalStateException("Unable to fetch the reader for the super type \"" + superType
+ "\" whilst processing \"" + type.getName() + "\".");
}
break;
}
newConcreteType.setSuperType(objectReaderSuperType);
context.debug("extends " + objectReaderSuperType);
// add an annotation that marks the type being handled by this
// ObjectReader
newConcreteType.addMetaData(SerializationConstants.SERIALIZABLE_TYPE, type.getName());
// create a public no arguments constructor.
final NewConstructor constructor = newConcreteType.newConstructor();
constructor.setBody(EmptyCodeBlock.INSTANCE);
constructor.setVisibility(Visibility.PUBLIC);
return newConcreteType;
}