11package dotty .tools .scaladoc
22package tasty
33
4- import scala .jdk . CollectionConverters . _
5-
6- import scala .quoted ._
4+ import scala .annotation . *
5+ import scala . jdk . CollectionConverters . *
6+ import scala .quoted .*
77import scala .util .control .NonFatal
88
9- import NameNormalizer ._
10- import SyntheticsSupport ._
9+ import NameNormalizer .*
10+ import SyntheticsSupport .*
1111
1212trait TypesSupport :
1313 self : TastyParser =>
@@ -155,24 +155,25 @@ trait TypesSupport:
155155 .reduceLeftOption((acc : SSignature , elem : SSignature ) => acc ++ plain(" , " ).l ++ elem).getOrElse(List ())
156156 ++ plain(" )" ).l
157157
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
159160 case m : MethodType => {
160161 val paramList = getParamList(m)
161162 keyword(" def " ).l ++ plain(name).l ++ polyTyped ++ paramList ++ plain(" : " ).l ++ inner(m.resType, skipThisTypePrefix)
162163 }
163- case t : PolyType => {
164+ case t : PolyType =>
164165 val paramBounds = getParamBounds(t)
165- val parsedMethod = parseRefinedElem(name, t.resType)
166- if (! paramBounds.isEmpty){
166+ if ! paramBounds.isEmpty then
167167 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 )
170170 case ByNameType (tp) => keyword(" def " ).l ++ plain(s " $name: " ).l ++ inner(tp, skipThisTypePrefix)
171171 case t : TypeBounds => keyword(" type " ).l ++ plain(name).l ++ inner(t, skipThisTypePrefix)
172172 case t : TypeRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
173173 case t : TermRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
174174 case other => noSupported(s " Not supported type in refinement $info" )
175- } ) ++ plain(" ; " ).l
175+
176+ ssig ++ plain(" ; " ).l
176177
177178 def parsePolyFunction (info : TypeRepr ): SSignature = info match {
178179 case t : PolyType =>
@@ -253,6 +254,7 @@ trait TypesSupport:
253254 }) ++ plain(" ]" ).l
254255
255256 case tp @ TypeRef (qual, typeName) =>
257+ inline def wrapping = shouldWrapInParens(inner = qual, outer = tp, isLeft = true )
256258 qual match {
257259 case r : RecursiveThis => tpe(s " this. $typeName" ).l
258260 case ThisType (tr) =>
@@ -269,23 +271,28 @@ trait TypesSupport:
269271 if skipPrefix(qual, elideThis, originalOwner, skipThisTypePrefix) then
270272 tpe(tp.typeSymbol)
271273 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)
274279
275280 case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
276281 tpe(tp.typeSymbol)
277282 case _ : TermRef | _ : ParamRef =>
278283 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
280287 case _ =>
281- val sig = inParens(inner(qual, skipThisTypePrefix), shouldWrapInParens(qual, tp, true ) )
288+ val sig = inParens(inner(qual, skipThisTypePrefix), wrapping )
282289 sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
283290 }
284291
285292 case tr @ TermRef (qual, typeName) =>
286293 val prefix = qual match
287294 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
289296 val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
290297 val typeSig = tr.termSymbol.tree match
291298 case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -304,9 +311,17 @@ trait TypesSupport:
304311 val spaces = " " * (indent)
305312 val casesTexts = cases.flatMap {
306313 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
308319 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
310325 }
311326 inner(sc, skipThisTypePrefix) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
312327
0 commit comments