From 1f7549cf30ae1a054489d17399acc9ee7541edec Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sat, 2 Nov 2024 18:56:04 +0100 Subject: [PATCH] port changes to scala 2 --- cask/src-2/cask/router/Macros.scala | 13 ++++++------- cask/src-2/cask/router/RoutesEndpointMetadata.scala | 1 - cask/src-3/cask/router/Macros.scala | 2 +- cask/test/src/test/cask/FailureTests.scala | 2 +- example/todo/app/src/TodoServer.scala | 2 +- example/todoDb/app/src/TodoMvcDb.scala | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cask/src-2/cask/router/Macros.scala b/cask/src-2/cask/router/Macros.scala index 6a8e14294a..04bd5628ad 100644 --- a/cask/src-2/cask/router/Macros.scala +++ b/cask/src-2/cask/router/Macros.scala @@ -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()) @@ -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) ) @@ -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{ @@ -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) diff --git a/cask/src-2/cask/router/RoutesEndpointMetadata.scala b/cask/src-2/cask/router/RoutesEndpointMetadata.scala index 8169781e22..9acbcbf7e1 100644 --- a/cask/src-2/cask/router/RoutesEndpointMetadata.scala +++ b/cask/src-2/cask/router/RoutesEndpointMetadata.scala @@ -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") ) diff --git a/cask/src-3/cask/router/Macros.scala b/cask/src-3/cask/router/Macros.scala index 4d8429f883..64b5f2dc42 100644 --- a/cask/src-3/cask/router/Macros.scala +++ b/cask/src-3/cask/router/Macros.scala @@ -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 ) } diff --git a/cask/test/src/test/cask/FailureTests.scala b/cask/test/src/test/cask/FailureTests.scala index 3f78e5e11c..dee2f6a829 100644 --- a/cask/test/src/test/cask/FailureTests.scala +++ b/cask/test/src/test/cask/FailureTests.scala @@ -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" - { diff --git a/example/todo/app/src/TodoServer.scala b/example/todo/app/src/TodoServer.scala index 44081229c1..ea0c456cee 100644 --- a/example/todo/app/src/TodoServer.scala +++ b/example/todo/app/src/TodoServer.scala @@ -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 } diff --git a/example/todoDb/app/src/TodoMvcDb.scala b/example/todoDb/app/src/TodoMvcDb.scala index 0b2c72d6bf..413db40bfb 100644 --- a/example/todoDb/app/src/TodoMvcDb.scala +++ b/example/todoDb/app/src/TodoMvcDb.scala @@ -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 }