scala.class_companion_rfields.ssp Maven / Gradle / Ivy
The newest version!
<%
// Copyright 2013 Foursquare Labs Inc. All Rights Reserved.
import com.foursquare.spindle.codegen.runtime.StructLike
%>
<%@ val cls: StructLike %>
// Spindle Descriptors.
<%--
// These look very much like the Thrift Descriptors, but they include type parameters
// which will be useful for Rogue. Maybe there's a way to merge the two?
--%>
#for (field <- cls.fields)
val ${field.escapedName} =
#if (field.isForeignKey)
new com.foursquare.spindle.ForeignKeyFieldDescriptor[${field.renderType.text}, ${cls.name}, ${cls.name}Meta](
#elseif (field.renderType.isInstanceOf[com.foursquare.spindle.codegen.runtime.BitfieldStructRenderType])
<% val structName = field.renderType.asInstanceOf[com.foursquare.spindle.codegen.runtime.BitfieldStructRenderType].className %>
new com.foursquare.spindle.BitfieldFieldDescriptor[${field.renderType.text}, ${cls.name}, ${cls.name}Meta, ${structName}, ${structName}Meta](
#elseif (field.renderType.isInstanceOf[com.foursquare.spindle.codegen.runtime.ExceptionRenderType])
new com.foursquare.spindle.ExceptionFieldDescriptor[${cls.name}, ${cls.name}Meta, ${field.renderType.text}.Struct, ${field.renderType.text}.StructMeta, ${field.renderType.text}](
#elseif (field.renderType.isInstanceOf[com.foursquare.spindle.codegen.runtime.StructRenderType])
new com.foursquare.spindle.StructFieldDescriptor[${cls.name}, ${cls.name}Meta, ${field.renderType.text}, ${field.renderType.text}Meta](
#else
new com.foursquare.spindle.OptionalFieldDescriptor[${field.renderType.text}, ${cls.name}, ${cls.name}Meta](
#end
name = "${field.wireName}",
longName = "${field.name}",
id = ${field.identifier},
annotations = Map(${field.annotations.toSeq.map(at => "\"%s\" -> \"%s\"".format(at._1, at._2)).mkString(", ")}),
owner = this,
getter = _.${field.name}Option,
setterRaw = (r: com.foursquare.spindle.MutableRecord[${cls.name}], v: ${field.renderType.text}) => { r.asInstanceOf[Raw${cls.name}].${field.escapedName}_=(v) },
unsetterRaw = (r: com.foursquare.spindle.MutableRecord[${cls.name}]) => { r.asInstanceOf[Raw${cls.name}].${field.name}Unset() },
#if (field.isForeignKey)
objSetter = (r: ${cls.name}, obj: com.foursquare.spindle.SemitypedHasPrimaryKey[${field.renderType.text}]) => { r.${field.name}SetObj(obj) },
objGetter = (r: ${cls.name}, m: com.foursquare.spindle.UntypedMetaRecord) => { r.${field.name}UntypedFk(m) },
unsafeObjGetter = (r: Any) => { r.asInstanceOf[${cls.name}].${field.name}GetObj },
alternateObjSetter = (r: ${cls.name}, obj: AnyRef) => { r.${field.name}SetAlternateObj(obj) },
alternateObjGetter = (r: ${cls.name}) => { r.${field.name}AlternateFk },
#elseif (field.renderType.isInstanceOf[com.foursquare.spindle.codegen.runtime.BitfieldStructRenderType])
<% val structName = field.renderType.asInstanceOf[com.foursquare.spindle.codegen.runtime.BitfieldStructRenderType].className %>
structMeta = ${structName},
#elseif (field.renderType.isInstanceOf[com.foursquare.spindle.codegen.runtime.ExceptionRenderType])
structMeta = ${field.renderType.text}.Struct,
#elseif (field.renderType.isInstanceOf[com.foursquare.spindle.codegen.runtime.StructRenderType])
structMeta = ${field.renderType.text},
#end
manifest = manifest[${field.renderType.text}]
)
#end
override def untypedFields: Seq[com.foursquare.spindle.UntypedFieldDescriptor] = fields
override val fields: Seq[com.foursquare.spindle.FieldDescriptor[_, ${cls.name}, ${cls.name}Meta]] =
Vector[com.foursquare.spindle.FieldDescriptor[_, ${cls.name}, ${cls.name}Meta]](
${cls.fields.map(_.escapedName).mkString(",\n ")}
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy