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

nl.topicus.jdbc.shaded.com.google.auto.value.processor.autovalue.vm Maven / Gradle / Ivy

## Template for each generated AutoValue_Foo class.
## This template uses the Apache Velocity Template Language (VTL).
## The variables ($pkg, $props, and so on) are defined by the fields of AutoValueTemplateVars.
##
## 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.

#if (!$pkg.empty)
package $pkg;
#end

#foreach ($i in $imports)
import $i;
#end

${gwtCompatibleAnnotation}
#if ($generated != "")
@${generated}("com.google.auto.value.processor.AutoValueProcessor")
#end
#if ($isFinal) final #else abstract #end class $subclass$formalTypes extends $origClass$actualTypes {

## Fields

#foreach ($p in $props)
  private final $p.type $p;
#end

## Constructor

#if ($isFinal && $builderTypeName != "")
  private ##
#end
  $subclass(
#foreach ($p in $props)

      ${p.nullableAnnotation}$p.type $p #if ($foreach.hasNext) , #end
#end ) {
#foreach ($p in $props)
  #if (!$p.kind.primitive && !$p.nullable && !$builderPropertyBuilders[$p.name])

    if ($p == null) {
      throw new NullPointerException("Null $p.name");
    }

  #end

    this.$p = $p;
#end
  }

## Property getters

#foreach ($p in $props)

  #foreach ($a in ${p.annotations})

  ${a}##
  #end

  @Override
  ${p.access}${p.type} ${p.getter}() {
    return $p;
  }

#end

#if ($toString)

  @Override
  public String toString() {
    return "$simpleClassName{"

  #foreach ($p in $props)

        + "$p.name=" ##
        + #if ($p.kind == "ARRAY") ${arrays}.toString($p) #else $p #end
        #if ($foreach.hasNext) + ", " #end

  #end

        + "}";
  }

#end

#if ($equals)
  #macro (equalsThatExpression $p)
    #if ($p.kind == "FLOAT")
      Float.floatToIntBits(this.$p) == Float.floatToIntBits(that.${p.getter}()) ##
    #elseif ($p.kind == "DOUBLE")
      Double.doubleToLongBits(this.$p) == Double.doubleToLongBits(that.${p.getter}()) ##
    #elseif ($p.kind.primitive)
      this.$p == that.${p.getter}() ##
    #elseif ($p.kind == "ARRAY")
      ${arrays}.equals(this.$p, ##
          (that instanceof $subclass) ? (($subclass) that).$p : that.${p.getter}()) ##
    #else
      #if ($p.nullable) (this.$p == null) ? (that.${p.getter}() == null) : #end ##
          this.${p}.equals(that.${p.getter}()) ##
    #end
  #end

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (o instanceof $origClass) {

  #if ($props.empty)

      return true;

  #else

      $origClass$wildcardTypes that = ($origClass$wildcardTypes) o;
      return ##
           #foreach ($p in $props)
           (#equalsThatExpression ($p))##
             #if ($foreach.hasNext)

           && ##
             #end
           #end
           ;
  #end

    }
    return false;
  }

#end

#if ($hashCode)
  #macro (hashCodeExpression $p)
    #if ($p.kind == "BYTE" || $p.kind == "SHORT" || $p.kind == "CHAR" || $p.kind == "INT")
      this.$p ##
    #elseif ($p.kind == "LONG")
      (this.$p >>> 32) ^ this.$p ##
    #elseif ($p.kind == "FLOAT")
      Float.floatToIntBits(this.$p) ##
    #elseif ($p.kind == "DOUBLE")
      (Double.doubleToLongBits(this.$p) >>> 32) ^ Double.doubleToLongBits(this.$p) ##
    #elseif ($p.kind == "BOOLEAN")
      this.$p ? 1231 : 1237 ##
    #elseif ($p.kind == "ARRAY")
      ${arrays}.hashCode(this.$p) ##
    #else
      #if ($p.nullable) ($p == null) ? 0 : #end this.${p}.hashCode() ##
    #end
  #end

  @Override
  public int hashCode() {
    int h = 1;

  #foreach ($p in $props)

    h *= 1000003;
    h ^= #hashCodeExpression($p);

  #end

    return h;
  }
