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

refactor

上级 83a835c8
...@@ -102,7 +102,11 @@ object constructorMacro { ...@@ -102,7 +102,11 @@ object constructorMacro {
val resTree = appendClassBody( val resTree = appendClassBody(
classDecl, classDecl,
classInfo => Seq(getThisMethodWithCurrying(classInfo.classParamss, classInfo.body))) classInfo => Seq(getThisMethodWithCurrying(classInfo.classParamss, classInfo.body)))
c.Expr(resTree) c.Expr(
q"""
${compDeclOpt.fold(EmptyTree)(x => x)}
$resTree
""")
} }
override def impl(annottees: c.universe.Expr[Any]*): c.universe.Expr[Any] = { override def impl(annottees: c.universe.Expr[Any]*): c.universe.Expr[Any] = {
...@@ -110,9 +114,9 @@ object constructorMacro { ...@@ -110,9 +114,9 @@ object constructorMacro {
if (isCaseClass(annotateeClass)) { if (isCaseClass(annotateeClass)) {
c.abort(c.enclosingPosition, ErrorMessage.ONLY_CLASS) c.abort(c.enclosingPosition, ErrorMessage.ONLY_CLASS)
} }
val res = returnWithCompanionObject(collectCustomExpr(annottees)(createCustomExpr).tree, annottees) val res = collectCustomExpr(annottees)(createCustomExpr)
printTree(force = extractArgumentsDetail._1, res) printTree(force = extractArgumentsDetail._1, res.tree)
c.Expr(res) res
} }
} }
......
...@@ -49,9 +49,8 @@ object equalsAndHashCodeMacro { ...@@ -49,9 +49,8 @@ object equalsAndHashCodeMacro {
c.abort(c.enclosingPosition, ErrorMessage.ONLY_CLASS) c.abort(c.enclosingPosition, ErrorMessage.ONLY_CLASS)
} }
val resTree = collectCustomExpr(annottees)(createCustomExpr) val resTree = collectCustomExpr(annottees)(createCustomExpr)
val res = returnWithCompanionObject(resTree.tree, annottees) printTree(force = extractArgumentsDetail._1, resTree.tree)
printTree(force = extractArgumentsDetail._1, res) resTree
c.Expr(res)
} }
/** /**
...@@ -120,11 +119,15 @@ object equalsAndHashCodeMacro { ...@@ -120,11 +119,15 @@ object equalsAndHashCodeMacro {
} }
val classDefinition = mapToClassDeclInfo(classDecl) val classDefinition = mapToClassDeclInfo(classDecl)
val res = appendClassBody(classDecl, classInfo => val res = appendClassBody(classDecl, classInfo =>
getEqualsMethod(classDefinition.className, map(classInfo), getEqualsMethod(classDefinition.className, map(classInfo), classDefinition.superClasses, classDefinition.body) ++
classDefinition.superClasses, classDefinition.body) ++
List(getHashcodeMethod(map(classInfo), classDefinition.superClasses)) List(getHashcodeMethod(map(classInfo), classDefinition.superClasses))
) )
c.Expr(res)
c.Expr(
q"""
${compDeclOpt.fold(EmptyTree)(x => x)}
$res
""")
} }
} }
......
...@@ -81,10 +81,9 @@ object jacksonEnumMacro { ...@@ -81,10 +81,9 @@ object jacksonEnumMacro {
} }
override def impl(annottees: c.universe.Expr[Any]*): c.universe.Expr[Any] = { override def impl(annottees: c.universe.Expr[Any]*): c.universe.Expr[Any] = {
val newClassExpr = collectCustomExpr(annottees)(createCustomExpr) val res = collectCustomExpr(annottees)(createCustomExpr)
val res = returnWithCompanionObject(newClassExpr.tree, annottees) printTree(force = extractArgumentsDetail._1, res.tree)
printTree(force = extractArgumentsDetail._1, res) res
c.Expr(res)
} }
override def createCustomExpr(classDecl: c.universe.ClassDef, compDeclOpt: Option[c.universe.ModuleDef]): Any = { override def createCustomExpr(classDecl: c.universe.ClassDef, compDeclOpt: Option[c.universe.ModuleDef]): Any = {
...@@ -95,11 +94,17 @@ object jacksonEnumMacro { ...@@ -95,11 +94,17 @@ object jacksonEnumMacro {
val q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends ..$bases { ..$body }" = classDecl val q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends ..$bases { ..$body }" = classDecl
val newFieldss = paramss.asInstanceOf[List[List[Tree]]].map(_.map(replaceAnnotation)) val newFieldss = paramss.asInstanceOf[List[List[Tree]]].map(_.map(replaceAnnotation))
val newClass = q"$mods class $tpname[..$tparams] $ctorMods(...$newFieldss) extends ..$bases { ..$body }" val newClass = q"$mods class $tpname[..$tparams] $ctorMods(...$newFieldss) extends ..$bases { ..$body }"
c.Expr( val res =
q""" q"""
..$typeReferClasses ..$typeReferClasses
$newClass $newClass
"""
c.Expr(
q"""
${compDeclOpt.fold(EmptyTree)(x => x)}
$res
""") """)
} }
} }
......
...@@ -74,9 +74,14 @@ object toStringMacro { ...@@ -74,9 +74,14 @@ object toStringMacro {
// Check the type of the class, which can only be defined on the ordinary class // Check the type of the class, which can only be defined on the ordinary class
val annotateeClass: ClassDef = checkAndGetClassDef(annottees) val annotateeClass: ClassDef = checkAndGetClassDef(annottees)
val resTree = appendClassBody(annotateeClass, _ => Seq(toStringTemplateImpl(argument, annotateeClass))) val resTree = appendClassBody(annotateeClass, _ => Seq(toStringTemplateImpl(argument, annotateeClass)))
val res = returnWithCompanionObject(resTree, annottees) val compDeclOpt = getCompanionObject(annottees)
printTree(argument.verbose, res) val res = c.Expr(
c.Expr[Any](res) q"""
${compDeclOpt.fold(EmptyTree)(x => x)}
$resTree
""")
printTree(force = extractArgumentsDetail._1, res.tree)
res
} }
private def printField(argument: Argument, lastParam: Option[String], field: Tree): Tree = { private def printField(argument: Argument, lastParam: Option[String], field: Tree): Tree = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册