Skip to content

Commit 5bb7c97

Browse files
committed
Add type params to type aliases
1 parent a0f47a0 commit 5bb7c97

File tree

7 files changed

+35
-17
lines changed

7 files changed

+35
-17
lines changed

doc-tool/resources/_layouts/api-page.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,25 @@ <h1 class="section {% if entity.hasVisibleMembers == false %}empty{% endif %}">
134134
{% endfor %}
135135
{% endif %}
136136

137-
{% if member.kind == "type" and member.alias != null %}
137+
{% if member.kind == "type" %}
138+
{% for tparam in member.typeParams %}
139+
{% if forloop.first %}
140+
<span class="no-left">[</span>
141+
{% endif %}
142+
{% if forloop.last %}
143+
<span class="no-left">{{ tparam }}</span>
144+
<span class="no-left">]</span>
145+
{% else %}
146+
<span class="no-left">{{ tparam }}, </span>
147+
{% endif %}
148+
{% endfor %}
149+
{% if member.alias != null %}
138150
<span class="type-alias">
139151
<span class="equals"> = </span>
140152
{% renderRef member.alias %}
141153
</span>
142154
{% endif %}
155+
{% endif %}
143156

144157
{% if member.returnValue %}
145158
<span class="no-left">: {% renderRef member.returnValue %}</span>

doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotc.CompilationUnit
88
import dotc.config.Printers.dottydoc
99
import dotc.core.Contexts.Context
1010
import dotc.core.Comments.ContextDocstrings
11-
import dotc.core.Types.NoType
11+
import dotc.core.Types.{PolyType, NoType}
1212
import dotc.core.Phases.Phase
1313
import dotc.core.Symbols.{ Symbol, NoSymbol }
1414

@@ -92,8 +92,16 @@ class DocASTPhase extends Phase {
9292
val sym = t.symbol
9393
if (sym.is(Flags.Synthetic | Flags.Param))
9494
NonEntity
95-
else
96-
TypeAliasImpl(sym, annotations(sym), flags(t), t.name.show.split("\\$\\$").last, path(sym), alias(t.rhs.tpe))
95+
else {
96+
val tparams = t.rhs.tpe match {
97+
case tp: PolyType => tp.paramRefs.zip(tp.variances).map { case (tp, variance) =>
98+
val varianceSym = if (variance == 1) "+" else if (variance == -1) "-" else ""
99+
varianceSym + tp.paramName.show
100+
}
101+
case _ => Nil
102+
}
103+
TypeAliasImpl(sym, annotations(sym), flags(t), t.name.show.split("\\$\\$").last, path(sym), alias(t.rhs.tpe), tparams)
104+
}
97105

98106
/** trait */
99107
case t @ TypeDef(n, rhs) if t.symbol.is(Flags.Trait) =>

doc-tool/src/dotty/tools/dottydoc/core/transform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ object transform {
9292
t.name,
9393
t.path,
9494
t.alias,
95+
t.typeParams,
9596
t.comment,
9697
t.parent
9798
)

doc-tool/src/dotty/tools/dottydoc/model/JavaConverters.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ object JavaConverters {
189189
"name" -> ent.name,
190190
"path" -> ent.path.asJava,
191191
"alias" -> ent.alias.map(_.asJava).asJava,
192+
"typeParams" -> ent.typeParams.asJava,
192193
"comment" -> ent.comment.map(_.asJava).asJava,
193194
"hasShortenedDocstring" -> ent.hasShortenedDocstring,
194195
"isPrivate" -> ent.isPrivate,

doc-tool/src/dotty/tools/dottydoc/model/entities.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ trait Package extends Entity with Members with SuperTypes {
108108
val kind = "package"
109109
}
110110

111-
trait TypeAlias extends Entity with Modifiers {
111+
trait TypeAlias extends Entity with Modifiers with TypeParams {
112112
val kind = "type"
113113
def alias: Option[Reference]
114114
def isAbstract: Boolean = !alias.isDefined

doc-tool/src/dotty/tools/dottydoc/model/factories.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ package model
44
import comment._
55
import references._
66
import dotty.tools.dotc
7-
import dotc.core.Types._
7+
import dotc.core.Types
8+
import Types._
89
import dotc.core.TypeApplications._
910
import dotc.core.Contexts.Context
1011
import dotc.core.Symbols.{ Symbol, ClassSymbol }
@@ -105,17 +106,8 @@ object factories {
105106
case ci: ClassInfo =>
106107
typeRef(ci.cls.name.show, query = ci.typeSymbol.showFullName)
107108

108-
case tl: PolyType => {
109-
// FIXME: should be handled correctly
110-
// example, in `Option`:
111-
//
112-
// ```scala
113-
// def companion: GenericCompanion[collection.Iterable]
114-
// ```
115-
//
116-
// Becomes: def companion: [+X0] -> collection.Iterable[X0]
117-
typeRef(tl.show + " (not handled)")
118-
}
109+
case tl: PolyType =>
110+
expandTpe(tl.resType)
119111

120112
case OrType(left, right) =>
121113
OrTypeReference(expandTpe(left), expandTpe(right))
@@ -148,6 +140,8 @@ object factories {
148140
prefix + tp.name.show.split("\\$").last
149141
}
150142
.toList
143+
case tp: Types.TypeAlias =>
144+
typeParams(tp.alias.typeSymbol)
151145
case _ =>
152146
Nil
153147
}

doc-tool/src/dotty/tools/dottydoc/model/internal.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ object internal {
3131
name: String,
3232
path: List[String],
3333
alias: Option[Reference],
34+
typeParams: List[String] = Nil,
3435
var comment: Option[Comment] = None,
3536
var parent: Entity = NonEntity
3637
) extends TypeAlias

0 commit comments

Comments
 (0)