1
1
package dotty .tools .dotc
2
2
package printing
3
3
4
- import ast .Trees .{ Untyped , Tree }
5
4
import core ._
6
- import Annotations .Annotation
7
- import Constants .Constant
8
- import Contexts .Context
9
- import Denotations .{ Denotation , MultiDenotation , SingleDenotation }
10
- import Flags ._
11
- import TypeApplications .{ AppliedType , EtaExpansion }
12
- import Names ._
13
- import NameOps ._
14
- import StdNames ._
15
- import Decorators ._
16
- import Scopes .Scope
17
- import Symbols .{ Symbol , ClassSymbol , defn }
18
- import SymDenotations .NoDenotation
19
- import Types ._
20
- import Texts ._
5
+ import Constants .Constant , Contexts .Context , Denotations ._ , Flags ._ , Names ._
6
+ import NameOps ._ , StdNames ._ , Decorators ._ , Scopes .Scope , Types ._ , Texts ._
7
+ import SymDenotations .NoDenotation , Symbols .{ Symbol , ClassSymbol , defn }
21
8
import typer .Implicits .SearchResult
22
9
import typer .ImportInfo
23
10
24
11
class UserFacingPrinter (_ctx : Context ) extends RefinedPrinter (_ctx) {
25
12
26
- private def panic (msg : String ): Nothing = throw new AssertionError (msg)
27
-
28
13
private [this ] def getPkgCls (path : String ) =
29
14
_ctx.requiredPackage(path).moduleClass.asClass
30
15
@@ -45,7 +30,7 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
45
30
def wellKnownPkg (pkgSym : Symbol ) = standardPkg(pkgSym) || wrappedName(pkgSym)
46
31
47
32
override protected def keyString (sym : Symbol ): String = {
48
- val flags = sym.flags
33
+ val flags = sym.flagsUNSAFE
49
34
if (flags is Package ) " "
50
35
else if (sym.isPackageObject) " package object"
51
36
else if (flags.is(Module ) && flags.is(Case )) " case object"
@@ -68,7 +53,7 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
68
53
toText(sym) ~ {
69
54
if (sym.is(Method )) toText(sym.info)
70
55
else if (sym.isClass) " "
71
- else if (sym.isType && sym.info.isInstanceOf [TypeAlias ]) " = " ~~ toText(sym.info)
56
+ else if (sym.isType && sym.info.isInstanceOf [TypeAlias ]) toText(sym.info)
72
57
else if (sym.isType) " "
73
58
else {
74
59
" :" ~~ toText(sym.info)
@@ -78,48 +63,17 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
78
63
override def toText (const : Constant ): Text = Str (const.value.toString)
79
64
80
65
override def toText (tp : Type ): Text = tp match {
81
- case tp : AnnotatedType => toText(tp.tpe) ~~ toText(tp.annot)
82
66
case tp : ConstantType => toText(tp.value)
83
- case tp : TypeAlias => toText(tp.underlying)
84
67
case ExprType (result) => " :" ~~ toText(result)
85
- case TypeBounds (lo, hi) =>
86
- { if (lo != defn.NothingType ) toText(lo) ~~ " >: _" else Str (" _" ) } ~~
87
- { if (hi != defn.AnyType ) " <:" ~~ toText(hi) else Text () }
88
68
case tp : TypeRef => tp.info match {
89
69
case TypeAlias (alias) => toText(alias)
90
70
case _ => toText(tp.info)
91
71
}
92
72
case tp : ParamRef => {
93
- val name = tp.paramName.unexpandedName.invariantName.toString
73
+ val name = ParamRefNameString ( tp.paramName)
94
74
if (tp.isInstanceOf [TermParamRef ]) name ~ " .type"
95
75
else name
96
76
}
97
- case EtaExpansion (tycon) => toText(tycon)
98
- case PolyType (params, res) =>
99
- " [" ~ Fluid (params.map(tl => toText(tl.toArg)).intersperse(Str (" , " ))) ~ " ]" ~ toText(res)
100
- case tp : MethodType => {
101
- def paramText (name : TermName , tp : Type ) = toText(name) ~ " : " ~ toText(tp)
102
- changePrec(GlobalPrec ) {
103
- (if (tp.isImplicit) " (implicit " else " (" ) ~
104
- Text ((tp.paramNames, tp.paramInfos).zipped map paramText, " , " ) ~
105
- (if (tp.resultType.isInstanceOf [MethodType ]) " )" else " ): " ) ~
106
- toText(tp.resultType)
107
- }
108
- }
109
- case AppliedType (tycon, args) => {
110
- def toTextInfixType (tycon : Type , args : List [Type ]): Text = {
111
- // TODO: blatant copy from `RefinedPrinter`
112
- val l :: r :: Nil = args
113
- val isRightAssoc = tycon.typeSymbol.name.endsWith(" :" )
114
- val leftArg = if (isRightAssoc && l.isInfixType) " (" ~ toText(l) ~ " )" else toText(l)
115
- val rightArg = if (! isRightAssoc && r.isInfixType) " (" ~ toText(r) ~ " )" else toText(r)
116
- leftArg ~~ atPrec(DotPrec ) { tycon.toText(this ) } ~~ rightArg
117
- }
118
- if (tp.isInfixType) toTextInfixType(tycon, args)
119
- else {
120
- toText(tycon) ~ " [" ~ Fluid (args.reverse.map(toText).intersperse(Str (" , " ))) ~ " ]"
121
- }
122
- }
123
77
case tp : ClassInfo => {
124
78
if (wellKnownPkg(tp.cls.owner))
125
79
nameString(tp.cls.name)
0 commit comments