From 4fbe60a5cf5ab26c6402bcdf98e7d0d8394e4d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=A2=83=E8=BF=B7=E7=A6=BB?= Date: Tue, 17 Aug 2021 22:24:38 +0800 Subject: [PATCH] add doc --- .../macros/AbstractMacroProcessor.scala | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/scala/io/github/dreamylost/macros/AbstractMacroProcessor.scala b/src/main/scala/io/github/dreamylost/macros/AbstractMacroProcessor.scala index 5908892..bd82f55 100644 --- a/src/main/scala/io/github/dreamylost/macros/AbstractMacroProcessor.scala +++ b/src/main/scala/io/github/dreamylost/macros/AbstractMacroProcessor.scala @@ -45,12 +45,12 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * * @param classDecl * @param compDeclOpt - * @return c.Expr[Any], Why use Any? The dependent type need aux-pattern in scala2. Now let's get around this. + * @return `c.Expr[Any]`, Why use Any? The dependent type need aux-pattern in scala2. Now let's get around this. */ def createCustomExpr(classDecl: ClassDef, compDeclOpt: Option[ModuleDef] = None): Any = ??? /** - * Subclasses should override this method if it cannot use `createCustomExpr` method. + * Subclasses should override this method if it cannot use [[createCustomExpr]] method. * * @param annottees * @return Return a macro expanded final syntax tree. @@ -110,7 +110,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Check the class and its companion object, and return the class definition. * * @param annottees - * @return Return ClassDef + * @return Return a [[ClassDef]] */ def checkGetClassDef(annottees: Seq[Expr[Any]]): ClassDef = { annottees.map(_.tree).toList match { @@ -124,7 +124,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Get object if it exists. * * @param annottees - * @return Return {{ Option[ModuleDef] }} + * @return Return a optional [[ModuleDef]] */ def getModuleDefOption(annottees: Seq[Expr[Any]]): Option[ModuleDef] = { annottees.map(_.tree).toList match { @@ -164,7 +164,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Check whether the mods of the fields has a `private[this]` or `protected[this]`, because it cannot be used out of class. * * @param tree Tree is a field or method? - * @return Return false if mods exists private[this] or protected[this] + * @return Return false if mods exists `private[this]` or `protected[this]` */ def isNotLocalClassMember(tree: Tree): Boolean = { lazy val modifierNotLocal = (mods: Modifiers) => { @@ -183,7 +183,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Get the field TermName with type. * * @param annotteeClassParams - * @return Return a sequence of Tree, each one is {{ i: Int}} + * @return Return a sequence of [[Tree]], each one is `tname: tpt` */ def getConstructorParamsNameWithType(annotteeClassParams: Seq[Tree]): Seq[Tree] = { annotteeClassParams.map(_.asInstanceOf[ValDef]).map(v => q"${v.name}: ${v.tpt}") @@ -195,7 +195,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * @param compDeclOpt * @param codeBlocks * @param className - * @return Return a ModuleDef which was appended codeblocks, ModuleDef may already exist or may be newly created + * @return Return a [[ModuleDef]] which was appended codeblocks, ModuleDef may already exist or may be newly created */ def appendModuleBody( compDeclOpt: Option[ModuleDef], @@ -210,10 +210,10 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { } /** - * Extract the internal fields of members belonging to the class, but not in primary constructor. + * Extract the internal fields of members belonging to the class, but not in primary constructor. * * @param annotteeClassDefinitions - * @return Return a sequence of ValDef + * @return Return a sequence of [[ValDef]] */ def getClassMemberValDefs(annotteeClassDefinitions: Seq[Tree]): Seq[ValDef] = { annotteeClassDefinitions.filter(_ match { @@ -226,27 +226,27 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Extract the constructor params ValDef and flatten for currying. * * @param annotteeClassParams - * @return Return a sequence of ValDef + * @return Return a sequence of [[ValDef]] */ def getClassConstructorValDefsFlatten(annotteeClassParams: List[List[Tree]]): Seq[ValDef] = { annotteeClassParams.flatten.map(_.asInstanceOf[ValDef]) } /** - * Extract the constructor params ValDef not flatten. + * Extract the constructor params [[ValDef]] not flatten. * * @param annotteeClassParams - * @return Return a sequence of {{ Seq[ValDef] }} + * @return Return a double sequence of [[ValDef]] */ def getClassConstructorValDefsNotFlatten(annotteeClassParams: List[List[Tree]]): Seq[Seq[ValDef]] = { annotteeClassParams.map(_.map(_.asInstanceOf[ValDef])) } /** - * Extract the methods belonging to the class, contains Secondary Constructor. + * Extract the methods belonging to the class, contains Secondary Constructor. * * @param annotteeClassDefinitions - * @return Return a sequence of DefDef + * @return Return a sequence of [[DefDef]] */ def getClassMemberDefDefs(annotteeClassDefinitions: Seq[Tree]): Seq[DefDef] = { annotteeClassDefinitions.filter(_ match { @@ -262,7 +262,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * @param fieldss * @param isCase * @return A constructor with currying, it not contains tpt, provide for calling method. - * @example Return a tree, such as {{ new TestClass12(i)(j)(k)(t) }} + * @example Return a tree, such as `new TestClass12(i)(j)(k)(t)` */ def getConstructorWithCurrying(typeName: TypeName, fieldss: List[List[Tree]], isCase: Boolean): Tree = { val fieldssValDefNotFlatten = getClassConstructorValDefsNotFlatten(fieldss) @@ -285,7 +285,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * @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) }} + * @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)) @@ -327,7 +327,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * This is because the generic parameters of a class cannot be used directly in the return type, and need to be converted. * * @param tpParams - * @return Return a sequence of TypeName + * @return Return a sequence of [[TypeName]] */ def extractClassTypeParamsTypeName(tpParams: List[Tree]): List[TypeName] = { tpParams.map(_.asInstanceOf[TypeDef].name) @@ -358,10 +358,10 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { } /** - * Retrieves the accessor fields on a class and returns a Seq of ValDefAccessor. + * Retrieves the accessor fields on a class and returns a Seq of [[ValDefAccessor]]. * * @param params The list of params retrieved from the class - * @return Return a sequence of tuples where each tuple encodes the string name and string type of a field + * @return Return a sequence of [[ValDefAccessor]] */ def valDefAccessors(params: Seq[Tree]): Seq[ValDefAccessor] = { params.map { @@ -374,7 +374,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Extract the necessary structure information of the class for macro programming. * * @param classDecl - * @return Return the expansion of the class definition as ClassDefinition + * @return Return the expansion of the class definition as [[ClassDefinition]] */ def mapToClassDeclInfo(classDecl: ClassDef): ClassDefinition = { val q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }" = classDecl @@ -387,7 +387,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Extract the necessary structure information of the moduleDef for macro programming. * * @param moduleDef - * @return Return the expansion of the class definition as ClassDefinition + * @return Return the expansion of the class definition as [[ClassDefinition]] */ def mapToModuleDeclInfo(moduleDef: ModuleDef): ClassDefinition = { val q"$mods object $tpname extends { ..$earlydefns } with ..$parents { $self => ..$stats }" = moduleDef @@ -402,7 +402,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * * @param classDecl * @param classInfoAction Content body added in class definition - * @return Return a new ClassDef + * @return Return a new [[ClassDef]] */ def appendClassBody(classDecl: ClassDef, classInfoAction: ClassDefinition => List[Tree]): c.universe.ClassDef = { val classInfo = mapToClassDeclInfo(classDecl) @@ -443,7 +443,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * * @param defDef * @param defBodyAction Method body of final result - * @return Return a new DefDef which changed by defBodyAction function + * @return Return a new [[DefDef]] which changed by defBodyAction function */ def mapToMethodDef(defDef: DefDef, defBodyAction: => Tree): c.universe.DefDef = { val DefDef(mods, name, tparams, vparamss, tpt, rhs) = defDef @@ -465,7 +465,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * Find the specified Name in the enclosingClass definition. * * @param t - * @return Return a {{ Option[TermName] }} + * @return Return a optional [[TermName]] */ def findNameOnEnclosingClass(t: Name): Option[TermName] = { @tailrec -- GitLab