@@ -58,6 +58,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
58
58
try op finally myCtx = savedCtx
59
59
}
60
60
61
+ inline def inContextBracket (inline op : Text ): Text =
62
+ val savedCtx = myCtx
63
+ try op finally myCtx = savedCtx
64
+
61
65
def withoutPos (op : => Text ): Text = {
62
66
val savedPrintPos = printPos
63
67
printPos = false
@@ -308,7 +312,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
308
312
blockText(block.stats :+ block.expr)
309
313
310
314
protected def blockText [T >: Untyped ](trees : List [Tree [T ]]): Text =
311
- (" {" ~ toText(trees, " \n " ) ~ " }" ).close
315
+ inContextBracket {
316
+ (" {" ~ toText(trees, " \n " ) ~ " }" ).close
317
+ }
312
318
313
319
protected def typeApplyText [T >: Untyped ](tree : TypeApply [T ]): Text = {
314
320
val funText = toTextLocal(tree.fun)
@@ -598,7 +604,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
598
604
typeDefText(tparamsTxt, optText(rhs)(" = " ~ _))
599
605
}
600
606
recur(rhs, " " , true )
601
- case Import (expr, selectors) =>
607
+ case tree @ Import (expr, selectors) =>
608
+ myCtx = myCtx.importContext(tree, tree.symbol)
602
609
keywordText(" import " ) ~ importText(expr, selectors)
603
610
case Export (expr, selectors) =>
604
611
keywordText(" export " ) ~ importText(expr, selectors)
@@ -965,7 +972,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
965
972
}
966
973
else impl.body
967
974
968
- val bodyText = " {" ~~ selfText ~ toTextGlobal(primaryConstrs ::: body, " \n " ) ~ " }"
975
+ val bodyText = inContextBracket(
976
+ " {" ~~ selfText ~ toTextGlobal(primaryConstrs ::: body, " \n " ) ~ " }" )
969
977
970
978
prefix ~
971
979
keywordText(" extends" ).provided(! ofNew && impl.parents.nonEmpty) ~~ parentsText ~
@@ -988,7 +996,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
988
996
protected def packageDefText (tree : PackageDef ): Text = {
989
997
val statsText = tree.stats match {
990
998
case (pdef : PackageDef ) :: Nil => toText(pdef)
991
- case _ => toTextGlobal(tree.stats, " \n " )
999
+ case _ => inContextBracket( toTextGlobal(tree.stats, " \n " ) )
992
1000
}
993
1001
val bodyText =
994
1002
if (currentPrecedence == TopLevelPrec ) " \n " ~ statsText else " {" ~ statsText ~ " }"
0 commit comments