Skip to content

Commit b13135f

Browse files
committed
Hello retains
1 parent 79a3ce1 commit b13135f

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package dotty.tools.scaladoc.cc
2+
3+
import scala.quoted._
4+
5+
object CaptureDefs:
6+
/** The name of the `retains` annotation. */
7+
val RetainsName: String = "scala.annotation.retains"
8+
9+
/** The name of the `retainsCap` annotation. */
10+
val RetainsCapName: String = "scala.annotation.retainsCap"
11+
12+
/** The name of the `retainsByName` annotation. */
13+
val RetainsByNameName: String = "scala.annotation.retainsByName"
14+
15+
def retains(using qctx: Quotes) = qctx.reflect.Symbol.requiredClass(RetainsName)
16+
def retainsCap(using qctx: Quotes) = qctx.reflect.Symbol.requiredClass(RetainsCapName)
17+
def retainsByName(using qctx: Quotes) = qctx.reflect.Symbol.requiredClass(RetainsByNameName)
18+
end CaptureDefs
19+
20+
extension (using qctx: Quotes)(term: qctx.reflect.Term)
21+
22+
/** Is this term a `retains`* annotations from capturing types? */
23+
def isRetains: Boolean =
24+
val sym = term.tpe match
25+
case qctx.reflect.AppliedType(base, _) => base.typeSymbol
26+
case other => other.typeSymbol
27+
sym == CaptureDefs.retains
28+
|| sym == CaptureDefs.retainsCap
29+
|| sym == CaptureDefs.retainsByName

scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import scala.jdk.CollectionConverters._
66
import scala.quoted._
77
import scala.util.control.NonFatal
88

9+
import dotty.tools.scaladoc.cc.*
10+
911
import NameNormalizer._
1012
import SyntheticsSupport._
1113

@@ -112,34 +114,9 @@ trait TypesSupport:
112114
inner(tpe) :+ plain("*")
113115
case AppliedType(repeatedClass, Seq(tpe)) if isRepeated(repeatedClass) =>
114116
inner(tpe) :+ plain("*")
115-
case tp @ AnnotatedType(tpe, annotTerm) =>
116-
val retainsSym = Symbol.requiredClass("_root_.scala.annotation.retains")
117-
val retainsCapSym = Symbol.requiredClass("_root_.scala.annotation.retainsCap")
118-
val retainsByNameSym = Symbol.requiredClass("_root_.scala.annotation.retainsByName")
119-
val retainsSym2 = Symbol.requiredClass("scala.annotation.retains")
120-
val retainsCapSym2 = Symbol.requiredClass("scala.annotation.retainsCap")
121-
val retainsByNameSym2 = Symbol.requiredClass("scala.annotation.retainsByName")
122-
val sym = annotTerm.tpe match
123-
case AppliedType(base, _) => base.typeSymbol
124-
case other => other.typeSymbol
125-
if sym.name.contains("retains") then
126-
println("Annot: " + sym)
127-
println("name: " + sym.fullName)
128-
println("id: " + System.identityHashCode(sym))
129-
println("isClassDef: " + sym.isClassDef)
130-
println("isRetains: " + sym == retainsSym)
131-
println("isRetainsCap: " + sym == retainsCapSym)
132-
println("isRetainsByName: " + sym == retainsByNameSym)
133-
println("isRetains2: " + sym == retainsSym2)
134-
println("isRetainsCap2: " + sym == retainsCapSym2)
135-
println("isRetainsByName2: " + sym == retainsByNameSym2)
136-
println("retainsSym " + retainsSym)
137-
println("retainsSym2 " + retainsSym2)
138-
println("retainsSym.isClassDef " + retainsSym.isClassDef)
139-
println("retainsSym2.isClassDef " + retainsSym2.isClassDef)
140-
println("retainsSym.id " + System.identityHashCode(retainsSym))
141-
println("retainsSym2.id " + System.identityHashCode(retainsSym2))
142-
println()
117+
case AnnotatedType(tpe, annotTerm) if annotTerm.isRetains =>
118+
inner(tpe) :+ plain(" @retains") // FIXME
119+
case AnnotatedType(tpe, _) =>
143120
inner(tpe)
144121
case tl @ TypeLambda(params, paramBounds, AppliedType(tpe, args))
145122
if paramBounds.map(inner).forall(_.isEmpty) && params.zip(args.map(inner).flatten.map(_.name)).forall(_ == _) =>

0 commit comments

Comments
 (0)