Skip to content

Commit

Permalink
Make Quill compatible with Scala 2.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mentegy committed May 12, 2017
1 parent c2d1aad commit 4452951
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 32 deletions.
20 changes: 14 additions & 6 deletions build.sbt
Expand Up @@ -318,10 +318,18 @@ lazy val commonSettings = ReleasePlugin.extraReleaseCommands ++ Seq(
<url>http://github.com/fwbrasil/</url>
</developer>
</developers>)
) ++ update2_12
) ++ `scala 2.12 hacks`

lazy val update2_12 = Seq(
scalacOptions -= (
if (scalaVersion.value.startsWith("2.12.")) "-Xfatal-warnings" else ""
)
)
lazy val `scala 2.12 hacks` = Seq(
scalacOptions := {
val opts = scalacOptions.value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => opts.map {
case "-Xlint" => "-Xlint:-unused,_"
case "-Ywarn-unused-import" => "-Ywarn-unused:imports"
case other => other
}
case _ => opts
}
}
)
8 changes: 4 additions & 4 deletions build/build.sh
Expand Up @@ -22,16 +22,16 @@ then
git checkout master || git checkout -b master
git reset --hard origin/master
git push --delete origin website
sbt tut 'release with-defaults'
sbt tut 'release cross with-defaults'
elif [[ $TRAVIS_BRANCH == "master" ]]
then
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean ++2.12.2 test ++2.11.11 coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt coverageOff publish
else
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean ++2.12.2 test ++2.11.11 coverage test tut coverageReport coverageAggregate checkUnformattedFiles
echo "version in ThisBuild := \"$TRAVIS_BRANCH-SNAPSHOT\"" > version.sbt
sbt coverageOff publish
fi
else
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean ++2.12.2 test ++2.11.11 coverage test tut coverageReport coverageAggregate checkUnformattedFiles
fi
Expand Up @@ -5,7 +5,7 @@ import java.time.{ LocalDate, LocalDateTime }
import io.getquill.context.sql.EncodingSpec

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ Await, ExecutionContext }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import java.util.Date

