com.google.auto.value.processor.gwtserializer.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of auto-value Show documentation
Show all versions of auto-value Show documentation
Immutable value-type code generation for Java 1.6+.
## Template for each generated AutoValue_Foo_CustomFieldSerializer class.
## This template uses the Apache Velocity Template Language (VTL).
## The variables ($pkg, $props, and so on) are defined by the fields of
## GwtSerialization.GwtTemplateVars.
##
## Comments, like this one, begin with ##. The comment text extends up to and including the newline
## character at the end of the line. So comments also serve to join a line to the next one.
## Velocity deletes a newline after a directive (#if, #foreach, #end etc) so ## is not needed there.
## That does mean that we sometimes need an extra blank line after such a directive.
##
## A post-processing step will remove unwanted spaces and blank lines, but will not join two lines.
## TODO(emcmanus): perform the post-processing.
#if (!$pkg.empty)
package $pkg;
#end
#foreach ($i in $imports)
import $i;
#end
import com.google.gwt.user.client.rpc.CustomFieldSerializer;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
@${generated}("com.google.auto.value.processor.AutoValueProcessor")
public final class $serializerClass$formalTypes extends CustomFieldSerializer<$subclass$actualTypes> {
public static $formalTypes $subclass$actualTypes instantiate(
SerializationStreamReader streamReader) throws SerializationException {
#foreach ($p in $props)
#if ($p.castingUnchecked)
@SuppressWarnings("unchecked")
#end
$p.type $p = ${p.gwtCast}streamReader.read${p.gwtType}();
#end
#if ($useBuilder)
return (${subclass}${actualTypes}) new ${subclass}.Builder${actualTypes}()
#foreach ($p in $props)
.${builderSetters[$p.name].iterator().next().name}($p)
#end
.build();
#else
return new ${subclass}$actualTypes(
#foreach ($p in $props) $p #if ($foreach.hasNext) , #end #end);
#end
}
public static $formalTypes void serialize(
SerializationStreamWriter streamWriter,
$subclass$actualTypes instance) throws SerializationException {
#foreach ($p in $props)
streamWriter.write${p.gwtType}(instance.${p.getter}());
#end
}
public static $formalTypes void deserialize(
@SuppressWarnings("unused") SerializationStreamReader streamReader,
@SuppressWarnings("unused") $subclass$actualTypes instance) {
// instantiate already did all the work.
}
// This dummy field is a hash of the fields in $subclass that will change if they do, including
// if their order changes. This is because GWT identity for a class that has a serializer is
// based on the fields of the serializer rather than the class itself.
@SuppressWarnings("unused")
private int dummy_$classHashString;
@Override
public void deserializeInstance(
SerializationStreamReader streamReader,
$subclass$actualTypes instance) {
deserialize(streamReader, instance);
}
@Override
public boolean hasCustomInstantiateInstance() {
return true;
}
@Override
public $subclass$actualTypes instantiateInstance(
SerializationStreamReader streamReader) throws SerializationException {
return instantiate(streamReader);
}
@Override
public void serializeInstance(
SerializationStreamWriter streamWriter,
$subclass$actualTypes instance) throws SerializationException {
serialize(streamWriter, instance);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy