scala.typedefs.ssp Maven / Gradle / Ivy
The newest version!
<%
// Copyright 2013 Foursquare Labs Inc. All Rights Reserved.
import com.foursquare.spindle.codegen.runtime.{PrimitiveRenderType, ProgramSource, ScalaTypedef}
%>
<%@ val typedefs: Seq[ScalaTypedef] %>
<%@ val baseName: String %>
object ${baseName}Typedefs {
#for (typedef <- typedefs)
#if (typedef.newType)
<%-- Dummy trait used to tag the new subtype --%>
trait __${typedef.typeAlias}Tag
#if (typedef.renderType.hasOrdering)
object __${typedef.typeAlias}Tag {
implicit val ordering: scala.math.Ordering[${typedef.typeAlias}] =
implicitly[scala.math.Ordering[${typedef.renderType.boxedText}]].asInstanceOf[scala.math.Ordering[${typedef.typeAlias}]]
}
#end
type ${typedef.typeAlias} = com.foursquare.spindle.Id[${typedef.renderType.boxedText}, __${typedef.typeAlias}Tag]
def ${typedef.typeAlias}(x: ${typedef.renderType.boxedText}): ${typedef.typeAlias} = x.asInstanceOf[${typedef.typeAlias}]
#else
type ${typedef.typeAlias} = ${typedef.renderType.text} // Underlying type: ${typedef.renderType.underlying.text}
#end
#end
}
trait ${baseName}TypedefImplicits {
#for (typedef <- typedefs)
#if (typedef.newType)
#if (typedef.renderType.boxedText == "org.bson.types.ObjectId")
implicit def stringTo${typedef.typeAlias}(x: String): ${baseName}Typedefs.${typedef.typeAlias} =
${baseName}Typedefs.${typedef.typeAlias}(new org.bson.types.ObjectId(x))
#elseif (typedef.renderType.boxedText == "String")
implicit def stringTo${typedef.typeAlias}(x: String): ${baseName}Typedefs.${typedef.typeAlias} =
${baseName}Typedefs.${typedef.typeAlias}(x)
#elseif (typedef.renderType.boxedText == "java.lang.Long")
implicit def intTo${typedef.typeAlias}(x: Int): ${baseName}Typedefs.${typedef.typeAlias} =
${baseName}Typedefs.${typedef.typeAlias}(new java.lang.Long(x))
implicit def longTo${typedef.typeAlias}(x: Long): ${baseName}Typedefs.${typedef.typeAlias} =
${baseName}Typedefs.${typedef.typeAlias}(long2Long(x))
#end
#end
#end
}
object ${baseName}TypedefImplicits extends ${baseName}TypedefImplicits
© 2015 - 2025 Weber Informatics LLC | Privacy Policy