Skip to content

Commit

Permalink
Make FreeGen emits ctors in more consistent order
Browse files Browse the repository at this point in the history
- Sort ctors using the arguments as well as the name
- Convert `java.lang.Object` to `scala.AnyRef`
  • Loading branch information
guersam committed Aug 12, 2016
1 parent 934c43a commit c31ad0b
Show file tree
Hide file tree
Showing 13 changed files with 899 additions and 897 deletions.
6 changes: 4 additions & 2 deletions project/FreeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FreeGen(managed: List[Class[_]], log: Logger) {
val ClassLong = classOf[Long]
val ClassFloat = classOf[Float]
val ClassDouble = classOf[Double]
val ClassObject = classOf[Object]
val ClassVoid = Void.TYPE

val renames: Map[Class[_], String] =
Expand All @@ -40,7 +41,7 @@ class FreeGen(managed: List[Class[_]], log: Logger) {
case _ => Nil
}

def toScalaType(t: Type): String =
def toScalaType(t: Type): String =
t match {
case t: GenericArrayType => s"Array[${toScalaType(t.getGenericComponentType)}]"
case t: ParameterizedType => s"${toScalaType(t.getRawType)}${t.getActualTypeArguments.map(toScalaType).mkString("[", ", ", "]")}"
Expand All @@ -54,6 +55,7 @@ class FreeGen(managed: List[Class[_]], log: Logger) {
case ClassLong => "Long"
case ClassFloat => "Float"
case ClassDouble => "Double"
case ClassObject => "AnyRef"
case x: Class[_] if x.isArray => s"Array[${toScalaType(x.getComponentType)}]"
case x: Class[_] => renames.getOrElse(x, x.getSimpleName)
}
Expand Down Expand Up @@ -152,7 +154,7 @@ class FreeGen(managed: List[Class[_]], log: Logger) {
// Ctor values for all methods in of A plus superclasses, interfaces, etc.
def ctors[A](implicit ev: ClassTag[A]): List[Ctor] =
methods(ev.runtimeClass).groupBy(_.getName).toList.flatMap { case (n, ms) =>
ms.toList.zipWithIndex.map {
ms.toList.sortBy(_.getGenericParameterTypes.map(toScalaType).mkString(",")).zipWithIndex.map {
case (m, i) => Ctor(m, i)
}
}.sortBy(_.cname)
Expand Down
24 changes: 12 additions & 12 deletions yax/core/src/main/scala/doobie/free/blob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,21 @@ object blob {
case object Length extends BlobOp[Long] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.length())
}
case class Position(a: Blob, b: Long) extends BlobOp[Long] {
case class Position(a: Array[Byte], b: Long) extends BlobOp[Long] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.position(a, b))
}
case class Position1(a: Array[Byte], b: Long) extends BlobOp[Long] {
case class Position1(a: Blob, b: Long) extends BlobOp[Long] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.position(a, b))
}
case class SetBinaryStream(a: Long) extends BlobOp[OutputStream] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setBinaryStream(a))
}
case class SetBytes(a: Long, b: Array[Byte], c: Int, d: Int) extends BlobOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setBytes(a, b, c, d))
}
case class SetBytes1(a: Long, b: Array[Byte]) extends BlobOp[Int] {
case class SetBytes(a: Long, b: Array[Byte]) extends BlobOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setBytes(a, b))
}
case class SetBytes1(a: Long, b: Array[Byte], c: Int, d: Int) extends BlobOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setBytes(a, b, c, d))
}
case class Truncate(a: Long) extends BlobOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.truncate(a))
}
Expand Down Expand Up @@ -265,13 +265,13 @@ object blob {
/**
* @group Constructors (Primitives)
*/
def position(a: Blob, b: Long): BlobIO[Long] =
def position(a: Array[Byte], b: Long): BlobIO[Long] =
F.liftF(Position(a, b))

/**
* @group Constructors (Primitives)
*/
def position(a: Array[Byte], b: Long): BlobIO[Long] =
def position(a: Blob, b: Long): BlobIO[Long] =
F.liftF(Position1(a, b))

/**
Expand All @@ -283,14 +283,14 @@ object blob {
/**
* @group Constructors (Primitives)
*/
def setBytes(a: Long, b: Array[Byte], c: Int, d: Int): BlobIO[Int] =
F.liftF(SetBytes(a, b, c, d))
def setBytes(a: Long, b: Array[Byte]): BlobIO[Int] =
F.liftF(SetBytes(a, b))

/**
* @group Constructors (Primitives)
*/
def setBytes(a: Long, b: Array[Byte]): BlobIO[Int] =
F.liftF(SetBytes1(a, b))
def setBytes(a: Long, b: Array[Byte], c: Int, d: Int): BlobIO[Int] =
F.liftF(SetBytes1(a, b, c, d))

/**
* @group Constructors (Primitives)
Expand Down
760 changes: 380 additions & 380 deletions yax/core/src/main/scala/doobie/free/callablestatement.scala

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions yax/core/src/main/scala/doobie/free/clob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ object clob {
case class SetCharacterStream(a: Long) extends ClobOp[Writer] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setCharacterStream(a))
}
case class SetString(a: Long, b: String, c: Int, d: Int) extends ClobOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setString(a, b, c, d))
}
case class SetString1(a: Long, b: String) extends ClobOp[Int] {
case class SetString(a: Long, b: String) extends ClobOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setString(a, b))
}
case class SetString1(a: Long, b: String, c: Int, d: Int) extends ClobOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setString(a, b, c, d))
}
case class Truncate(a: Long) extends ClobOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.truncate(a))
}
Expand Down Expand Up @@ -304,14 +304,14 @@ object clob {
/**
* @group Constructors (Primitives)
*/
def setString(a: Long, b: String, c: Int, d: Int): ClobIO[Int] =
F.liftF(SetString(a, b, c, d))
def setString(a: Long, b: String): ClobIO[Int] =
F.liftF(SetString(a, b))

/**
* @group Constructors (Primitives)
*/
def setString(a: Long, b: String): ClobIO[Int] =
F.liftF(SetString1(a, b))
def setString(a: Long, b: String, c: Int, d: Int): ClobIO[Int] =
F.liftF(SetString1(a, b, c, d))

/**
* @group Constructors (Primitives)
Expand Down
96 changes: 48 additions & 48 deletions yax/core/src/main/scala/doobie/free/connection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ object connection {
case object Commit extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.commit())
}
case class CreateArrayOf(a: String, b: Array[Object]) extends ConnectionOp[SqlArray] {
case class CreateArrayOf(a: String, b: Array[AnyRef]) extends ConnectionOp[SqlArray] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.createArrayOf(a, b))
}
case object CreateBlob extends ConnectionOp[Blob] {
Expand All @@ -173,7 +173,7 @@ object connection {
case class CreateStatement2(a: Int, b: Int, c: Int) extends ConnectionOp[Statement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.createStatement(a, b, c))
}
case class CreateStruct(a: String, b: Array[Object]) extends ConnectionOp[Struct] {
case class CreateStruct(a: String, b: Array[AnyRef]) extends ConnectionOp[Struct] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.createStruct(a, b))
}
case object GetAutoCommit extends ConnectionOp[Boolean] {
Expand All @@ -182,12 +182,12 @@ object connection {
case object GetCatalog extends ConnectionOp[String] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.getCatalog())
}
case class GetClientInfo(a: String) extends ConnectionOp[String] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.getClientInfo(a))
}
case object GetClientInfo1 extends ConnectionOp[Properties] {
case object GetClientInfo extends ConnectionOp[Properties] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.getClientInfo())
}
case class GetClientInfo1(a: String) extends ConnectionOp[String] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.getClientInfo(a))
}
case object GetHoldability extends ConnectionOp[Int] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.getHoldability())
}
Expand Down Expand Up @@ -224,54 +224,54 @@ object connection {
case class NativeSQL(a: String) extends ConnectionOp[String] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.nativeSQL(a))
}
case class PrepareCall(a: String, b: Int, c: Int, d: Int) extends ConnectionOp[CallableStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareCall(a, b, c, d))
case class PrepareCall(a: String) extends ConnectionOp[CallableStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareCall(a))
}
case class PrepareCall1(a: String, b: Int, c: Int) extends ConnectionOp[CallableStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareCall(a, b, c))
}
case class PrepareCall2(a: String) extends ConnectionOp[CallableStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareCall(a))
case class PrepareCall2(a: String, b: Int, c: Int, d: Int) extends ConnectionOp[CallableStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareCall(a, b, c, d))
}
case class PrepareStatement(a: String, b: Int, c: Int) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a, b, c))
case class PrepareStatement(a: String) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a))
}
case class PrepareStatement1(a: String, b: Array[String]) extends ConnectionOp[PreparedStatement] {
case class PrepareStatement1(a: String, b: Array[Int]) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a, b))
}
case class PrepareStatement2(a: String, b: Array[Int]) extends ConnectionOp[PreparedStatement] {
case class PrepareStatement2(a: String, b: Array[String]) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a, b))
}
case class PrepareStatement3(a: String, b: Int) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a, b))
}
case class PrepareStatement4(a: String) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a))
case class PrepareStatement4(a: String, b: Int, c: Int) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a, b, c))
}
case class PrepareStatement5(a: String, b: Int, c: Int, d: Int) extends ConnectionOp[PreparedStatement] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.prepareStatement(a, b, c, d))
}
case class ReleaseSavepoint(a: Savepoint) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.releaseSavepoint(a))
}
case class Rollback(a: Savepoint) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.rollback(a))
}
case object Rollback1 extends ConnectionOp[Unit] {
case object Rollback extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.rollback())
}
case class Rollback1(a: Savepoint) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.rollback(a))
}
case class SetAutoCommit(a: Boolean) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setAutoCommit(a))
}
case class SetCatalog(a: String) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setCatalog(a))
}
case class SetClientInfo(a: String, b: String) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setClientInfo(a, b))
}
case class SetClientInfo1(a: Properties) extends ConnectionOp[Unit] {
case class SetClientInfo(a: Properties) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setClientInfo(a))
}
case class SetClientInfo1(a: String, b: String) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setClientInfo(a, b))
}
case class SetHoldability(a: Int) extends ConnectionOp[Unit] {
override def defaultTransK[M[_]: Monad: Catchable: Capture] = primitive(_.setHoldability(a))
}
Expand Down Expand Up @@ -397,7 +397,7 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def createArrayOf(a: String, b: Array[Object]): ConnectionIO[SqlArray] =
def createArrayOf(a: String, b: Array[AnyRef]): ConnectionIO[SqlArray] =
F.liftF(CreateArrayOf(a, b))

/**
Expand Down Expand Up @@ -445,7 +445,7 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def createStruct(a: String, b: Array[Object]): ConnectionIO[Struct] =
def createStruct(a: String, b: Array[AnyRef]): ConnectionIO[Struct] =
F.liftF(CreateStruct(a, b))

/**
Expand All @@ -463,14 +463,14 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def getClientInfo(a: String): ConnectionIO[String] =
F.liftF(GetClientInfo(a))
val getClientInfo: ConnectionIO[Properties] =
F.liftF(GetClientInfo)

/**
* @group Constructors (Primitives)
*/
val getClientInfo: ConnectionIO[Properties] =
F.liftF(GetClientInfo1)
def getClientInfo(a: String): ConnectionIO[String] =
F.liftF(GetClientInfo1(a))

/**
* @group Constructors (Primitives)
Expand Down Expand Up @@ -547,8 +547,8 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def prepareCall(a: String, b: Int, c: Int, d: Int): ConnectionIO[CallableStatement] =
F.liftF(PrepareCall(a, b, c, d))
def prepareCall(a: String): ConnectionIO[CallableStatement] =
F.liftF(PrepareCall(a))

/**
* @group Constructors (Primitives)
Expand All @@ -559,25 +559,25 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def prepareCall(a: String): ConnectionIO[CallableStatement] =
F.liftF(PrepareCall2(a))
def prepareCall(a: String, b: Int, c: Int, d: Int): ConnectionIO[CallableStatement] =
F.liftF(PrepareCall2(a, b, c, d))

/**
* @group Constructors (Primitives)
*/
def prepareStatement(a: String, b: Int, c: Int): ConnectionIO[PreparedStatement] =
F.liftF(PrepareStatement(a, b, c))
def prepareStatement(a: String): ConnectionIO[PreparedStatement] =
F.liftF(PrepareStatement(a))

/**
* @group Constructors (Primitives)
*/
def prepareStatement(a: String, b: Array[String]): ConnectionIO[PreparedStatement] =
def prepareStatement(a: String, b: Array[Int]): ConnectionIO[PreparedStatement] =
F.liftF(PrepareStatement1(a, b))

/**
* @group Constructors (Primitives)
*/
def prepareStatement(a: String, b: Array[Int]): ConnectionIO[PreparedStatement] =
def prepareStatement(a: String, b: Array[String]): ConnectionIO[PreparedStatement] =
F.liftF(PrepareStatement2(a, b))

/**
Expand All @@ -589,8 +589,8 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def prepareStatement(a: String): ConnectionIO[PreparedStatement] =
F.liftF(PrepareStatement4(a))
def prepareStatement(a: String, b: Int, c: Int): ConnectionIO[PreparedStatement] =
F.liftF(PrepareStatement4(a, b, c))

/**
* @group Constructors (Primitives)
Expand All @@ -607,14 +607,14 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def rollback(a: Savepoint): ConnectionIO[Unit] =
F.liftF(Rollback(a))
val rollback: ConnectionIO[Unit] =
F.liftF(Rollback)

/**
* @group Constructors (Primitives)
*/
val rollback: ConnectionIO[Unit] =
F.liftF(Rollback1)
def rollback(a: Savepoint): ConnectionIO[Unit] =
F.liftF(Rollback1(a))

/**
* @group Constructors (Primitives)
Expand All @@ -631,14 +631,14 @@ object connection {
/**
* @group Constructors (Primitives)
*/
def setClientInfo(a: String, b: String): ConnectionIO[Unit] =
F.liftF(SetClientInfo(a, b))
def setClientInfo(a: Properties): ConnectionIO[Unit] =
F.liftF(SetClientInfo(a))

/**
* @group Constructors (Primitives)
*/
def setClientInfo(a: Properties): ConnectionIO[Unit] =
F.liftF(SetClientInfo1(a))
def setClientInfo(a: String, b: String): ConnectionIO[Unit] =
F.liftF(SetClientInfo1(a, b))

/**
* @group Constructors (Primitives)
Expand Down
Loading

0 comments on commit c31ad0b

Please sign in to comment.