#end

#if (!$serialVersionUID.empty)
  private static final long serialVersionUID = $serialVersionUID;
#end

#if ($builderTypeName != "")

  #foreach ($m in $toBuilderMethods)

  @Override
  public ${builderTypeName}${builderActualTypes} ${m}() {
    return new Builder${builderActualTypes}(this);
  }

  #end

  static final class Builder${builderFormalTypes} ##
  #if ($builderIsInterface) implements #else extends #end
      ${builderTypeName}${builderActualTypes} {

  #foreach ($p in $props)

    #if ($p.kind.primitive)

    private $types.boxedClass($p.typeMirror).simpleName $p;

    #else

      #if ($builderPropertyBuilders[$p.name])
      ## If you have ImmutableList.Builder stringsBuilder() then we define two fields:
      ## private ImmutableList.Builder stringsBuilder$;
      ## private ImmutableList strings;

    private ${builderPropertyBuilders[$p.name].builderType} ##
        ${builderPropertyBuilders[$p.name].name};

      #end

    private $p.type $p;

    #end
  #end

    Builder() {

  #foreach ($p in $props)
    #if ($builderPropertyBuilders[$p.name])

      this.$p = ${builderPropertyBuilders[$p.name].empty};

    #end
  #end

    }

    Builder(${origClass}${actualTypes} source) {

  #foreach ($p in $props)

      this.$p = source.${p.getter}();

  #end

    }

  #foreach ($p in $props)

    ## The following is either null or an instance of BuilderSpec.PropertyBuilder
    #set ($propertyBuilder = $builderPropertyBuilders[$p.name])

    ## Setter and/or property builder

    #foreach ($setter in $builderSetters[$p.name])

    @Override
    public ${builderTypeName}${builderActualTypes} ##
        ${setter.name}(${p.nullableAnnotation}$setter.parameterType $p) {

      #if ($propertyBuilder)

      if (${propertyBuilder.name} != null) {
        throw new IllegalStateException("Cannot set $p after calling ${p.name}Builder()");
      }

      #end

      this.$p = ${setter.copy($p)};
      return this;
    }

    #end

    #if ($propertyBuilder)

    @Override
    public $propertyBuilder.builderType ${p.name}Builder() {
      if (${propertyBuilder.name} == null) {
        ${propertyBuilder.name} = ${propertyBuilder.initializer};
        ${propertyBuilder.name}.${propertyBuilder.copyAll}($p);
        $p = null;
      }
      return $propertyBuilder.name;
    }

    #end

    ## Getter

    #if ($propertiesWithBuilderGetters.contains($p.name))

    @Override
    ${p.nullableAnnotation}public $p.type ${p.getter}() {
      #if ($builderRequiredProperties.contains($p))

      if ($p == null) {
        throw new IllegalStateException("Property \"$p.name\" has not been set");
      }

      #end

      #if ($builderPropertyBuilders[$p.name])

      if (${propertyBuilder.name} != null) {
        return ${propertyBuilder.name}.build();
      }

      #end

      return $p;

    }

    #end
  #end

    @Override
    public ${origClass}${actualTypes} ${buildMethodName}() {

  #foreach ($p in $props)
    #if ($builderPropertyBuilders[$p.name])

      if (${builderPropertyBuilders[$p.name].name} != null) {
        $p = ${builderPropertyBuilders[$p.name].name}.build();
      }

    #end
  #end


  #if (!$builderRequiredProperties.empty)

      String missing = "";

    #foreach ($p in $builderRequiredProperties)

      if ($p == null) {
        missing += " $p.name";
      }

    #end

      if (!missing.isEmpty()) {
        throw new IllegalStateException("Missing required properties:" + missing);
      }
  #end

      return new ${finalSubclass}${actualTypes}(
  #foreach ($p in $props)

          this.$p #if ($foreach.hasNext) , #end
  #end );
    }
  }
#end

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy