Skip to content

Commit

Permalink
port changes to scala 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jodersky committed Nov 2, 2024
1 parent d7924cc commit 1f7549c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
13 changes: 6 additions & 7 deletions cask/src-2/cask/router/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Macros[C <: blackbox.Context](val c: C) {
def extractMethod(method: MethodSymbol,
curCls: c.universe.Type,
convertToResultType: c.Tree,
ctx: c.Tree,
argReaders: Seq[c.Tree],
annotDeserializeTypes: Seq[c.Tree]): c.universe.Tree = {
val baseArgSym = TermName(c.freshName())
Expand Down Expand Up @@ -108,18 +107,18 @@ class Macros[C <: blackbox.Context](val c: C) {

val argSig =
q"""
cask.router.ArgSig[$annotDeserializeType, $curCls, $docUnwrappedType, $ctx](
cask.router.ArgSig[$annotDeserializeType, $curCls, $docUnwrappedType, Any](
${arg.name.toString},
${docUnwrappedType.toString},
$docTree,
$defaultOpt
)($argReader[$docUnwrappedType])
)($argReader[$docUnwrappedType].asInstanceOf[cask.router.ArgReader[$annotDeserializeType, $docUnwrappedType, Any]])
"""

val reader = q"""
cask.router.Runtime.makeReadCall(
$argValuesSymbol($argListIndex),
$ctxSymbol,
$ctxSymbol($argListIndex),
$default,
$argSigsSymbol($argListIndex)($i)
)
Expand Down Expand Up @@ -151,7 +150,7 @@ class Macros[C <: blackbox.Context](val c: C) {
for(argNameCast <- argNameCasts) methodCall = q"$methodCall(..$argNameCast)"

val res = q"""
cask.router.EntryPoint[$curCls, $ctx](
cask.router.EntryPoint[$curCls, Any](
${method.name.toString},
${argSigs.toList},
${methodDoc match{
Expand All @@ -160,9 +159,9 @@ class Macros[C <: blackbox.Context](val c: C) {
}},
(
$baseArgSym: $curCls,
$ctxSymbol: $ctx,
$ctxSymbol: Seq[_],
$argValuesSymbol: Seq[Map[String, Any]],
$argSigsSymbol: scala.Seq[scala.Seq[cask.router.ArgSig[Any, _, _, $ctx]]]
$argSigsSymbol: scala.Seq[scala.Seq[cask.router.ArgSig[Any, _, _, Any]]]
) =>
cask.router.Runtime.validate(Seq(..${readArgs.flatten.toList})).map{
case Seq(..${argNames.flatten.toList}) => $convertToResultType($methodCall)
Expand Down
1 change: 0 additions & 1 deletion cask/src-2/cask/router/RoutesEndpointMetadata.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ object RoutesEndpointsMetadata{
m.asInstanceOf[MethodSymbol],
weakTypeOf[T],
q"${annotObjectSyms.last}.convertToResultType",
tq"cask.Request",
annotObjectSyms.reverse.map(annotObjectSym => q"$annotObjectSym.getParamParser"),
annotObjectSyms.reverse.map(annotObjectSym => tq"$annotObjectSym.InputTypeAlias")
)
Expand Down
2 changes: 1 addition & 1 deletion cask/src-3/cask/router/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Macros {
} else {
hasErrors = true
report.error(
s"required: cask.router.Decorator[_, ${prevOuter.show}, _]",
s"required: cask.router.Decorator[_, ${prevOuter.show}, _, _]",
d
)
}
Expand Down
2 changes: 1 addition & 1 deletion cask/test/src/test/cask/FailureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object FailureTests extends TestSuite {
initialize()
}
""").msg
assert(m.contains("required: cask.router.Decorator[_, cask.endpoints.WebsocketResult, _]"))
assert(m.contains("required: cask.router.Decorator[_, cask.endpoints.WebsocketResult, _, _]"))
}

"noEndpoint" - {
Expand Down
2 changes: 1 addition & 1 deletion example/todo/app/src/TodoServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object TodoServer extends cask.MainRoutes{
class transactional extends cask.RawDecorator{
def wrapFunction(pctx: cask.Request, delegate: Delegate) = {
sqliteClient.transaction { txn =>
val res = delegate(ctx, Map("txn" -> txn))
val res = delegate(pctx, Map("txn" -> txn))
if (res.isInstanceOf[cask.router.Result.Error]) txn.rollback()
res
}
Expand Down
2 changes: 1 addition & 1 deletion example/todoDb/app/src/TodoMvcDb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object TodoMvcDb extends cask.MainRoutes{
class transactional extends cask.RawDecorator{
def wrapFunction(pctx: cask.Request, delegate: Delegate) = {
sqliteClient.transaction { txn =>
val res = delegate(ctx, Map("txn" -> txn))
val res = delegate(pctx, Map("txn" -> txn))
if (res.isInstanceOf[cask.router.Result.Error]) txn.rollback()
res
}
Expand Down

0 comments on commit 1f7549c

Please sign in to comment.