@@ -42,6 +42,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
42
42
case _ => false
43
43
}
44
44
45
+ private var printPos = ctx.settings.Yprintpos .value
46
+
45
47
override protected def recursionLimitExceeded () = {}
46
48
47
49
protected val PrintableFlags = (SourceModifierFlags | Label | Module | Local ).toCommonFlags
@@ -156,6 +158,18 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
156
158
def blockText [T >: Untyped ](trees : List [Tree [T ]]): Text =
157
159
(" {" ~ toText(trees, " \n " ) ~ " }" ).close
158
160
161
+ def constrText (tree : untpd.Tree ): Text = toTextLocal(tree).stripPrefix(" new " ) // DD
162
+
163
+ // Would like to override this:
164
+ // But this leads to tasty position tests failing because we read some
165
+ // annotations wihtout positions (curiously, only annootated types in patterns
166
+ // seem to be a problem). A failing test is:
167
+ //
168
+ // test/new/annot.scala
169
+ //
170
+ // override def toText(annot: Annotation): Text =
171
+ // if (annot.tree.isEmpty) annot.toString else constrText(annot.tree)
172
+
159
173
override def toText [T >: Untyped ](tree : Tree [T ]): Text = controlled {
160
174
161
175
import untpd .{modsDeco => _ , _ }
@@ -206,8 +220,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
206
220
case untpd.Function (_, tpt) => " <% " ~ toText(tpt)
207
221
}
208
222
209
- def constrText (tree : untpd.Tree ): Text = toTextLocal(tree).stripPrefix(" new " ) // DD
210
-
211
223
def annotText (tree : untpd.Tree ): Text = " @" ~ constrText(tree) // DD
212
224
213
225
def useSymbol =
@@ -524,11 +536,20 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
524
536
case tp => tp
525
537
}
526
538
if (tree.isType) txt = toText(tp)
527
- else if (! tree.isDef) txt = (" <" ~ txt ~ " :" ~ toText(tp) ~ " >" ).close
539
+ else if (! tree.isDef) {
540
+ val saved = printPos
541
+ printPos = false // disable printPos for types that are not explicitly written
542
+ try txt = (" <" ~ txt ~ " :" ~ toText(tp) ~ " >" ).close
543
+ finally printPos = saved
544
+ }
528
545
}
529
- else if (homogenizedView && tree.isType)
546
+ else if (homogenizedView && tree.isType) {
530
547
txt = toText(tree.typeOpt)
531
- if (ctx.settings.Yprintpos .value && ! tree.isInstanceOf [WithoutTypeOrPos [_]]) {
548
+ if (printPos && false )
549
+ txt = txt ~ " @@" ~
550
+ Text (TypePositions .refPositions(tree.asInstanceOf [tpd.Tree ]).map(x => Str (x.toString)))
551
+ }
552
+ if (printPos && ! tree.isInstanceOf [WithoutTypeOrPos [_]]) {
532
553
val pos =
533
554
if (homogenizedView)
534
555
tree match {
@@ -537,7 +558,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
537
558
case _ => tree.pos.toSynthetic // deserialized position is synthetic
538
559
}
539
560
else tree.pos
540
- val clsStr = " " // DEBUG: if (tree.isType) tree.getClass.toString else ""
561
+ val clsStr = " " // #" + tree.uniqueId // DEBUG: if (tree.isType) tree.getClass.toString else ""
541
562
txt = (txt ~ " @" ~ pos.toString ~ clsStr).close
542
563
}
543
564
tree match {
0 commit comments