Skip to content

Commit 5381a3d

Browse files
committed
Refine printing of Export trees
1 parent 70535c8 commit 5381a3d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,20 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
317317
case _ => tree
318318
}
319319

320+
def importText(deleg: Boolean, expr: Tree, selectors: List[Tree]) = {
321+
def selectorText(sel: Tree): Text = sel match {
322+
case Thicket(l :: r :: Nil) => toTextGlobal(l) ~ " => " ~ toTextGlobal(r)
323+
case _: Ident => toTextGlobal(sel)
324+
case TypeBoundsTree(_, tpt) => "for " ~ toTextGlobal(tpt)
325+
}
326+
val selectorsText: Text = selectors match {
327+
case id :: Nil => toText(id)
328+
case _ => "{" ~ Text(selectors map selectorText, ", ") ~ "}"
329+
}
330+
(keywordText("delegate ") provided deleg) ~
331+
toTextLocal(expr) ~ "." ~ selectorsText
332+
}
333+
320334
tree match {
321335
case id: Trees.BackquotedIdent[_] if !homogenizedView =>
322336
"`" ~ toText(id.name) ~ "`"
@@ -499,18 +513,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
499513
typeDefText(tparamsTxt, optText(rhs)(" = " ~ _))
500514
}
501515
recur(rhs, "")
502-
case Import(importImplied, expr, selectors) =>
503-
def selectorText(sel: Tree): Text = sel match {
504-
case Thicket(l :: r :: Nil) => toTextGlobal(l) ~ " => " ~ toTextGlobal(r)
505-
case _: Ident => toTextGlobal(sel)
506-
case TypeBoundsTree(_, tpt) => "for " ~ toTextGlobal(tpt)
507-
}
508-
val selectorsText: Text = selectors match {
509-
case id :: Nil => toText(id)
510-
case _ => "{" ~ Text(selectors map selectorText, ", ") ~ "}"
511-
}
512-
keywordText("import ") ~ (keywordText("delegate ") provided importImplied) ~
513-
toTextLocal(expr) ~ "." ~ selectorsText
516+
case Import(deleg, expr, selectors) =>
517+
keywordText("import ") ~ importText(deleg, expr, selectors)
518+
case Export(deleg, expr, selectors) =>
519+
keywordText("export ") ~ importText(deleg, expr, selectors)
514520
case packageDef: PackageDef =>
515521
packageDefText(packageDef)
516522
case tree: Template =>

0 commit comments

Comments
 (0)