Skip to content

Commit 68d09ac

Browse files
authored
Merge pull request #7686 from dotty-staging/tastydoc-update
Make Tastydoc compile
2 parents debe978 + 362275e commit 68d09ac

File tree

12 files changed

+137
-146
lines changed

12 files changed

+137
-146
lines changed

.gitignore

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,3 @@ community-build/sbt-dotty-sbt
8383

8484
# Vulpix output files
8585
*.check.out
86-
87-
tastydoc/report/report\.aux
88-
89-
tastydoc/report/report\.fdb_latexmk
90-
91-
tastydoc/report/report\.fls
92-
93-
tastydoc/report/report\.synctex\.gz
94-
95-
tastydoc/report/report\.toc
96-
97-
tastydoc/report/report\.out
98-
99-
tastydoc/report/presentation/presentation\.aux
100-
101-
tastydoc/report/presentation/presentation\.fdb_latexmk
102-
103-
tastydoc/report/presentation/presentation\.fls
104-
105-
tastydoc/report/presentation/presentation\.nav
106-
107-
tastydoc/report/presentation/presentation\.out
108-
109-
tastydoc/report/presentation/presentation\.snm
110-
111-
tastydoc/report/presentation/presentation\.synctex\.gz
112-
113-
tastydoc/report/presentation/presentation\.toc
114-
115-
tastydoc/dotty-0\.15\.0-RC1/
116-
117-
tastydoc/report/presentation/presentation\.vrb
118-
119-
tastydoc/dotty-0\.16\.0-RC3/

