提交 6708f5e3 编写于 作者: 梦境迷离's avatar 梦境迷离

fix some

上级 dad7294f
......@@ -26,6 +26,7 @@ import io.github.dreamylost.logs.LogType.LogType
import scala.reflect.macros.whitebox
trait BaseLog {
val typ: LogType
def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree
......
......@@ -67,15 +67,15 @@ object builderMacro {
val builderMethod = q"def builder[..$classTypeParams](): $builderClassName[..$returnTypeParams] = new $builderClassName()"
val buulderClass =
q"""
class $builderClassName[..$classTypeParams] {
class $builderClassName[..$classTypeParams] {
..$builderFieldDefinitions
..$builderFieldDefinitions
..$builderFieldMethods
..$builderFieldMethods
def build(): $typeName[..$returnTypeParams] = ${getConstructorWithCurrying(typeName, fieldss, isCase)}
}
"""
def build(): $typeName[..$returnTypeParams] = ${getConstructorWithCurrying(typeName, fieldss, isCase)}
}
"""
List(builderMethod, buulderClass)
}
......
......@@ -84,7 +84,7 @@ object constructorMacro {
this(..${allFieldsTermName.flatten})
..${annotteeClassFieldNames.map(f => q"this.$f = $f")}
}
"""
"""
} else {
// NOTE: currying constructor overload must be placed in the first bracket block.
val allClassCtorParamsNameWithType = annotteeClassParams.map(cc => getConstructorParamsNameWithType(cc))
......
......@@ -54,7 +54,7 @@ object elapsedMacro {
}
private val extractArgumentsDetail: (Duration, LogLevel) = extractArgumentsTuple2 {
case q"new elapsed(limit=$limit, logLevel=$logLevel)" => (evalTree[Duration](limit.asInstanceOf[Tree]), getLogLevel(logLevel.asInstanceOf[Tree]))
case q"new elapsed(limit=$limit, logLevel=$logLevel)" => (evalTree(limit.asInstanceOf[Tree]), getLogLevel(logLevel.asInstanceOf[Tree]))
case _ => c.abort(c.enclosingPosition, ErrorMessage.UNEXPECTED_PATTERN)
}
......@@ -63,12 +63,13 @@ object elapsedMacro {
}
private def getLog(methodName: TermName, logBy: Tree): c.universe.Tree = {
// CI will fail when use lambda.
implicit val durationApply: c.universe.Liftable[Duration] = new Liftable[Duration] {
override def apply(value: Duration): c.universe.Tree = q"${value._1}"
}
q"""
val $valDef = _root_.scala.concurrent.duration.Duration.fromNanos(System.nanoTime()) - $start
if ($valDef._1 >= ${extractArgumentsDetail._1}) $logBy(StringContext("slow invoked: [", "] elapsed [", "]").s(${methodName.toString}, $valDef.toMillis))
val $valDef = _root_.scala.concurrent.duration.Duration.fromNanos(System.nanoTime()) - $start
if ($valDef._1 >= ${extractArgumentsDetail._1}) $logBy(StringContext("slow invoked: [", "] elapsed [", "]").s(${methodName.toString}, $valDef.toMillis))
"""
}
......@@ -152,7 +153,7 @@ object elapsedMacro {
mapToNewMethod(defDef, defDef => {
q"""
$getStartExpr
${Try.apply(defDef.rhs, Nil, getPrintlnLog(defDef.name))}
${Try(defDef.rhs, Nil, getPrintlnLog(defDef.name))}
"""
})
}
......
......@@ -78,12 +78,12 @@ object equalsAndHashCodeMacro {
val canEqual = if (existsCanEqual) q"" else q"$modifiers def canEqual(that: Any) = that.isInstanceOf[$className]"
val equalsMethod =
q"""
override def equals(that: Any): Boolean =
that match {
case t: $className => t.canEqual(this) && Seq(..$equalsExprs).forall(f => f) && ${if (existsSuperClassExcludeSdkClass(superClasses)) q"super.equals(that)" else q"true"}
case _ => false
}
"""
override def equals(that: Any): Boolean =
that match {
case t: $className => t.canEqual(this) && Seq(..$equalsExprs).forall(f => f) && ${if (existsSuperClassExcludeSdkClass(superClasses)) q"super.equals(that)" else q"true"}
case _ => false
}
"""
List(canEqual, equalsMethod)
}
......
......@@ -31,10 +31,10 @@ package object macros {
object ErrorMessage {
// common error msg
final lazy val ONLY_CLASS = "Annotation is only supported on class."
final lazy val ONLY_CASE_CLASS = "Annotation is only supported on case class."
final lazy val ONLY_OBJECT_CLASS = "Annotation is only supported on class or object."
final lazy val UNEXPECTED_PATTERN = "Unexpected annotation pattern!"
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."
final lazy val ONLY_OBJECT_CLASS: String = "Annotation is only supported on class or object."
final lazy val UNEXPECTED_PATTERN: String = "Unexpected annotation pattern!"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册