*/
protected void overrideReadFieldsMethods(final NewConcreteType deserializer, final Type type) {
Checker.notNull("parameter:deserializer", deserializer);
Checker.notNull("parameter:type", type);
final GeneratorContext context = this.getGeneratorContext();
context.branch();
context.debug("Overriding " + Constants.READ_FIELDS_METHOD + "() and creating list setters for type \"" + deserializer.getName()
+ "\".");
final NewMethod readFields = deserializer.newMethod();
readFields.setAbstract(false);
readFields.setFinal(false);
readFields.setName(Constants.READ_FIELDS_METHOD);
readFields.setNative(false);
readFields.setReturnType(context.getVoid());
readFields.setStatic(false);
readFields.setVisibility(Visibility.PROTECTED);
final NewMethodParameter readFieldsJsonObjectParameter = readFields.newParameter();
readFieldsJsonObjectParameter.setFinal(true);
readFieldsJsonObjectParameter.setName("jsonObject");
final Type jsonObjectType = this.getJsonObject();
readFieldsJsonObjectParameter.setType(jsonObjectType);
final NewMethodParameter readFieldsInstanceParameter = readFields.newParameter();
readFieldsInstanceParameter.setFinal(true);
readFieldsInstanceParameter.setName("instance");
readFieldsInstanceParameter.setType(type);
final CodeBlockList body = new CodeBlockList();
readFields.setBody(body);
final Type stringType = context.getString();
final Iterator fields = type.getFields().iterator();
while (fields.hasNext()) {
final Field field = (Field) fields.next();
if (field.isStatic() || field.isTransient()) {
continue;
}
if (field.isFinal()) {
throwFinalFieldsCannotBeDeserialized(field);
}
final SetFieldTemplatedFile writeMethodBody = new SetFieldTemplatedFile();
writeMethodBody.setField(field);
// create the setter method itself.
final NewMethod setter = deserializer.newMethod();
setter.setAbstract(false);
setter.setFinal(false);
setter.setName(GeneratorHelper.buildSetterName(field.getName()));
setter.setNative(true);
setter.setReturnType(context.getVoid());
setter.setStatic(false);
setter.setVisibility(Visibility.PRIVATE);
setter.setBody(writeMethodBody);
// add its instance parameter
final NewMethodParameter setterInstanceParameter = setter.newParameter();
setterInstanceParameter.setFinal(true);
setterInstanceParameter.setName(Constants.SET_FIELD_INSTANCE_PARAMETER);
setterInstanceParameter.setType(type);
// add the value parameter
final NewMethodParameter setterValueParameter = setter.newParameter();
setterValueParameter.setFinal(true);
setterValueParameter.setName(Constants.SET_FIELD_VALUE_PARAMETER);
setterValueParameter.setType(field.getType());
final Type fieldType = field.getType();
if (fieldType.equals(context.getLong())) {
setter.addMetaData("com.google.gwt.core.client.UnsafeNativeLong", "");
}
context.debug("Created setter for field " + field + " setter method " + setter);
// simple type ?
if (fieldType.isPrimitive() || fieldType.equals(stringType)) {
final SetSimpleTemplatedFile template = new SetSimpleTemplatedFile();
template.setFieldSetter(setter);
template.setJavascriptPropertyName(this.getJavascriptPropertyName(field));
template.setSerializer(this.getSerializer(field));
body.add(template);
continue;
}
final SetComplexTemplatedFile template = new SetComplexTemplatedFile();
template.setFieldSetter(setter);
template.setJavascriptPropertyName(this.getJavascriptPropertyName(field));
template.setFieldType(fieldType);
final Type serializer = this.getSerializer(field);
template.setSerializer(serializer);
final String readMethodName = this.selectReadMethod(fieldType);
final Method readMethod = serializer.getMostDerivedMethod(readMethodName, Collections.nCopies(1, this.getJsonValue()));
template.setReadMethod(readMethod);
body.add(template);
}
context.unbranch();
}