tastydoc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
documentation/*

tastydoc/src/dotty/tastydoc/DocPrinter.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ class DocPrinter(mutablePackagesMap: scala.collection.mutable.HashMap[String, Em
128128
(if(c.authors.nonEmpty) Md.bold(Md.italics("authors")) + " " + c.authors.mkString(", ") + "\n" else "") +
129129
(if(c.see.nonEmpty) Md.bold(Md.italics("see")) + " " + c.see.mkString(", ") + "\n" else "") +
130130
(if(c.result.isDefined) Md.bold(Md.italics("return")) + " " + c.result.get + "\n" else "") +
131-
(if(c.throws.nonEmpty) c.throws.map((x, y) => Md.bold(Md.italics(x)) + " " + y).mkString("\n") else "") +
132-
(if(c.valueParams.nonEmpty) c.valueParams.map((x, y) => Md.bold(Md.italics(x)) + " " + y).mkString("\n") + "\n" else "") +
133-
(if(c.typeParams.nonEmpty) c.typeParams.map((x, y) => Md.bold(Md.italics(x)) + " " + y).mkString("\n") + "\n" else "") +
131+
(if(c.throws.nonEmpty) c.throws.map { case (x, y) => Md.bold(Md.italics(x)) + " " + y }.mkString("\n") else "") +
132+
(if(c.valueParams.nonEmpty) c.valueParams.map { case (x, y) => Md.bold(Md.italics(x)) + " " + y }.mkString("\n") + "\n" else "") +
133+
(if(c.typeParams.nonEmpty) c.typeParams.map { case (x, y) => Md.bold(Md.italics(x)) + " " + y }.mkString("\n") + "\n" else "") +
134134
(if(c.version.isDefined) Md.bold(Md.italics("version")) + " " + c.version.get + "\n" else "") +
135135
(if(c.since.isDefined) Md.bold(Md.italics("since")) + " " + c.since.get + "\n" else "") +
136136
(if(c.todo.nonEmpty) Md.bold(Md.italics("TODO")) + " " + c.todo.mkString(", ") + "\n" else "") +
@@ -139,9 +139,9 @@ class DocPrinter(mutablePackagesMap: scala.collection.mutable.HashMap[String, Em
139139
(if(c.example.nonEmpty) Md.bold(Md.italics("Example")) + " " + c.example.mkString("\n") + "\n" else "") +
140140
(if(c.constructor.isDefined) Md.bold(Md.italics("Constructor")) + " " + c.constructor.get + "\n" else "") +
141141
(if(c.group.isDefined) Md.bold(Md.italics("Group")) + " " + c.group.get + "\n" else "") +
142-
(if(c.groupDesc.nonEmpty) c.groupDesc.map((x, y) => Md.bold(Md.italics(x)) + " " + y).mkString("\n") else "") +
143-
(if(c.groupNames.nonEmpty) c.groupNames.map((x, y) => Md.bold(Md.italics(x)) + " " + y).mkString("\n") + "\n" else "") +
144-
(if(c.groupPrio.nonEmpty) c.groupPrio.map((x, y) => Md.bold(Md.italics(x)) + " " + y).mkString("\n") + "\n" else "") +
142+
(if(c.groupDesc.nonEmpty) c.groupDesc.map { case (x, y) => Md.bold(Md.italics(x)) + " " + y }.mkString("\n") else "") +
143+
(if(c.groupNames.nonEmpty) c.groupNames.map { case (x, y) => Md.bold(Md.italics(x)) + " " + y }.mkString("\n") + "\n" else "") +
144+
(if(c.groupPrio.nonEmpty) c.groupPrio.map { case (x, y) => Md.bold(Md.italics(x)) + " " + y }.mkString("\n") + "\n" else "") +
145145
(if(c.hideImplicitConversions.nonEmpty) Md.bold(Md.italics("Hide Implicit Conversions")) + " " + c.hideImplicitConversions.mkString(", ") + "\n" else "")
146146
case None => ""
147147
}
@@ -434,4 +434,4 @@ class DocPrinter(mutablePackagesMap: scala.collection.mutable.HashMap[String, Em
434434

435435
case _ =>
436436
}
437-
}
437+
}

tastydoc/src/dotty/tastydoc/TastyExtractor.scala

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import dotty.tastydoc.representations._
88
/** A trait containing useful methods for extracting information from the reflect API */
99
trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentCleaner{
1010
def extractPath(reflect: Reflection)(symbol: reflect.Symbol) : List[String] = {
11-
import reflect._
11+
import reflect.{given, _}
1212

13-
val pathArray = symbol.show(implicitly[reflect.Context].withoutColors).split("\\.")
14-
pathArray.view(0, pathArray.length - 1).toList
13+
val pathArray = symbol.show.split("\\.") // NOTE: this should print w/o colors, inspect afterwards
14+
pathArray.iterator.slice(0, pathArray.length - 1).toList
1515
}
1616

1717
def extractModifiers(reflect: Reflection)(flags: reflect.Flags, privateWithin: Option[reflect.Type], protectedWithin: Option[reflect.Type]) : (List[String], Option[Reference], Option[Reference]) = {
18-
import reflect._
18+
import reflect.{given, _}
1919

2020
(((if(flags.is(Flags.Override)) "override" else "") ::
2121
(if(flags.is(Flags.Private)) "private" else "")::
@@ -40,7 +40,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
4040
}
4141

4242
def extractComments(reflect: Reflection)(comment: Option[reflect.Comment], rep: Representation) : (Map[String, EmulatedPackageRepresentation], String) => Option[Comment] = {
43-
import reflect._
43+
import reflect.{given, _}
4444

4545
comment match {
4646
case Some(com) =>
@@ -58,8 +58,8 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
5858
}
5959
}
6060

61-
def extractClassMembers(reflect: Reflection)(body: List[reflect.Statement], symbol: reflect.ClassDefSymbol, parentRepresentation: Some[Representation]) given (mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) : List[Representation with Modifiers] = {
62-
import reflect._
61+
def extractClassMembers(reflect: Reflection)(body: List[reflect.Statement], symbol: reflect.Symbol, parentRepresentation: Some[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) : List[Representation with Modifiers] = {
62+
import reflect.{given, _}
6363

6464
/** Filter fields which shouldn't be displayed in the doc
6565
*/
@@ -74,14 +74,22 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
7474
!(symbol.owner.name == "Any" && ownerPath == List("scala"))
7575
}
7676

77-
(body.flatMap{
78-
case IsDefDef(_) => None //No definitions, they are appended with symbol.methods below
79-
case IsValDef(_) => None //No val/var, they are appended with symbol.fields below
80-
case IsInlined(_) => None //Inlined aren't desirable members
77+
(body.flatMap {
78+
case _: DefDef => None //No definitions, they are appended with symbol.methods below
79+
case _: ValDef => None //No val/var, they are appended with symbol.fields below
80+
case _: Inlined => None //Inlined aren't desirable members
8181
case x => Some(x)
8282
}.filter(x => filterSymbol(x.symbol)).map(convertToRepresentation(reflect)(_, parentRepresentation)) ++
8383
symbol.methods.filter(x => filterSymbol(x)).map{x => convertToRepresentation(reflect)(x.tree, parentRepresentation)} ++
84-
symbol.fields.filter(x => filterSymbol(x)).flatMap{case reflect.IsValDefSymbol(x) => Some(x) case _ => None}.map{x => convertToRepresentation(reflect)(x.tree, parentRepresentation)}
84+
symbol.fields.filter { x =>
85+
filterSymbol(x)
86+
}.flatMap {
87+
case x if x.isValDef => Some(x)
88+
// case reflect.IsValDefSymbol(x) => Some(x)
89+
case _ => None
90+
}.map { x =>
91+
convertToRepresentation(reflect)(x.tree, parentRepresentation)
92+
}
8593
)
8694
.flatMap{
8795
case r: Representation with Modifiers => Some(r)
@@ -91,11 +99,11 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
9199
}
92100

93101
def extractParents(reflect: Reflection)(parents: List[reflect.Tree]): List[Reference] = {
94-
import reflect._
102+
import reflect.{given, _}
95103

96104
val parentsReferences = parents.map{
97-
case reflect.IsTypeTree(c) => convertTypeToReference(reflect)(c.tpe)
98-
case reflect.IsTerm(c) => convertTypeToReference(reflect)(c.tpe)
105+
case c: TypeTree => convertTypeToReference(reflect)(c.tpe)
106+
case c: Term => convertTypeToReference(reflect)(c.tpe)
99107
case _ => throw Exception("Unhandeld case in parents. Please open an issue.")
100108
}
101109

@@ -110,7 +118,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
110118
* @return (is case, is a trait, is an object, the kind as a String)
111119
*/
112120
def extractKind(reflect: Reflection)(flags: reflect.Flags): (Boolean, Boolean, Boolean, String) = {
113-
import reflect._
121+
import reflect.{given, _}
114122

115123
val isCase = flags.is(reflect.Flags.Case)
116124
val isTrait = flags.is(reflect.Flags.Trait)
@@ -134,8 +142,8 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
134142
(isCase, isTrait, isObject, kind)
135143
}
136144

137-
def extractCompanion(reflect: Reflection)(companionModule: Option[reflect.ValDefSymbol], companionClass: Option[reflect.ClassDefSymbol], companionIsObject: Boolean): Option[CompanionReference] = {
138-
import reflect._
145+
def extractCompanion(reflect: Reflection)(companionModule: Option[reflect.Symbol], companionClass: Option[reflect.Symbol], companionIsObject: Boolean): Option[CompanionReference] = {
146+
import reflect.{given, _}
139147

140148
if(companionIsObject){
141149
companionModule match {
@@ -157,7 +165,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
157165
}
158166

159167
def extractAnnotations(reflect: Reflection)(annots: List[reflect.Term]): List[TypeReference] = {
160-
import reflect._
168+
import reflect.{given, _}
161169

162170
def keepAnnot(label: String, link: String): Boolean = {
163171
!(label == "SourceFile" && link == "/internal") &&
@@ -176,4 +184,4 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
176184
val pidSplit = pidShowNoColor.split("\\.")
177185
(pidSplit.last, pidSplit.init.toList)
178186
}
179-
}
187+
}

tastydoc/src/dotty/tastydoc/TastyTypeConverter.scala

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tastydoc.references._
77
trait TastyTypeConverter {
88

99
def convertTypeOrBoundsToReference(reflect: Reflection)(typeOrBounds: reflect.TypeOrBounds): Reference = {
10-
import reflect._
10+
import reflect.{given, _}
1111

1212
def anyOrNothing(reference: Reference): Boolean = reference match {
1313
case TypeReference("Any", "/scala", _, _) => true
@@ -16,8 +16,8 @@ trait TastyTypeConverter {
1616
}
1717

1818
typeOrBounds match {
19-
case reflect.IsType(tpe) => convertTypeToReference(reflect)(tpe)
20-
case reflect.IsTypeBounds(reflect.TypeBounds(low, hi)) =>
19+
case tpe: Type => convertTypeToReference(reflect)(tpe)
20+
case TypeBounds(low, hi) =>
2121
val lowRef = convertTypeToReference(reflect)(low)
2222
val hiRef = convertTypeToReference(reflect)(hi)
2323
if(hiRef == lowRef){
@@ -30,20 +30,20 @@ trait TastyTypeConverter {
3030
}
3131

3232
def convertTypeToReference(reflect: Reflection)(tp: reflect.Type): Reference = {
33-
import reflect._
33+
import reflect.{given, _}
3434

3535
//Inner method to avoid passing the reflection each time
3636
def inner(tp: reflect.Type): Reference = tp match {
37-
case reflect.Type.IsOrType(reflect.Type.OrType(left, right)) => OrTypeReference(inner(left), inner(right))
38-
case reflect.Type.IsAndType(reflect.Type.AndType(left, right)) => AndTypeReference(inner(left), inner(right))
39-
case reflect.Type.IsByNameType(reflect.Type.ByNameType(tpe)) => ByNameReference(inner(tpe))
40-
case reflect.Type.IsConstantType(reflect.Type.ConstantType(constant)) => ConstantReference(constant.value.toString)
41-
case reflect.Type.IsThisType(reflect.Type.ThisType(tpe)) => inner(tpe)
42-
case reflect.Type.IsAnnotatedType(reflect.Type.AnnotatedType(tpe, _)) => inner(tpe)
43-
case reflect.Type.IsTypeLambda(reflect.Type.TypeLambda(paramNames, paramTypes, resType)) => ConstantReference(tp.show(implicitly[reflect.Context].withoutColors)) //TOFIX
44-
case reflect.Type.IsRefinement(reflect.Type.Refinement(parent, name, info)) =>
37+
case OrType(left, right) => OrTypeReference(inner(left), inner(right))
38+
case AndType(left, right) => AndTypeReference(inner(left), inner(right))
39+
case ByNameType(tpe) => ByNameReference(inner(tpe))
40+
case ConstantType(constant) => ConstantReference(constant.value.toString)
41+
case ThisType(tpe) => inner(tpe)
42+
case AnnotatedType(tpe, _) => inner(tpe)
43+
case TypeLambda(paramNames, paramTypes, resType) => ConstantReference(tp.show) //TOFIX
44+
case Refinement(parent, name, info) =>
4545
val tuple = convertTypeOrBoundsToReference(reflect)(info) match {
46-
case r if (info match {case reflect.IsTypeBounds(info) => true case _ => false}) => ("type", name, r)
46+
case r if (info match {case info: TypeBounds => true case _ => false}) => ("type", name, r)
4747
case r@TypeReference(_, _, _, _) => ("val", name, r)
4848
case ByNameReference(rChild) => ("def", name, rChild)
4949
case r => throw new Exception("Match error in info of Refinement. This should not happen, please open an issue. " + r)
@@ -53,7 +53,7 @@ trait TastyTypeConverter {
5353
RefinedReference(p, ls:+tuple)
5454
case t => RefinedReference(t, List(tuple))
5555
}
56-
case reflect.Type.IsAppliedType(reflect.Type.AppliedType(tpe, typeOrBoundsList)) =>
56+
case AppliedType(tpe, typeOrBoundsList) =>
5757
inner(tpe) match {
5858
case TypeReference(label, link, _, hasOwnFile) =>
5959
if(link == "/scala"){
@@ -70,36 +70,46 @@ trait TastyTypeConverter {
7070
}
7171
case _ => throw Exception("Match error in AppliedType. This should not happen, please open an issue. " + tp)
7272
}
73-
case reflect.Type.IsTypeRef(reflect.Type.TypeRef(typeName, qual)) =>
73+
case tp @ TypeRef(qual, typeName) =>
7474
convertTypeOrBoundsToReference(reflect)(qual) match {
7575
case TypeReference(label, link, xs, _) => TypeReference(typeName, link + "/" + label, xs, true)
7676
case EmptyReference => TypeReference(typeName, "", Nil, true)
77-
case _ => throw Exception("Match error in TypeRef. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(qual))
77+
case _ if tp.typeSymbol.exists =>
78+
tp.typeSymbol match {
79+
// NOTE: Only TypeRefs can reference ClassDefSymbols
80+
case sym if sym.isClassDef => //Need to be split because these types have their own file
81+
convertTypeOrBoundsToReference(reflect)(qual) match {
82+
case TypeReference(label, link, xs, _) => TypeReference(sym.name, link + "/" + label, xs, true)
83+
case EmptyReference if sym.name == "<root>" | sym.name == "_root_" => EmptyReference
84+
case EmptyReference => TypeReference(sym.name, "", Nil, true)
85+
case _ => throw Exception("Match error in SymRef/TypeOrBounds/ClassDef. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(qual))
86+
}
87+
88+
// NOTE: This branch handles packages, which are now TypeRefs
89+
case sym if sym.isTerm || sym.isTypeDef =>
90+
convertTypeOrBoundsToReference(reflect)(qual) match {
91+
case TypeReference(label, link, xs, _) => TypeReference(sym.name, link + "/" + label, xs)
92+
case EmptyReference if sym.name == "<root>" | sym.name == "_root_" => EmptyReference
93+
case EmptyReference => TypeReference(sym.name, "", Nil)
94+
case _ => throw Exception("Match error in SymRef/TypeOrBounds/Other. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(qual))
95+
}
96+
case sym => throw Exception("Match error in SymRef. This should not happen, please open an issue. " + sym)
97+
}
98+
case _ =>
99+
throw Exception("Match error in TypeRef. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(qual))
78100
}
79-
case reflect.Type.IsTermRef(reflect.Type.TermRef(typeName, qual)) =>
101+
case TermRef(qual, typeName) =>
80102
convertTypeOrBoundsToReference(reflect)(qual) match {
81103
case TypeReference(label, link, xs, _) => TypeReference(typeName + "$", link + "/" + label, xs)
82104
case EmptyReference => TypeReference(typeName, "", Nil)
83105
case _ => throw Exception("Match error in TermRef. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(qual))
84106
}
85-
case reflect.Type.IsSymRef(reflect.Type.SymRef(symbol, typeOrBounds)) => symbol match {
86-
case reflect.IsClassDefSymbol(_) => //Need to be split because these types have their own file
87-
convertTypeOrBoundsToReference(reflect)(typeOrBounds) match {
88-
case TypeReference(label, link, xs, _) => TypeReference(symbol.name, link + "/" + label, xs, true)
89-
case EmptyReference if symbol.name == "<root>" | symbol.name == "_root_" => EmptyReference
90-
case EmptyReference => TypeReference(symbol.name, "", Nil, true)
91-
case _ => throw Exception("Match error in SymRef/TypeOrBounds/ClassDef. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(typeOrBounds))
92-
}
93-
case reflect.IsTermSymbol(_) | reflect.IsTypeDefSymbol(_) =>
94-
convertTypeOrBoundsToReference(reflect)(typeOrBounds) match {
95-
case TypeReference(label, link, xs, _) => TypeReference(symbol.name, link + "/" + label, xs)
96-
case EmptyReference if symbol.name == "<root>" | symbol.name == "_root_" => EmptyReference
97-
case EmptyReference => TypeReference(symbol.name, "", Nil)
98-
case _ => throw Exception("Match error in SymRef/TypeOrBounds/Other. This should not happen, please open an issue. " + convertTypeOrBoundsToReference(reflect)(typeOrBounds))
99-
}
100-
case _ => throw Exception("Match error in SymRef. This should not happen, please open an issue. " + symbol)
101-
}
102-
case _ => throw Exception("No match for type in conversion to Reference. This should not happen, please open an issue. " + tp)
107+
108+
// NOTE: old SymRefs are now either TypeRefs or TermRefs - the logic here needs to be moved into above branches
109+
// NOTE: _.symbol on *Ref returns its symbol
110+
// case SymRef(symbol, typeOrBounds) => symbol match {
111+
// }
112+
// case _ => throw Exception("No match for type in conversion to Reference. This should not happen, please open an issue. " + tp)
103113
}
104114

105115
inner(tp)

tastydoc/src/dotty/tastydoc/TastydocConsumer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class TastydocConsumer(mutablePackagesMap: scala.collection.mutable.HashMap[Stri
1414
final def apply(reflect: Reflection)(root: reflect.Tree): Unit = {
1515
import reflect._
1616

17-
representations.convertToRepresentation(reflect)(root, None) given (mutablePackagesMap)
17+
representations.convertToRepresentation(reflect)(root, None)(given mutablePackagesMap)
1818
}
19-
}
19+
}

tastydoc/src/dotty/tastydoc/comment/BodyEntities.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tastydoc
22
package comment
33

4-
import scala.collection._
4+
import scala.collection.{Seq => _, _}
55
import representations._
66

77
/** A body of text. A comment has a single body, which is composed of

0 commit comments

Comments
 (0)