Skip to content

Commit

Permalink
Defn.Def: add Decl.Def and Defn.Macro as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 2, 2022
1 parent cdee46b commit dce9e5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ case class Align(
treeCategory: Map[String, String] = Map(
"Defn.Val" -> "given/val/var/def",
"Defn.Var" -> "given/val/var/def",
"Decl.Def" -> "given/val/var/def",
"Defn.Def" -> "given/val/var/def",
"Defn.Macro" -> "given/val/var/def",
"Defn.GivenAlias" -> "given/val/var/def",
"Defn.Class" -> "class/object/trait/enum",
"Defn.Object" -> "class/object/trait/enum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ class FormatWriter(formatOps: FormatOps) {
def unapply(tree: Tree): Option[(List[meta.Mod], Tree)] =
tree match {
case p: Defn.Def => Some(p.mods -> p.body)
case p: Defn.Macro => Some(p.mods -> p.body)
case p: Defn.Given => Some(p.mods -> p.templ)
case p: Defn.GivenAlias => Some(p.mods -> p.body)
case p: Defn.Val => Some(p.mods -> p.rhs)
Expand Down Expand Up @@ -1863,6 +1864,7 @@ object FormatWriter {
case t: Pkg.Object => t.name.toString
// definitions
case t: Defn.Def => t.name.toString
case t: Defn.Macro => t.name.toString
case t: Defn.GivenAlias =>
val label = t.name.toString
if (label.isEmpty) "given" else label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ object TreeOps {
def loop(subtree: Tree): Unit = {
subtree match {
case t: Defn.Class => addDefn[KwClass](t.mods, t)
case t: Decl.Def => addDefn[KwDef](t.mods, t)
case t: Defn.Def => addDefn[KwDef](t.mods, t)
case t: Defn.Given => addDefn[KwGiven](t.mods, t)
case t: Defn.GivenAlias => addDefn[KwGiven](t.mods, t)
case t: Defn.Macro => addDefn[KwDef](t.mods, t)
case t: Decl.Def => addDefn[KwDef](t.mods, t)
case t: Decl.Given => addDefn[KwGiven](t.mods, t)
case t: Defn.Given => addDefn[KwGiven](t.mods, t)
case t: Defn.GivenAlias => addDefn[KwGiven](t.mods, t)
case t: Defn.Enum => addDefn[KwEnum](t.mods, t)
case t: Defn.ExtensionGroup =>
addDefnTokens(Nil, t, "extension", soft.KwExtension.unapply)
Expand Down Expand Up @@ -317,17 +317,17 @@ object TreeOps {

def isDefDef(tree: Tree): Boolean =
tree match {
case _: Decl.Def | _: Defn.Def => true
case _: Decl.Def | _: Defn.Def | _: Defn.Macro => true
case _ => false
}

@tailrec
def defDefBody(tree: Tree): Option[Tree] =
tree match {
case d: Defn.Def => Some(d.body)
case d: Defn.Macro => Some(d.body)
case d: Defn.Given => Some(d.templ)
case d: Defn.GivenAlias => Some(d.body)
case d: Defn.Macro => Some(d.body)
case d: Defn.Val => Some(d.rhs)
case d: Defn.Var => d.rhs
case t: Defn.Class => Some(t.templ)
Expand All @@ -348,6 +348,7 @@ object TreeOps {
tree match {
case d: Decl.Def => Some(d.decltpe)
case d: Defn.Def => d.decltpe
case d: Defn.Macro => d.decltpe
case d: Defn.Given => d.templ.inits.headOption.map(_.tpe)
case d: Defn.GivenAlias => Some(d.decltpe)
case d: Decl.Given => Some(d.decltpe)
Expand Down Expand Up @@ -720,8 +721,9 @@ object TreeOps {
case _: Defn.Trait => DanglingParentheses.Exclude.`trait`
case _: Defn.Enum => DanglingParentheses.Exclude.`enum`
case _: Defn.ExtensionGroup => DanglingParentheses.Exclude.`extension`
case _: Defn.Def => DanglingParentheses.Exclude.`def`
case _: Defn.Given | _: Defn.GivenAlias =>
case _: Decl.Def | _: Defn.Def | _: Defn.Macro =>
DanglingParentheses.Exclude.`def`
case _: Decl.Given | _: Defn.Given | _: Defn.GivenAlias =>
DanglingParentheses.Exclude.`given`
case _ => null
}
Expand Down

0 comments on commit dce9e5b

Please sign in to comment.