All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.auto.value.processor.gwtserializer.vm Maven / Gradle / Ivy

There is a newer version: 1.11.0
Show newest version
## Copyright 2014 Google LLC
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

## 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

## The following line will be replaced by the required imports during post-processing.
`import`

#if (!$generated.empty)
@${generated}("com.google.auto.value.processor.AutoValueProcessor")
#else
// Generated by com.google.auto.value.processor.AutoValueProcessor
#end
public final class $serializerClass$formalTypes
    extends `com.google.gwt.user.client.rpc.CustomFieldSerializer`<$subclass$actualTypes> {

  public static $formalTypes $subclass$actualTypes instantiate(
      `com.google.gwt.user.client.rpc.SerializationStreamReader` streamReader)
      throws `com.google.gwt.user.client.rpc.SerializationException` {
#foreach ($p in $props)
    #if ($p.castingUnchecked)
    @SuppressWarnings("unchecked")
    #end
    $p.type $p = ${p.gwtCast}streamReader.read${p.gwtType}();
#end
#if ($useBuilder)

    ${subclass}.Builder${actualTypes} builder$ = new ${subclass}.Builder${actualTypes}();
  #foreach ($p in $props)

    #if ($builderSetters[$p.name].empty)
      #set ($propertyBuilder = $builderPropertyBuilders[$p.name])

    builder$.${propertyBuilder.propertyBuilderMethod}.${propertyBuilder.copyAll}($p);

    #else

    builder$.${builderSetters[$p.name].iterator().next().name}($p);
    #end
  #end

    return (${subclass}${actualTypes}) builder$.build();
#else

    return new ${subclass}$actualTypes(
        #foreach ($p in $props) $p #if ($foreach.hasNext) , #end #end);

#end
  }

  public static $formalTypes void serialize(
      `com.google.gwt.user.client.rpc.SerializationStreamWriter` streamWriter,
      $subclass$actualTypes instance) throws `com.google.gwt.user.client.rpc.SerializationException` {
#foreach ($p in $props)
    streamWriter.write${p.gwtType}(instance.${p.getter}());
#end
  }

  public static $formalTypes void deserialize(
      @SuppressWarnings("unused") `com.google.gwt.user.client.rpc.SerializationStreamReader` streamReader,
      @SuppressWarnings("unused") $subclass$actualTypes instance) {
    // instantiate already did all the work.
  }

  // This dummy field is a hash of the fields in ${subclass}. It 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;

  @`java.lang.Override`
  public void deserializeInstance(
      `com.google.gwt.user.client.rpc.SerializationStreamReader` streamReader,
      $subclass$actualTypes instance) {
    deserialize(streamReader, instance);
  }

  @`java.lang.Override`
  public boolean hasCustomInstantiateInstance() {
    return true;
  }

  @`java.lang.Override`
  public $subclass$actualTypes instantiateInstance(
      `com.google.gwt.user.client.rpc.SerializationStreamReader` streamReader)
      throws `com.google.gwt.user.client.rpc.SerializationException` {
    return instantiate(streamReader);
  }

  @`java.lang.Override`
  public void serializeInstance(
      `com.google.gwt.user.client.rpc.SerializationStreamWriter` streamWriter,
      $subclass$actualTypes instance)
      throws `com.google.gwt.user.client.rpc.SerializationException` {
    serialize(streamWriter, instance);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy