@@ -101,7 +101,12 @@ trait TypesSupport:
101
101
case ByNameType (tpe) => keyword(" => " ) :: inner(tpe)
102
102
case ConstantType (constant) =>
103
103
plain(constant.show).l
104
- case ThisType (tpe) => inner(tpe)
104
+ case ThisType (tpe) =>
105
+ val prefix = findSupertype(elideThis, tpe.typeSymbol) match
106
+ case Some (_) => Nil
107
+ case None => inner(tpe) ++ plain(" ." ).l
108
+ val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
109
+ prefix ++ keyword(" this" ).l ++ suffix
105
110
case AnnotatedType (AppliedType (_, Seq (tpe)), annotation) if isRepeatedAnnotation(annotation) =>
106
111
inner(tpe) :+ plain(" *" )
107
112
case AppliedType (repeatedClass, Seq (tpe)) if isRepeated(repeatedClass) =>
@@ -220,10 +225,6 @@ trait TypesSupport:
220
225
}) ++ plain(" ]" ).l
221
226
222
227
case tp @ TypeRef (qual, typeName) =>
223
- def defaultSignature () =
224
- val suffix = keyword(" #" ).l ++ tpe(tp.typeSymbol)
225
- inParens(inner(qual), shouldWrapInParens(qual, tp, true )) ++ suffix
226
-
227
228
qual match {
228
229
case r : RecursiveThis => tpe(s " this. $typeName" ).l
229
230
case t if skipPrefix(t, elideThis) =>
@@ -232,21 +233,23 @@ trait TypesSupport:
232
233
val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
233
234
inner(qual)(using skipTypeSuffix = true ) ++ plain(" ." ).l ++ suffix
234
235
case ThisType (tr) =>
235
- import dotty .tools .scaladoc .tasty .SymOps .isHiddenByVisibility
236
-
237
- val supertype = getSupertypes(elideThis).filterNot((s, t) => s.isHiddenByVisibility).find((s, t) => s == tr.typeSymbol)
238
- supertype match
236
+ findSupertype(elideThis, tr.typeSymbol) match
239
237
case Some ((sym, AppliedType (tr2, args))) =>
240
238
sym.tree.asInstanceOf [ClassDef ].constructor.paramss.headOption match
241
239
case Some (TypeParamClause (tpc)) =>
242
240
tpc.zip(args).collectFirst {
243
241
case (TypeDef (name, _), arg) if name == typeName => arg
244
242
} match
245
243
case Some (tr) => inner(tr)
246
- case _ => defaultSignature()
247
- case _ => defaultSignature()
248
- case _ => defaultSignature()
249
- case _ => defaultSignature()
244
+ case None => tpe(tp.typeSymbol)
245
+ case _ => tpe(tp.typeSymbol)
246
+ case Some (_) => tpe(tp.typeSymbol)
247
+ case None =>
248
+ val sig = inParens(inner(qual)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
249
+ sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
250
+ case _ =>
251
+ val sig = inParens(inner(qual), shouldWrapInParens(qual, tp, true ))
252
+ sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
250
253
}
251
254
252
255
case tr @ TermRef (qual, typeName) =>
@@ -326,6 +329,9 @@ trait TypesSupport:
326
329
regularTypeBounds(low, high)
327
330
case _ => regularTypeBounds(low, high)
328
331
332
+ private def findSupertype (using Quotes )(c : reflect.ClassDef , sym : reflect.Symbol ) =
333
+ getSupertypes(c).find((s, t) => s == sym)
334
+
329
335
private def skipPrefix (using Quotes )(tr : reflect.TypeRepr , elideThis : reflect.ClassDef ) =
330
336
import reflect ._
331
337
0 commit comments