@@ -16,6 +16,7 @@ import config.Config
16
16
import scala .annotation .switch
17
17
import language .implicitConversions
18
18
19
+ /** Pretty printer used by default with `.show`, generate strings very close to scala source code. */
19
20
class RefinedPrinter (_ctx : Context ) extends PlainPrinter (_ctx) {
20
21
21
22
/** A stack of enclosing DefDef, TypeDef, or ClassDef, or ModuleDefs nodes */
@@ -64,12 +65,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
64
65
65
66
override def toTextRef (tp : SingletonType ): Text = controlled {
66
67
tp match {
67
- case tp : ThisType =>
68
- if (tp.cls.isAnonymousClass) return " this"
69
- if (tp.cls is ModuleClass ) return fullNameString(tp.cls.sourceModule)
68
+ case tp : ThisType if tp.cls.isAnonymousClass =>
69
+ " this"
70
+ case tp : ThisType if tp.cls is ModuleClass =>
71
+ fullNameString(tp.cls.sourceModule)
70
72
case _ =>
73
+ super .toTextRef(tp)
71
74
}
72
- super .toTextRef(tp)
73
75
}
74
76
75
77
override def toTextPrefix (tp : Type ): Text = controlled {
@@ -113,44 +115,46 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
113
115
homogenize(tp) match {
114
116
case AppliedType (tycon, args) =>
115
117
val cls = tycon.typeSymbol
116
- if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ " *"
117
- if (defn.isFunctionClass(cls)) return toTextFunction(args)
118
- if (defn.isTupleClass(cls)) return toTextTuple(args)
119
- return (toTextLocal(tycon) ~ " [" ~ Text (args map argText, " , " ) ~ " ]" ).close
118
+ if (tycon.isRepeatedParam) toTextLocal(args.head) ~ " *"
119
+ else if (defn.isFunctionClass(cls)) toTextFunction(args)
120
+ else if (defn.isTupleClass(cls)) toTextTuple(args)
121
+ else (toTextLocal(tycon) ~ " [" ~ Text (args map argText, " , " ) ~ " ]" ).close
120
122
case tp : TypeRef =>
121
123
val hideType = tp.symbol is AliasPreferred
122
124
if (hideType && ! ctx.phase.erasedTypes && ! tp.symbol.isCompleting) {
123
125
tp.info match {
124
- case TypeAlias (alias) => return toText(alias)
125
- case _ => if (tp.prefix.isInstanceOf [ThisType ]) return nameString(tp.symbol)
126
+ case TypeAlias (alias) => toText(alias)
127
+ case _ if (tp.prefix.isInstanceOf [ThisType ]) => nameString(tp.symbol)
128
+ case _ => super .toText(tp)
126
129
}
127
- }
128
- else if (tp.symbol.isAnonymousClass && ! ctx.settings.uniqid.value)
129
- return toText(tp.info)
130
+ } else if (tp.symbol.isAnonymousClass && ! ctx.settings.uniqid.value)
131
+ toText(tp.info)
132
+ else
133
+ super .toText(tp)
130
134
case ExprType (result) =>
131
- return " => " ~ toText(result)
135
+ " => " ~ toText(result)
132
136
case ErasedValueType (tycon, underlying) =>
133
- return " ErasedValueType(" ~ toText(tycon) ~ " , " ~ toText(underlying) ~ " )"
137
+ " ErasedValueType(" ~ toText(tycon) ~ " , " ~ toText(underlying) ~ " )"
134
138
case tp : ClassInfo =>
135
- return toTextParents(tp.parentsWithArgs) ~ " {...}"
139
+ toTextParents(tp.parentsWithArgs) ~ " {...}"
136
140
case JavaArrayType (elemtp) =>
137
- return toText(elemtp) ~ " []"
141
+ toText(elemtp) ~ " []"
138
142
case tp : SelectionProto =>
139
- return " ?{ " ~ toText(tp.name) ~ (" " provided ! tp.name.decode.last.isLetterOrDigit) ~
143
+ " ?{ " ~ toText(tp.name) ~ (" " provided ! tp.name.decode.last.isLetterOrDigit) ~
140
144
" : " ~ toText(tp.memberProto) ~ " }"
141
145
case tp : ViewProto =>
142
- return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
146
+ toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
143
147
case tp @ FunProto (args, resultType, _) =>
144
148
val argsText = args match {
145
149
case dummyTreeOfType(tp) :: Nil if ! (tp isRef defn.NullClass ) => " null: " ~ toText(tp)
146
150
case _ => toTextGlobal(args, " , " )
147
151
}
148
- return " FunProto(" ~ argsText ~ " ):" ~ toText(resultType)
152
+ " FunProto(" ~ argsText ~ " ):" ~ toText(resultType)
149
153
case tp : IgnoredProto =>
150
- return " ?"
154
+ " ?"
151
155
case _ =>
156
+ super .toText(tp)
152
157
}
153
- super .toText(tp)
154
158
}
155
159
156
160
def blockText [T >: Untyped ](trees : List [Tree [T ]]): Text =
0 commit comments