未验证 提交 70457b58 编写于 作者: 梦境迷离's avatar 梦境迷离 提交者: GitHub

optimize code (#168)

上级 3325f1f7
version in ThisBuild := "0.4.3-SNAPSHOT"
ThisBuild / version := "0.4.3-SNAPSHOT"
......@@ -14,6 +14,20 @@ lazy val scala211 = "2.11.12"
lazy val scala213 = "2.13.8"
lazy val lastVersionForExamples = "0.4.2"
lazy val scalatestVersion = "3.2.11"
lazy val zioVersion = "1.0.13"
lazy val zioLoggingVersion = "0.5.14"
lazy val configVersion = "1.4.2"
lazy val caffeineVersion = "2.9.3"
lazy val zioRedisVersion = "0.0.0+381-86c20614-SNAPSHOT" // 实验性质的
lazy val zioSchemaVersion = "0.1.8"
lazy val scalaLoggingVersion = "3.9.4"
lazy val playJsonVersion = "2.7.4"
lazy val log4jVersion = "2.17.2"
lazy val jacksonScalaVersion = "2.13.2"
lazy val jraftVersion = "1.3.9"
lazy val commonSettings =
Seq(
organization := "org.bitlap",
......@@ -23,7 +37,7 @@ lazy val commonSettings =
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalatest" %% "scalatest" % "3.2.11" % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
), Compile / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n <= 12 => Nil
......@@ -45,9 +59,9 @@ lazy val `cacheable-core` = (project in file("cacheable-core"))
name := "smt-cacheable-core",
crossScalaVersions := List(scala213, scala212),
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "1.0.13",
"dev.zio" %% "zio-streams" % "1.0.13",
"dev.zio" %% "zio-logging" % "0.5.14"
"dev.zio" %% "zio" % zioVersion, // FIXME we should use compile or provide ???
"dev.zio" %% "zio-streams" % zioVersion,
"dev.zio" %% "zio-logging" % zioLoggingVersion
),
excludeDependencies ++= Seq(
InclExclRule("com.google.protobuf")
......@@ -62,13 +76,13 @@ lazy val `cacheable-caffeine` = (project in file("cacheable-caffeine"))
name := "smt-cacheable-caffeine",
crossScalaVersions := List(scala213, scala212),
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.4.2",
"com.github.ben-manes.caffeine" % "caffeine" % "2.9.3"
"com.typesafe" % "config" % configVersion,
"com.github.ben-manes.caffeine" % "caffeine" % caffeineVersion
),
excludeDependencies ++= Seq(
InclExclRule("com.google.protobuf")
)
).dependsOn(`cacheable-core`)
).dependsOn(`cacheable-core` % "compile->compile;test->test")
.settings(paradise())
.enablePlugins(HeaderPlugin)
......@@ -78,16 +92,16 @@ lazy val `cacheable-redis` = (project in file("cacheable-redis"))
name := "smt-cacheable-redis",
crossScalaVersions := List(scala213, scala212),
libraryDependencies ++= Seq(
"dev.zio" %% "zio-redis" % "0.0.0+381-86c20614-SNAPSHOT", // 实验性质的
"com.typesafe" % "config" % "1.4.2",
"dev.zio" %% "zio-schema" % "0.1.8",
"dev.zio" %% "zio-schema-json" % "0.1.8",
"dev.zio" %% "zio-schema-derivation" % "0.1.8" % Test,
"dev.zio" %% "zio-redis" % zioRedisVersion,
"com.typesafe" % "config" % configVersion,
"dev.zio" %% "zio-schema" % zioSchemaVersion,
"dev.zio" %% "zio-schema-json" % zioSchemaVersion,
"dev.zio" %% "zio-schema-derivation" % zioSchemaVersion % Test,
),
excludeDependencies ++= Seq(
InclExclRule("com.google.protobuf")
)
).dependsOn(`cacheable-core`)
).dependsOn(`cacheable-core` % "compile->compile;test->test")
.settings(paradise())
.enablePlugins(HeaderPlugin)
......@@ -109,13 +123,13 @@ lazy val tools = (project in file("tools"))
name := "smt-tools",
crossScalaVersions := List(scala213, scala212, scala211),
libraryDependencies ++= Seq(
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
"com.typesafe.play" %% "play-json" % "2.7.4" % Test,
"org.apache.logging.log4j" % "log4j-api" % "2.17.2" % Test,
"org.apache.logging.log4j" % "log4j-core" % "2.17.2" % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.17.2" % Test,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.13.2" % Test,
"com.alipay.sofa" % "jraft-core" % "1.3.9" % Test
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
"com.typesafe.play" %% "play-json" % playJsonVersion % Test,
"org.apache.logging.log4j" % "log4j-api" % log4jVersion % Test,
"org.apache.logging.log4j" % "log4j-core" % log4jVersion % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % log4jVersion % Test,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonScalaVersion % Test,
"com.alipay.sofa" % "jraft-core" % jraftVersion % Test
),
ProtocConfig / sourceDirectory := {
CrossVersion.partialVersion(scalaVersion.value) match {
......@@ -152,6 +166,7 @@ lazy val root = (project in file(".")).aggregate(tools, `cacheable-core`, `cache
)
)
//FIXME root doesnot aggregate these examples
lazy val `scala2-13` = (project in file("examples/scala2-13")).settings(scalaVersion := scala213)
.settings(libraryDependencies ++= Seq(
"org.bitlap" %% "smt-tools" % lastVersionForExamples,
......
......@@ -36,6 +36,5 @@ import scala.annotation.{ StaticAnnotation, compileTimeOnly }
*/
@compileTimeOnly("enable macro to expand macro annotations")
final class cacheEvict(local: Boolean = true, values: List[String] = Nil) extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro CacheEvictMacro.CacheEvictProcessor.impl
}
......@@ -35,6 +35,5 @@ import scala.annotation.{ StaticAnnotation, compileTimeOnly }
*/
@compileTimeOnly("enable macro to expand macro annotations")
final class cacheable(local: Boolean = true) extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro CacheableProcessor.impl
}
......@@ -37,8 +37,6 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
import c.universe._
protected val verbose: Boolean = false
/**
* Output ast result.
*
......@@ -78,7 +76,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
case tree :: tail =>
tree match {
case DefDef(_, name, _, _, _, _) =>
c.info(c.enclosingPosition, s"Method: `${name.decodedName.toString}` in enclosing class: `$getEnclosingClassName`.", force = verbose)
c.info(c.enclosingPosition, s"Method: `${name.decodedName.toString}` in enclosing class: `$getEnclosingClassName`.", force = true)
buffer.append(name)
doFind(tail)
case _ =>
......
......@@ -31,8 +31,8 @@ import scala.concurrent.duration.Duration
* annotation to record method cost time.
*
* @author 梦境迷离
* @param limit Time consuming condition to trigger log
* @param logLevel Log Level
* @param limit Time consuming condition to trigger log.
* @param logLevel Log Level.
* @since 2021/8/7
* @version 1.0
*/
......
......@@ -30,7 +30,6 @@ import scala.annotation.{ StaticAnnotation, compileTimeOnly }
*
* @author 梦境迷离
* @author choly
*
* @param nonTypeRefers Whether to not generate the subclass of the TypeReference for paramTypes of class.
* @since 2021/8/3
* @version 1.0
......
/*
* Copyright (c) 2022 bitlap
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.logs
/**
*
* @author 梦境迷离
* @param classNameStr The Class Name.
* @param isClass Is it a class?
* @since 2021/7/26
* @version 1.0
*/
case class LogTransferArgument(classNameStr: String, isClass: Boolean)
......@@ -23,7 +23,13 @@ package org.bitlap.tools.logs
import org.bitlap.tools.PACKAGE
import org.bitlap.tools.logs.extension.{ ScalaLoggingLazyImpl, ScalaLoggingStrictImpl }
import org.bitlap.tools.logs.impl.{ JLogImpl, Log4J2Impl, Slf4jImpl }
/**
*
* @author 梦境迷离
* @version 1.0,2022/3/29
*/
object LogType extends Enumeration {
type LogType = Value
......@@ -41,6 +47,7 @@ object LogType extends Enumeration {
types.getOrElse(logType, default = throw new Exception(s"Not support log type: $logType"))
}
// TODO not use Enumeratio
def getLogType(shortType: String): LogType = {
val tpe1 = s"$PACKAGE.logs.$shortType" //LogType.JLog
val tpe2 = s"$PACKAGE.logs.LogType.$shortType" // JLog
......
......@@ -22,7 +22,7 @@
package org.bitlap.tools.logs.extension
import org.bitlap.tools.logs.LogType.LogType
import org.bitlap.tools.logs.{ BaseLog, LogTransferArgument, LogType }
import org.bitlap.tools.logs.{ BaseLog, LogArgument, LogType }
import scala.reflect.macros.whitebox
......@@ -37,7 +37,7 @@ object ScalaLoggingLazyImpl extends BaseLog {
override val `type`: LogType = LogType.ScalaLoggingLazy
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
override def getTemplate(c: whitebox.Context)(logArgument: LogArgument): c.Tree = {
import c.universe._
tq"_root_.org.bitlap.tools.logs.extension.ScalaLazyLogging"
}
......
......@@ -22,7 +22,7 @@
package org.bitlap.tools.logs.extension
import org.bitlap.tools.logs.LogType.LogType
import org.bitlap.tools.logs.{ BaseLog, LogTransferArgument, LogType }
import org.bitlap.tools.logs.{ BaseLog, LogArgument, LogType }
import scala.reflect.macros.whitebox
......@@ -37,7 +37,7 @@ object ScalaLoggingStrictImpl extends BaseLog {
override val `type`: LogType = LogType.ScalaLoggingStrict
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
override def getTemplate(c: whitebox.Context)(logArgument: LogArgument): c.Tree = {
import c.universe._
tq"_root_.org.bitlap.tools.logs.extension.ScalaStrictLogging"
}
......
......@@ -19,22 +19,28 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.logs
package org.bitlap.tools.logs.impl
import org.bitlap.tools.logs.{ BaseLog, LogArgument, LogType }
import org.bitlap.tools.logs.LogType.LogType
import scala.reflect.macros.whitebox
/**
*
* @author 梦境迷离
* @version 1.0,2022/3/29
*/
object JLogImpl extends BaseLog {
override val `type`: LogType = LogType.JLog
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
override def getTemplate(c: whitebox.Context)(logArgument: LogArgument): c.Tree = {
import c.universe._
if (logTransferArgument.isClass) {
q"""@transient private final val log: java.util.logging.Logger = java.util.logging.Logger.getLogger(classOf[${TypeName(logTransferArgument.classNameStr)}].getName)"""
if (logArgument.isClass) {
q"""@transient private final val log: java.util.logging.Logger = java.util.logging.Logger.getLogger(classOf[${TypeName(logArgument.classNameStr)}].getName)"""
} else {
q"""@transient private final val log: java.util.logging.Logger = java.util.logging.Logger.getLogger(${TermName(logTransferArgument.classNameStr)}.getClass.getName)"""
q"""@transient private final val log: java.util.logging.Logger = java.util.logging.Logger.getLogger(${TermName(logArgument.classNameStr)}.getClass.getName)"""
}
}
......
......@@ -19,22 +19,28 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.logs
package org.bitlap.tools.logs.impl
import org.bitlap.tools.logs.{ BaseLog, LogArgument, LogType }
import org.bitlap.tools.logs.LogType.LogType
import scala.reflect.macros.whitebox
/**
*
* @author 梦境迷离
* @version 1.0,2022/3/29
*/
object Log4J2Impl extends BaseLog {
override val `type`: LogType = LogType.Log4j2
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
override def getTemplate(c: whitebox.Context)(logArgument: LogArgument): c.Tree = {
import c.universe._
if (logTransferArgument.isClass) {
q"""@transient private final val log: org.apache.logging.log4j.Logger = org.apache.logging.log4j.LogManager.getLogger(classOf[${TypeName(logTransferArgument.classNameStr)}].getName)"""
if (logArgument.isClass) {
q"""@transient private final val log: org.apache.logging.log4j.Logger = org.apache.logging.log4j.LogManager.getLogger(classOf[${TypeName(logArgument.classNameStr)}].getName)"""
} else {
q"""@transient private final val log: org.apache.logging.log4j.Logger = org.apache.logging.log4j.LogManager.getLogger(${TermName(logTransferArgument.classNameStr)}.getClass.getName)"""
q"""@transient private final val log: org.apache.logging.log4j.Logger = org.apache.logging.log4j.LogManager.getLogger(${TermName(logArgument.classNameStr)}.getClass.getName)"""
}
}
......
......@@ -19,22 +19,28 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.logs
package org.bitlap.tools.logs.impl
import org.bitlap.tools.logs.{ BaseLog, LogArgument, LogType }
import org.bitlap.tools.logs.LogType.LogType
import scala.reflect.macros.whitebox
/**
*
* @author 梦境迷离
* @version 1.0,2022/3/29
*/
object Slf4jImpl extends BaseLog {
override val `type`: LogType = LogType.Slf4j
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
override def getTemplate(c: whitebox.Context)(logArgument: LogArgument): c.Tree = {
import c.universe._
if (logTransferArgument.isClass) {
q"""@transient private final val log: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(classOf[${TypeName(logTransferArgument.classNameStr)}])"""
if (logArgument.isClass) {
q"""@transient private final val log: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(classOf[${TypeName(logArgument.classNameStr)}])"""
} else {
q"""@transient private final val log: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(${TermName(logTransferArgument.classNameStr)}.getClass)"""
q"""@transient private final val log: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(${TermName(logArgument.classNameStr)}.getClass)"""
}
}
}
......@@ -19,15 +19,37 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.logs
package org.bitlap.tools
import org.bitlap.tools.logs.LogType.LogType
import scala.reflect.macros.whitebox
trait BaseLog {
/**
*
* @author 梦境迷离
* @version 1.0,2022/3/29
*/
package object logs {
/**
*
* @author 梦境迷离
* @version 1.0,2022/3/29
*/
private[tools] trait BaseLog {
val `type`: LogType
def getTemplate(c: whitebox.Context)(logArgument: LogArgument): c.Tree
}
val `type`: LogType
/**
*
* @author 梦境迷离
* @param classNameStr The class Name.
* @param isClass Is it a class?
*/
private[tools] case class LogArgument(classNameStr: String, isClass: Boolean)
def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree
}
......@@ -264,35 +264,13 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
constructor
}
/**
* We generate apply method with currying, and we have to deal with the first layer of currying alone.
*
* @param typeName
* @param fieldss
* @return A apply method with currying.
* @example Return a tree, such as `def apply(int: Int)(j: Int)(k: Option[String])(t: Option[Long]): B3 = new B3(int)(j)(k)(t)`
*/
def getApplyMethodWithCurrying(typeName: TypeName, fieldss: List[List[Tree]], classTypeParams: List[Tree]): Tree = {
val allFieldsTermName = fieldss.map(f => getConstructorParamsNameWithType(f))
val returnTypeParams = extractClassTypeParamsTypeName(classTypeParams)
// not currying
val applyMethod = if (fieldss.isEmpty || fieldss.size == 1) {
q"def apply[..$classTypeParams](..${allFieldsTermName.flatten}): $typeName[..$returnTypeParams] = ${getConstructorWithCurrying(typeName, fieldss, isCase = false)}"
} else {
// currying
val first = allFieldsTermName.head
q"def apply[..$classTypeParams](..$first)(...${allFieldsTermName.tail}): $typeName[..$returnTypeParams] = ${getConstructorWithCurrying(typeName, fieldss, isCase = false)}"
}
applyMethod
}
/**
* Only for primitive types, we can get type and map to scala type.
*
* @param jType java type name
* @param javaType java type name
* @return Scala type name
*/
def toScalaType(jType: String): String = {
def toScalaType(javaType: String): String = {
val types = Map(
"java.lang.Integer" -> "Int",
"java.lang.Long" -> "Long",
......@@ -304,7 +282,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
"java.lang.Character" -> "Char",
"java.lang.String" -> "String"
)
types.getOrElse(jType, jType)
types.getOrElse(javaType, javaType)
}
/**
......@@ -337,9 +315,9 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
def typeName: TypeName = symbol.name.toTypeName
def symbol: c.universe.Symbol = paramType.typeSymbol
def symbol: Symbol = paramType.typeSymbol
def paramType = c.typecheck(tq"$tpt", c.TYPEmode).tpe
def paramType: Type = c.typecheck(tq"$tpt", c.TYPEmode).tpe
}
/**
......
......@@ -35,6 +35,28 @@ object applyMacro {
import c.universe._
/**
* We generate apply method with currying, and we have to deal with the first layer of currying alone.
*
* @param typeName
* @param fieldss
* @return A apply method with currying.
* @example Return a tree, such as `def apply(int: Int)(j: Int)(k: Option[String])(t: Option[Long]): B3 = new B3(int)(j)(k)(t)`
*/
private def getApplyMethodWithCurrying(typeName: TypeName, fieldss: List[List[Tree]], classTypeParams: List[Tree]): Tree = {
val allFieldsTermName = fieldss.map(f => getConstructorParamsNameWithType(f))
val returnTypeParams = extractClassTypeParamsTypeName(classTypeParams)
// not currying
val applyMethod = if (fieldss.isEmpty || fieldss.size == 1) {
q"def apply[..$classTypeParams](..${allFieldsTermName.flatten}): $typeName[..$returnTypeParams] = ${getConstructorWithCurrying(typeName, fieldss, isCase = false)}"
} else {
// currying
val first = allFieldsTermName.head
q"def apply[..$classTypeParams](..$first)(...${allFieldsTermName.tail}): $typeName[..$returnTypeParams] = ${getConstructorWithCurrying(typeName, fieldss, isCase = false)}"
}
applyMethod
}
override def createCustomExpr(classDecl: ClassDef, compDeclOpt: Option[ModuleDef] = None): Any = {
val classDefinition = mapToClassDeclInfo(classDecl)
val apply = getApplyMethodWithCurrying(classDefinition.className, classDefinition.classParamss, classDefinition.classTypeParams)
......
......@@ -28,9 +28,9 @@ import scala.concurrent.duration._
import scala.reflect.macros.whitebox
/**
* 1.Annotation is only supported use on non-abstract method.
* 2.For methods that are not future, `try finally` is used to implement the timing of the method.
* 3.For methods that are Futures, `Future map` is used to implement the timing of the method.
* 1. This annotation only support use on non-abstract method.
* 2. For methods that are not future, `try finally` is used to implement the timing of the method.
* 3. For methods that are Futures, `Future map` is used to implement the timing of the method.
*
* @author 梦境迷离
* @since 2021/8/7
......
......@@ -22,7 +22,7 @@
package org.bitlap.tools.macros
import org.bitlap.tools.logs.LogType._
import org.bitlap.tools.logs.{ LogTransferArgument, LogType }
import org.bitlap.tools.logs.{ LogArgument, LogType }
import org.bitlap.tools.{ PACKAGE, logs }
import scala.reflect.macros.whitebox
......@@ -59,7 +59,7 @@ object logMacro {
}
private def logTree(annottees: Seq[c.universe.Expr[Any]]): c.universe.Tree = {
val buildArg = (name: Name) => LogTransferArgument(name.toTermName.decodedName.toString, isClass = true)
val buildArg = (name: Name) => LogArgument(name.toTermName.decodedName.toString, isClass = true)
(annottees.map(_.tree) match {
case (classDef: ClassDef) :: Nil =>
LogType.getLogImpl(extractArgs).getTemplate(c)(buildArg(classDef.name))
......
......@@ -29,7 +29,7 @@ package org.bitlap.tools
*/
package object macros {
object ErrorMessage {
private[macros] object ErrorMessage {
// common error msg
final lazy val ONLY_CLASS: String = "Annotation is only supported on class."
final lazy val ONLY_CASE_CLASS: String = "Annotation is only supported on case class."
......
......@@ -19,12 +19,11 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.method
package org.bitlap.tools.methods
import org.bitlap.tools.method.impl.ProcessorCreatorMacro
import org.bitlap.tools.methods.impl.ProcessorCreatorMacro
import java.util.concurrent.Executor
import scala.language.higherKinds
/**
* The macro util to generate processor for alipay sofa jraft rpc.
......@@ -36,19 +35,19 @@ object ProcessorCreator {
/**
*
* @param service Instance of the [[Service]]
* @param service Instance of the `Service`
* @param defaultResp Default instance of the Response Message
* @param executor Instance of the Executor
* @param processRequest Function to handle request
* @param processException Function to handle exception
* @tparam RRC RpcRequestClosure
* @tparam RRP RpcRequestProcessor
* @tparam RC RpcContext
* @tparam RRC `RpcRequestClosure`
* @tparam RRP `RpcRequestProcessor`
* @tparam RC `RpcContext`
* @tparam Req Request Message of the protobuf
* @tparam Resp Response Message of the protobuf
* @tparam Service Should be custom class/interface/trait which handle the business logic of Processors
* @tparam E Should be subclass of the Executor
* @return [[ RRP ]] Instance of the RpcRequestProcessor subclass
* @return [[ RRP ]] Instance of the `RpcRequestProcessor` subclass
*/
def apply[RRC, RRP[_ <: Req], RC, Req, Resp, Service, E <: Executor]
(
......
......@@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.method.impl
package org.bitlap.tools.methods.impl
/**
*
......
......@@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.method.impl
package org.bitlap.tools.methods.impl
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
......@@ -168,7 +168,7 @@ object ProcessorCreatorMacro {
$processException(service, rpcCtx, exception)
}
}
val service = new org.bitlap.tools.method.impl.Creator[$serviceType].createInstance(null)(0)
val service = new org.bitlap.tools.utils.ScalaReflectionUtils[$serviceType].createInstance(null)(0)
new $className(service)
"""
printTree[RRP](c)(processor)
......
......@@ -41,6 +41,5 @@ final class toString(
includeFieldNames: Boolean = true,
callSuper: Boolean = false
) extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro toStringMacro.ToStringProcessor.impl
}
......@@ -19,19 +19,19 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.bitlap.tools.method.impl
package org.bitlap.tools.utils
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe._
/**
* Runtime reflection
* Scala runtime reflection
*
* @author 梦境迷离
* @since 2021/12/5
* @version 1.0
*/
class Creator[T: WeakTypeTag] {
class ScalaReflectionUtils[T: WeakTypeTag] {
def createInstance(args: AnyRef*)(ctor: Int = 0): T = {
val tt = weakTypeTag[T]
......
......@@ -22,10 +22,10 @@
package org.bitlap.tools
import com.alipay.sofa.jraft.rpc.{ RpcContext, RpcRequestClosure, RpcRequestProcessor }
import org.bitlap.tools.methods.ProcessorCreator
import org.bitlap.tools.test.proto.BOpenSession.{ BOpenSessionReq, BOpenSessionResp }
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.bitlap.tools.method.ProcessorCreator
import java.util.concurrent.Executor
import scala.jdk.CollectionConverters.MapHasAsScala
......
......@@ -21,9 +21,9 @@
package org.bitlap.tools
import org.bitlap.tools.utils.ScalaReflectionUtils
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.bitlap.tools.method.impl.Creator
/**
*
......@@ -31,9 +31,9 @@ import org.bitlap.tools.method.impl.Creator
* @since 2021/12/5
* @version 1.0
*/
class CreatorTest extends AnyFlatSpec with Matchers {
class ScalaReflectionUtilsTest extends AnyFlatSpec with Matchers {
"Creator" should "ok" in {
val service = new Creator[NetService]().createInstance(null)(0)
val service = new ScalaReflectionUtils[NetService]().createInstance(null)(0)
println(service.openSession("1", "2"))
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册