@@ -32,7 +32,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
32
32
else {
33
33
if (ctx.toTextRecursions >= maxToTextRecursions)
34
34
recursionLimitExceeded()
35
- " ..."
35
+ " ..." .toText
36
36
}
37
37
38
38
protected def recursionLimitExceeded () = {
@@ -138,7 +138,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
138
138
else
139
139
toTextPrefix(tp.prefix) ~ selectionString(tp)
140
140
case tp : TermParamRef =>
141
- ParamRefNameString (tp) ~ " .type"
141
+ ParamRefNameString (tp) ~ " .type" .toText
142
142
case tp : TypeParamRef =>
143
143
ParamRefNameString (tp) ~ lambdaHash(tp.binder)
144
144
case tp : SingletonType =>
@@ -152,21 +152,21 @@ class PlainPrinter(_ctx: Context) extends Printer {
152
152
case tp : RecType =>
153
153
try {
154
154
openRecs = tp :: openRecs
155
- " {" ~ selfRecName(openRecs.length) ~ " => " ~ toTextGlobal(tp.parent) ~ " }"
155
+ " {" ~ selfRecName(openRecs.length).toText ~ " => " ~ toTextGlobal(tp.parent) ~ " }"
156
156
}
157
157
finally openRecs = openRecs.tail
158
158
case AndType (tp1, tp2) =>
159
159
changePrec(AndPrec ) { toText(tp1) ~ " & " ~ toText(tp2) }
160
160
case OrType (tp1, tp2) =>
161
161
changePrec(OrPrec ) { toText(tp1) ~ " | " ~ toText(tp2) }
162
162
case tp : ErrorType =>
163
- s " <error ${tp.msg.msg}> "
163
+ s " <error ${tp.msg.msg}> " .toText
164
164
case tp : WildcardType =>
165
- if (tp.optBounds.exists) " (?" ~ toTextRHS(tp.bounds) ~ " )" else " ?"
165
+ if (tp.optBounds.exists) " (?" ~ toTextRHS(tp.bounds) ~ " )" else " ?" .toText
166
166
case NoType =>
167
- " <notype>"
167
+ " <notype>" .toText
168
168
case NoPrefix =>
169
- " <noprefix>"
169
+ " <noprefix>" .toText
170
170
case tp : MethodType =>
171
171
changePrec(GlobalPrec ) {
172
172
(if (tp.isImplicitMethod) " (implicit " else " (" ) ~ paramsText(tp) ~
@@ -222,10 +222,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
222
222
223
223
/** If -uniqid is set, the hashcode of the lambda type, after a # */
224
224
protected def lambdaHash (pt : LambdaType ): Text =
225
- if (ctx.settings.uniqid.value)
225
+ ( if (ctx.settings.uniqid.value)
226
226
try " #" + pt.hashCode
227
227
catch { case ex : NullPointerException => " " }
228
- else " "
228
+ else " " ).toText
229
229
230
230
/** If -uniqid is set, the unique id of symbol, after a # */
231
231
protected def idString (sym : Symbol ): String =
@@ -259,19 +259,19 @@ class PlainPrinter(_ctx: Context) extends Printer {
259
259
case tp : TermRef =>
260
260
toTextPrefix(tp.prefix) ~ selectionString(tp)
261
261
case tp : ThisType =>
262
- nameString(tp.cls) + " .this"
262
+ ( nameString(tp.cls) + " .this" ).toText
263
263
case SuperType (thistpe : SingletonType , _) =>
264
264
toTextRef(thistpe).map(_.replaceAll(""" \bthis$""" , " super" ))
265
265
case SuperType (thistpe, _) =>
266
266
" Super(" ~ toTextGlobal(thistpe) ~ " )"
267
267
case tp @ ConstantType (value) =>
268
268
toText(value)
269
269
case pref : TermParamRef =>
270
- nameString(pref.binder.paramNames(pref.paramNum))
270
+ nameString(pref.binder.paramNames(pref.paramNum)).toText
271
271
case tp : RecThis =>
272
272
val idx = openRecs.reverse.indexOf(tp.binder)
273
- if (idx >= 0 ) selfRecName(idx + 1 )
274
- else " {...}.this" // TODO move underlying type to an addendum, e.g. ... z3 ... where z3: ...
273
+ ( if (idx >= 0 ) selfRecName(idx + 1 )
274
+ else " {...}.this" ).toText // TODO move underlying type to an addendum, e.g. ... z3 ... where z3: ...
275
275
case tp : SkolemType =>
276
276
if (homogenizedView) toText(tp.info) else toText(tp.repr)
277
277
}
@@ -280,7 +280,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
280
280
/** The string representation of this type used as a prefix */
281
281
protected def toTextPrefix (tp : Type ): Text = controlled {
282
282
homogenize(tp) match {
283
- case NoPrefix => " "
283
+ case NoPrefix => " " .toText
284
284
case tp : SingletonType => toTextRef(tp) ~ " ."
285
285
case tp => trimPrefix(toTextLocal(tp)) ~ " #"
286
286
}
@@ -297,7 +297,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
297
297
*/
298
298
protected def toTextRHS (optType : Option [Type ]): Text = optType match {
299
299
case Some (tp) => toTextRHS(tp)
300
- case None => " ?"
300
+ case None => " ?" .toText
301
301
}
302
302
303
303
/** String representation of a definition's type following its name */
@@ -315,7 +315,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
315
315
if (tparams.isEmpty) Text () else (" [" ~ dclsText(tparams) ~ " ]" ).close
316
316
val selfText : Text = selfInfo match {
317
317
case NoType => Text ()
318
- case sym : Symbol if ! sym.isCompleted => " this: ? =>"
318
+ case sym : Symbol if ! sym.isCompleted => " this: ? =>" .toText
319
319
case _ => " this: " ~ atPrec(InfixPrec ) { toText(tp.selfType) } ~ " =>"
320
320
}
321
321
val trueDecls = otherDecls.filterNot(treatAsTypeArg)
@@ -379,7 +379,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
379
379
380
380
/** String representation of symbol's flags */
381
381
protected def toTextFlags (sym : Symbol ): Text =
382
- Text (sym.flagsUNSAFE.flagStrings map stringToText , " " )
382
+ Text (sym.flagsUNSAFE.flagStrings. map(_.toText) , " " )
383
383
384
384
/** String representation of symbol's variance or "" if not applicable */
385
385
protected def varianceString (sym : Symbol ): String = varianceString(sym.variance)
@@ -398,17 +398,17 @@ class PlainPrinter(_ctx: Context) extends Printer {
398
398
399
399
private def dclTextWithInfo (sym : Symbol , info : Option [Type ]): Text =
400
400
(toTextFlags(sym) ~~ keyString(sym) ~~
401
- (varianceString(sym) ~ nameString(sym)) ~ toTextRHS(info)).close
401
+ (varianceString(sym) ~ nameString(sym).toText ) ~ toTextRHS(info)).close
402
402
403
403
def toText (sym : Symbol ): Text =
404
- (kindString(sym) ~~ {
404
+ (kindString(sym).toText ~~ {
405
405
if (sym.isAnonymousClass) toText(sym.info.parents, " with " ) ~ " {...}"
406
- else if (hasMeaninglessName(sym)) simpleNameString(sym.owner) + idString(sym)
407
- else nameString(sym)
406
+ else if (hasMeaninglessName(sym)) ( simpleNameString(sym.owner) + idString(sym)).toText
407
+ else nameString(sym).toText
408
408
}).close
409
409
410
410
def locationText (sym : Symbol ): Text =
411
- if (! sym.exists) " "
411
+ if (! sym.exists) " " .toText
412
412
else {
413
413
val ownr = sym.effectiveOwner
414
414
if (ownr.isClass && ! isEmptyPrefix(ownr)) " in " ~ toText(ownr) else Text ()
@@ -418,18 +418,18 @@ class PlainPrinter(_ctx: Context) extends Printer {
418
418
(toText(sym) ~ locationText(sym)).close
419
419
420
420
def extendedLocationText (sym : Symbol ): Text =
421
- if (! sym.exists) " "
421
+ if (! sym.exists) " " .toText
422
422
else {
423
423
def recur (ownr : Symbol , innerLocation : String ): Text = {
424
424
def nextOuter (innerKind : String ): Text =
425
425
recur(ownr.effectiveOwner,
426
426
if (! innerLocation.isEmpty) innerLocation
427
427
else s " in an anonymous $innerKind" )
428
428
def showLocation (ownr : Symbol , where : String ): Text =
429
- innerLocation ~ " " ~ where ~ " " ~ toText(ownr)
429
+ innerLocation ~ " " .toText ~ where ~ " " ~ toText(ownr)
430
430
if (ownr.isAnonymousClass) nextOuter(" class" )
431
431
else if (ownr.isAnonymousFunction) nextOuter(" function" )
432
- else if (isEmptyPrefix(ownr)) " "
432
+ else if (isEmptyPrefix(ownr)) " " .toText
433
433
else if (ownr.isLocalDummy) showLocation(ownr.owner, " locally defined in" )
434
434
else if (ownr.isTerm && ! ownr.is(Module | Method )) showLocation(ownr, " in the initalizer of" )
435
435
else showLocation(ownr, " in" )
@@ -461,7 +461,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
461
461
case _ => literalText(String .valueOf(const.value))
462
462
}
463
463
464
- def toText (annot : Annotation ): Text = s " @ ${annot.symbol.name}" // for now
464
+ def toText (annot : Annotation ): Text = s " @ ${annot.symbol.name}" .toText // for now
465
465
466
466
protected def escapedString (str : String ): String = str flatMap escapedChar
467
467
@@ -476,9 +476,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
476
476
def toTextElem (elem : Any ): Text = elem match {
477
477
case elem : Showable => elem.toText(this )
478
478
case elem : List [_] => " List(" ~ Text (elem map toTextElem, " ," ) ~ " )"
479
- case elem => elem.toString
479
+ case elem => elem.toString.toText
480
480
}
481
- val nodeName = node.productPrefix
481
+ val nodeName = node.productPrefix.toText
482
482
val elems =
483
483
Text (node.productIterator.map(toTextElem).toList, " , " )
484
484
val tpSuffix =
@@ -498,13 +498,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
498
498
" SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)
499
499
case result : SearchFailure =>
500
500
result.reason match {
501
- case _ : NoMatchingImplicits => " No Matching Implicit"
502
- case _ : DivergingImplicit => " Diverging Implicit"
503
- case _ : ShadowedImplicit => " Shadowed Implicit"
501
+ case _ : NoMatchingImplicits => " No Matching Implicit" .toText
502
+ case _ : DivergingImplicit => " Diverging Implicit" .toText
503
+ case _ : ShadowedImplicit => " Shadowed Implicit" .toText
504
504
case result : AmbiguousImplicits =>
505
505
" Ambiguous Implicit: " ~ toText(result.alt1.ref) ~ " and " ~ toText(result.alt2.ref)
506
506
case _ =>
507
- " ?Unknown Implicit Result?" + result.getClass
507
+ s " ?Unknown Implicit Result? ${ result.getClass} " .toText
508
508
}
509
509
}
510
510
@@ -515,7 +515,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
515
515
case Ident (name) :: Nil => name.show
516
516
case _ => " {...}"
517
517
}
518
- s " import $exprStr. $selectorStr"
518
+ s " import $exprStr. $selectorStr" .toText
519
519
}
520
520
521
521
@@ -533,15 +533,16 @@ class PlainPrinter(_ctx: Context) extends Printer {
533
533
def plain = this
534
534
535
535
protected def keywordStr (text : String ): String = coloredStr(text, SyntaxHighlighting .KeywordColor )
536
- protected def keywordText (text : String ): Text = coloredStr (text, SyntaxHighlighting . KeywordColor )
536
+ protected def keywordText (text : String ): Text = keywordStr (text).toText
537
537
protected def valDefText (text : Text ): Text = coloredText(text, SyntaxHighlighting .ValDefColor )
538
538
protected def typeText (text : Text ): Text = coloredText(text, SyntaxHighlighting .TypeColor )
539
539
protected def literalText (text : Text ): Text = coloredText(text, SyntaxHighlighting .LiteralColor )
540
+ protected def literalText (string : String ): Text = literalText(string.toText)
540
541
protected def stringText (text : Text ): Text = coloredText(text, SyntaxHighlighting .StringColor )
542
+ protected def stringText (string : String ): Text = stringText(string.toText)
541
543
542
544
private def coloredStr (text : String , color : String ): String =
543
545
if (ctx.useColors) color + text + SyntaxHighlighting .NoColor else text
544
546
private def coloredText (text : Text , color : String ): Text =
545
547
if (ctx.useColors) color ~ text ~ SyntaxHighlighting .NoColor else text
546
548
}
547
-
0 commit comments