Skip to content

Commit 4cdcb29

Browse files
bracevacnatsukagami
authored andcommitted
Hello retains
1 parent abdf293 commit 4cdcb29

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

@@ -116,34 +118,9 @@ trait TypesSupport:
116118
inner(tpe, skipThisTypePrefix) :+ plain("*")
117119
case AppliedType(repeatedClass, Seq(tpe)) if isRepeated(repeatedClass) =>
118120
inner(tpe, skipThisTypePrefix) :+ plain("*")
119-
case tp @ AnnotatedType(tpe, annotTerm) =>
120-
val retainsSym = Symbol.requiredClass("_root_.scala.annotation.retains")
121-
val retainsCapSym = Symbol.requiredClass("_root_.scala.annotation.retainsCap")
122-
val retainsByNameSym = Symbol.requiredClass("_root_.scala.annotation.retainsByName")
123-
val retainsSym2 = Symbol.requiredClass("scala.annotation.retains")
124-
val retainsCapSym2 = Symbol.requiredClass("scala.annotation.retainsCap")
125-
val retainsByNameSym2 = Symbol.requiredClass("scala.annotation.retainsByName")
126-
val sym = annotTerm.tpe match
127-
case AppliedType(base, _) => base.typeSymbol
128-
case other => other.typeSymbol
129-
if sym.name.contains("retains") then
130-
println("Annot: " + sym)
131-
println("name: " + sym.fullName)
132-
println("id: " + System.identityHashCode(sym))
133-
println("isClassDef: " + sym.isClassDef)
134-
println("isRetains: " + sym == retainsSym)
135-
println("isRetainsCap: " + sym == retainsCapSym)
136-
println("isRetainsByName: " + sym == retainsByNameSym)
137-
println("isRetains2: " + sym == retainsSym2)
138-
println("isRetainsCap2: " + sym == retainsCapSym2)
139-
println("isRetainsByName2: " + sym == retainsByNameSym2)
140-
println("retainsSym " + retainsSym)
141-
println("retainsSym2 " + retainsSym2)
142-
println("retainsSym.isClassDef " + retainsSym.isClassDef)
143-
println("retainsSym2.isClassDef " + retainsSym2.isClassDef)
144-
println("retainsSym.id " + System.identityHashCode(retainsSym))
145-
println("retainsSym2.id " + System.identityHashCode(retainsSym2))
146-
println()
121+
case AnnotatedType(tpe, annotTerm) if annotTerm.isRetains =>
122+
inner(tpe, skipThisTypePrefix) :+ plain(" @retains") // FIXME
123+
case AnnotatedType(tpe, _) =>
147124
inner(tpe, skipThisTypePrefix)
148125
case tl @ TypeLambda(params, paramBounds, AppliedType(tpe, args))
149126
if paramBounds.forall { case TypeBounds(low, hi) => low.typeSymbol == defn.NothingClass && hi.typeSymbol == defn.AnyClass }

0 commit comments

Comments
 (0)