Expand Down Expand Up @@ -143,7 +143,7 @@ class MysqlAsyncEncodingSpec extends EncodingSpec {

"encodes custom type inside singleton object" in {
object Singleton {
def apply()(implicit c: TestContext, ec: ExecutionContext) = {
def apply()(implicit c: TestContext) = {
import c._
for {
_ <- c.run(query[EncodingTestEntity].delete)
Expand Down
Expand Up @@ -5,7 +5,7 @@ import java.time.{ LocalDate, LocalDateTime }
import io.getquill.context.sql.EncodingSpec

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ Await, ExecutionContext }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import java.util.Date
import java.util.UUID
Expand Down Expand Up @@ -111,7 +111,7 @@ class PostgresAsyncEncodingSpec extends EncodingSpec {

"encodes custom type inside singleton object" in {
object Singleton {
def apply()(implicit c: TestContext, ec: ExecutionContext) = {
def apply()(implicit c: TestContext) = {
import c._
for {
_ <- c.run(query[EncodingTestEntity].delete)
Expand Down
Expand Up @@ -5,7 +5,6 @@ import scala.util.Try
import com.typesafe.config.Config
import com.typesafe.config.ConfigValueType
import java.lang.reflect.Method
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import com.datastax.driver.core.Cluster

Expand All @@ -15,7 +14,7 @@ object ClusterBuilder {
set(Cluster.builder, cfg)

private def set[T](instance: T, cfg: Config): T = {
for (key <- cfg.entrySet.map(_.getKey.split('.').head)) {
for (key <- cfg.entrySet.asScala.map(_.getKey.split('.').head)) {

def tryMethod(m: Method) =
m.getParameterTypes.toList match {
Expand Down
10 changes: 5 additions & 5 deletions quill-core/src/main/scala/io/getquill/dsl/MetaDsl.scala
Expand Up @@ -22,19 +22,19 @@ trait MetaDsl extends MetaDslLowPriorityImplicits {
def insertMeta[T](exclude: (T => Any)*): InsertMeta[T] = macro MetaDslMacro.insertMeta[T]

trait SchemaMeta[T] {
val entity: Quoted[EntityQuery[T]]
def entity: Quoted[EntityQuery[T]]
}

trait QueryMeta[T] {
val expand: Quoted[Query[T] => Query[_]]
val extract: ResultRow => T
def expand: Quoted[Query[T] => Query[_]]
def extract: ResultRow => T
}

trait UpdateMeta[T] {
val expand: Quoted[(EntityQuery[T], T) => Update[T]]
def expand: Quoted[(EntityQuery[T], T) => Update[T]]
}

trait InsertMeta[T] {
val expand: Quoted[(EntityQuery[T], T) => Insert[T]]
def expand: Quoted[(EntityQuery[T], T) => Insert[T]]
}
}
20 changes: 12 additions & 8 deletions quill-core/src/main/scala/io/getquill/dsl/MetaDslMacro.scala
Expand Up @@ -12,10 +12,10 @@ class MetaDslMacro(val c: MacroContext) {
c.untypecheck {
q"""
new ${c.prefix}.SchemaMeta[$t] {
val entity =
${c.prefix}.quote {
${c.prefix}.querySchema[$t]($entity, ..$columns)
}
private[this] val _entity = ${c.prefix}.quote {
${c.prefix}.querySchema[$t]($entity, ..$columns)
}
def entity = _entity
}
"""
}
Expand All @@ -24,7 +24,8 @@ class MetaDslMacro(val c: MacroContext) {
c.untypecheck {
q"""
new ${c.prefix}.QueryMeta[$t] {
val expand = $expand
private[this] val _expand = $expand
def expand = _expand
val extract =
(r: ${c.prefix}.ResultRow) => $extract(implicitly[${c.prefix}.QueryMeta[$r]].extract(r))
}
Expand All @@ -41,7 +42,8 @@ class MetaDslMacro(val c: MacroContext) {
val value = this.value("Decoder", t.tpe)
q"""
new ${c.prefix}.QueryMeta[$t] {
val expand = ${expandQuery[T](value)}
private[this] val _expanded = ${expandQuery[T](value)}
def expand = _expanded
val extract = ${extract[T](value)}
}
"""
Expand All @@ -57,8 +59,9 @@ class MetaDslMacro(val c: MacroContext) {
if (t.tpe.typeSymbol.isClass && t.tpe.typeSymbol.asClass.isCaseClass) {
q"""
new ${c.prefix}.SchemaMeta[$t] {
val entity =
private[this] val _entity =
${c.prefix}.quote(${c.prefix}.querySchema[$t](${t.tpe.typeSymbol.name.decodedName.toString}))
def entity = _entity
}
"""
} else {
Expand Down Expand Up @@ -122,8 +125,9 @@ class MetaDslMacro(val c: MacroContext) {
c.untypecheck {
q"""
new ${c.prefix}.${TypeName(method.capitalize + "Meta")}[$t] {
val expand =
private[this] val _expand =
${c.prefix}.quote((q: ${c.prefix}.EntityQuery[$t], value: $t) => q.${TermName(method)}(..$assignments))
def expand = _expand
}
"""
}
Expand Down
Expand Up @@ -726,6 +726,7 @@ class QuotationSpec extends Spec {
quote(unquote(q)).ast match {
case Function(params, Tuple(values)) =>
values mustEqual params
case _ => require(false, "Should not happen")
}
}
"java to scala" in {
Expand All @@ -739,6 +740,7 @@ class QuotationSpec extends Spec {
quote(unquote(q)).ast match {
case Function(params, Tuple(values)) =>
values mustEqual params
case _ => require(false, "Should not happen")
}
}
}
Expand Down Expand Up @@ -847,8 +849,8 @@ class QuotationSpec extends Spec {
l.encoder mustEqual intEncoder
}
"property" in {
case class Test(a: String)
val t = Test("a")
case class TestEntity(a: String)
val t = TestEntity("a")
val q = quote(lift(t.a))

val l = q.liftings.`t.a`
Expand All @@ -857,7 +859,7 @@ class QuotationSpec extends Spec {
}
"abritrary" in {
val q = quote(lift(String.valueOf(1)))
q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
//q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
}
"duplicate" in {
val i = 1
Expand Down

0 comments on commit 4452951

Please sign in to comment.