Skip to content

Commit ca4333f

Browse files
committed
Add annotations to type parameters
1 parent 40a66c5 commit ca4333f

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tests
2+
3+
package specializedSignature
4+
5+
import scala.{specialized}
6+
7+
trait AdditiveMonoid[@specialized(Int, Long, Float, Double) A]
8+
{
9+
def a: A
10+
= ???
11+
}

scala3doc/src/dotty/dokka/model/api/api.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ case class Parameter(
116116
)
117117

118118
case class TypeParameter(
119+
annotations: Seq[Annotation],
119120
variance: "" | "+" | "-",
120121
name: String,
121122
dri: DRI,

scala3doc/src/dotty/dokka/tasty/BasicSupport.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@ trait BasicSupport:
1515
export SymOps._
1616

1717
def parseAnnotation(annotTerm: Term): Annotation =
18+
import dotty.tools.dotc.ast.Trees.{SeqLiteral}
1819
val dri = annotTerm.tpe.typeSymbol.dri
20+
def inner(t: Term): List[Annotation.AnnotationParameter] = t match {
21+
case i: Ident => List(Annotation.LinkParameter(None, i.tpe.typeSymbol.dri, i.name))
22+
case Typed(term, tpeTree) => inner(term)
23+
case SeqLiteral(args, tpeTree) => args.map(_.asInstanceOf[Term]).flatMap(inner)
24+
case Literal(constant) => List(Annotation.PrimitiveParameter(None, constant.show))
25+
case NamedArg(name, Literal(constant)) => List(Annotation.PrimitiveParameter(Some(name), constant.show))
26+
case x @ Select(qual, name) => List.empty
27+
case other => List(Annotation.UnresolvedParameter(None, other.show))
28+
}
29+
30+
1931
val params = annotTerm match
2032
case Apply(target, appliedWith) => {
21-
appliedWith.flatMap {
22-
case Literal(constant) => Some(Annotation.PrimitiveParameter(None, constant.show))
23-
case NamedArg(name, Literal(constant)) => Some(Annotation.PrimitiveParameter(Some(name), constant.show))
24-
case x @ Select(qual, name) => None
25-
case other => Some(Annotation.UnresolvedParameter(None, other.show))
26-
}
33+
appliedWith.flatMap(inner)
2734
}
2835

2936
Annotation(dri, params)

scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ trait ClassLikeSupport:
395395
else ""
396396

397397
TypeParameter(
398+
argument.symbol.getAnnotations(),
398399
variancePrefix,
399400
argument.symbol.normalizedName,
400401
argument.symbol.dri,

scala3doc/src/dotty/dokka/translators/ScalaSignatureUtils.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ trait SignatureBuilder extends ScalaSignatureUtils {
4848
def annotationsInline(d: Parameter): SignatureBuilder =
4949
d.annotations.foldLeft(this){ (bdr, annotation) => bdr.buildAnnotation(annotation) }
5050

51+
def annotationsInline(t: TypeParameter): SignatureBuilder =
52+
t.annotations.foldLeft(this){ (bdr, annotation) => bdr.buildAnnotation(annotation) }
53+
5154
private def buildAnnotation(a: Annotation): SignatureBuilder =
5255
text("@").driLink(a.dri.location.split('.').last, a.dri).buildAnnotationParams(a).text(" ")
5356

@@ -77,7 +80,7 @@ trait SignatureBuilder extends ScalaSignatureUtils {
7780
text(all.toSignatureString()).text(kind + " ")
7881

7982
def generics(on: Seq[TypeParameter]) = list(on.toList, "[", "]"){ (bdr, e) =>
80-
bdr.text(e.variance).memberName(e.name, e.dri).signature(e.signature)
83+
bdr.annotationsInline(e).text(e.variance).memberName(e.name, e.dri).signature(e.signature)
8184
}
8285

8386
def functionParameters(params: Seq[ParametersList]) =

scala3doc/test/dotty/dokka/SignatureTestCases.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ class ImplicitConversionsTest3 extends SignatureTest(
8282
SignatureTest.all,
8383
sourceFiles = List("implicitConversions2"),
8484
filterFunc = _.toString.endsWith("ClassWithConversionWithProperType.html")
85-
)
85+
)
86+
87+
class SpecializedSignature extends SignatureTest("specializedSignature", SignatureTest.all)

0 commit comments

Comments
 (0)