1
1
package dotty .tools .scaladoc
2
2
package tasty
3
3
4
- import scala .jdk . CollectionConverters . _
5
-
6
- import scala .quoted ._
4
+ import scala .annotation . *
5
+ import scala . jdk . CollectionConverters . *
6
+ import scala .quoted .*
7
7
import scala .util .control .NonFatal
8
8
9
- import NameNormalizer ._
10
- import SyntheticsSupport ._
9
+ import NameNormalizer .*
10
+ import SyntheticsSupport .*
11
11
12
12
trait TypesSupport :
13
13
self : TastyParser =>
@@ -155,24 +155,25 @@ trait TypesSupport:
155
155
.reduceLeftOption((acc : SSignature , elem : SSignature ) => acc ++ plain(" , " ).l ++ elem).getOrElse(List ())
156
156
++ plain(" )" ).l
157
157
158
- def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature = ( info match {
158
+ def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature =
159
+ val ssig = info match
159
160
case m : MethodType => {
160
161
val paramList = getParamList(m)
161
162
keyword(" def " ).l ++ plain(name).l ++ polyTyped ++ paramList ++ plain(" : " ).l ++ inner(m.resType, skipThisTypePrefix)
162
163
}
163
- case t : PolyType => {
164
+ case t : PolyType =>
164
165
val paramBounds = getParamBounds(t)
165
- val parsedMethod = parseRefinedElem(name, t.resType)
166
- if (! paramBounds.isEmpty){
166
+ if ! paramBounds.isEmpty then
167
167
parseRefinedElem(name, t.resType, plain(" [" ).l ++ paramBounds ++ plain(" ]" ).l)
168
- } else parseRefinedElem(name, t.resType)
169
- }
168
+ else
169
+ parseRefinedElem(name, t.resType, polyTyped = Nil )
170
170
case ByNameType (tp) => keyword(" def " ).l ++ plain(s " $name: " ).l ++ inner(tp, skipThisTypePrefix)
171
171
case t : TypeBounds => keyword(" type " ).l ++ plain(name).l ++ inner(t, skipThisTypePrefix)
172
172
case t : TypeRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
173
173
case t : TermRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
174
174
case other => noSupported(s " Not supported type in refinement $info" )
175
- } ) ++ plain(" ; " ).l
175
+
176
+ ssig ++ plain(" ; " ).l
176
177
177
178
def parsePolyFunction (info : TypeRepr ): SSignature = info match {
178
179
case t : PolyType =>
@@ -253,6 +254,7 @@ trait TypesSupport:
253
254
}) ++ plain(" ]" ).l
254
255
255
256
case tp @ TypeRef (qual, typeName) =>
257
+ inline def wrapping = shouldWrapInParens(inner = qual, outer = tp, isLeft = true )
256
258
qual match {
257
259
case r : RecursiveThis => tpe(s " this. $typeName" ).l
258
260
case ThisType (tr) =>
@@ -269,23 +271,28 @@ trait TypesSupport:
269
271
if skipPrefix(qual, elideThis, originalOwner, skipThisTypePrefix) then
270
272
tpe(tp.typeSymbol)
271
273
else
272
- val sig = inParens(inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
273
- sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
274
+ val sig = inParens(
275
+ inner(qual, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true ), wrapping)
276
+ sig
277
+ ++ plain(" ." ).l
278
+ ++ tpe(tp.typeSymbol)
274
279
275
280
case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
276
281
tpe(tp.typeSymbol)
277
282
case _ : TermRef | _ : ParamRef =>
278
283
val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
279
- inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l ++ suffix
284
+ inner(qual, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true )
285
+ ++ plain(" ." ).l
286
+ ++ suffix
280
287
case _ =>
281
- val sig = inParens(inner(qual, skipThisTypePrefix), shouldWrapInParens(qual, tp, true ) )
288
+ val sig = inParens(inner(qual, skipThisTypePrefix), wrapping )
282
289
sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
283
290
}
284
291
285
292
case tr @ TermRef (qual, typeName) =>
286
293
val prefix = qual match
287
294
case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) => Nil
288
- case tp => inner(tp, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l
295
+ case tp => inner(tp, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true ) ++ plain(" ." ).l
289
296
val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
290
297
val typeSig = tr.termSymbol.tree match
291
298
case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -304,9 +311,17 @@ trait TypesSupport:
304
311
val spaces = " " * (indent)
305
312
val casesTexts = cases.flatMap {
306
313
case MatchCase (from, to) =>
307
- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
314
+ keyword(caseSpaces + " case " ).l
315
+ ++ inner(from, skipThisTypePrefix)
316
+ ++ keyword(" => " ).l
317
+ ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix)
318
+ ++ plain(" \n " ).l
308
319
case TypeLambda (_, _, MatchCase (from, to)) =>
309
- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
320
+ keyword(caseSpaces + " case " ).l
321
+ ++ inner(from, skipThisTypePrefix)
322
+ ++ keyword(" => " ).l
323
+ ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix)
324
+ ++ plain(" \n " ).l
310
325
}
311
326
inner(sc, skipThisTypePrefix) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
312
327
0 commit comments