Skip to content

Commit 1e63423

Browse files
authored
Merge pull request #9858 from dotty-staging/rename-Reflection-Comment-to-Documentation
Rename reflection comment to documentation
2 parents 006437d + 9207fd3 commit 1e63423

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,11 +2233,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
22332233

22342234
def localContext: Context =
22352235
if self.exists then ctx.withOwner(self) else ctx
2236-
def comment: Option[Comment] =
2236+
def documentation: Option[Documentation] =
22372237
import dotc.core.Comments.CommentsContext
22382238
val docCtx = ctx.docCtx.getOrElse {
22392239
throw new RuntimeException(
2240-
"DocCtx could not be found and comments are unavailable. This is a compiler-internal error."
2240+
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
22412241
)
22422242
}
22432243
docCtx.docstring(self)
@@ -2520,18 +2520,18 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25202520
def warning(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit =
25212521
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
25222522

2523-
type Comment = dotc.core.Comments.Comment
2523+
type Documentation = dotc.core.Comments.Comment
25242524

2525-
object Comment extends CommentModule
2525+
object Documentation extends DocumentationModule
25262526

2527-
object CommentMethodsImpl extends CommentMethods:
2528-
extension (self: Comment):
2527+
object DocumentationMethodsImpl extends DocumentationMethods:
2528+
extension (self: Documentation):
25292529
def raw: String = self.raw
25302530
def expanded: Option[String] = self.expanded
25312531
def usecases: List[(String, Option[DefDef])] =
25322532
self.usecases.map { uc => (uc.code, uc.tpdCode) }
25332533
end extension
2534-
end CommentMethodsImpl
2534+
end DocumentationMethodsImpl
25352535

25362536
private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
25372537
if tree.isEmpty then None else Some(tree)

library/src/scala/tasty/Reflection.scala

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import scala.tasty.reflect._
105105
*
106106
* +- Position
107107
*
108-
* +- Comment
108+
* +- Documentation
109109
*
110110
* +- Constant
111111
*
@@ -2551,8 +2551,8 @@ trait Reflection { reflection =>
25512551

25522552
def localContext: Context
25532553

2554-
/** The comment for this symbol, if any */
2555-
def comment: Option[Comment]
2554+
/** The documentation for this symbol, if any */
2555+
def documentation: Option[Documentation]
25562556

25572557
/** Tree of this definition
25582558
*
@@ -3138,28 +3138,26 @@ trait Reflection { reflection =>
31383138
/** Emits a warning at a specific range of a file */
31393139
def warning(msg: => String, source: SourceFile, start: Int, end: Int): Unit
31403140

3141-
//////////////
3142-
// COMMENTS //
3143-
//////////////
3144-
3145-
// TODO: misnomer. Rename to `Documentation`
3141+
///////////////////
3142+
// DOCUMENTATION //
3143+
///////////////////
31463144

31473145
/** Attachment representing the documentation of a definition */
3148-
type Comment <: AnyRef
3146+
type Documentation <: AnyRef
31493147

3150-
val Comment: CommentModule
3148+
val Documentation: DocumentationModule
31513149

3152-
trait CommentModule { this: Comment.type => }
3150+
trait DocumentationModule { this: Documentation.type => }
31533151

3154-
given CommentMethods as CommentMethods = CommentMethodsImpl
3155-
protected val CommentMethodsImpl: CommentMethods
3152+
given DocumentationMethods as DocumentationMethods = DocumentationMethodsImpl
3153+
protected val DocumentationMethodsImpl: DocumentationMethods
31563154

3157-
trait CommentMethods {
3158-
extension (self: Comment):
3159-
/** Raw comment string */
3155+
trait DocumentationMethods {
3156+
extension (self: Documentation):
3157+
/** Raw documentation string */
31603158
def raw: String
31613159

3162-
/** Expanded comment string, if any */
3160+
/** Expanded documentation string, if any */
31633161
def expanded: Option[String]
31643162

31653163
/** List of usecases and their corresponding trees, if any */

tastydoc/src/dotty/tastydoc/TastyExtractor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
3939
})
4040
}
4141

42-
def extractComments(using QuoteContext)(comment: Option[qctx.tasty.Comment], rep: Representation) : (Map[String, EmulatedPackageRepresentation], String) => Option[Comment] = {
42+
def extractComments(using QuoteContext)(comment: Option[qctx.tasty.Documentation], rep: Representation) : (Map[String, EmulatedPackageRepresentation], String) => Option[Comment] = {
4343
comment match {
4444
case Some(com) =>
4545
(packages, userDocSyntax) => {

tastydoc/src/dotty/tastydoc/representations.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object representations extends TastyExtractor {
8989
override val members = internal.stats.map(convertToRepresentation(_, Some(this)))
9090
override val annotations = extractAnnotations(internal.symbol.annots)
9191

92-
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.comment, this)(packages, userDocSyntax)
92+
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.documentation, this)(packages, userDocSyntax)
9393
}
9494

9595
class ImportRepresentation(using QuoteContext)(internal: qctx.tasty.Import, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation {
@@ -103,7 +103,7 @@ object representations extends TastyExtractor {
103103
override val path = internal.expr.symbol.show.split("\\.").toList
104104
override val annotations = extractAnnotations(internal.symbol.annots)
105105

106-
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.comment, this)(packages, userDocSyntax)
106+
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.documentation, this)(packages, userDocSyntax)
107107
}
108108

109109
class ClassRepresentation(using QuoteContext)(internal: qctx.tasty.ClassDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members with Parents with Modifiers with Companion with Constructors with TypeParams {
@@ -139,7 +139,7 @@ object representations extends TastyExtractor {
139139
)
140140
override val members: List[Representation with Modifiers] = extractClassMembers(internal.body, internal.symbol, Some(this))
141141

142-
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.comment, this)(packages, userDocSyntax)
142+
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.documentation, this)(packages, userDocSyntax)
143143
}
144144

145145
class DefRepresentation(using QuoteContext)(internal: qctx.tasty.DefDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams with MultipleParamList with ReturnValue {
@@ -158,7 +158,7 @@ object representations extends TastyExtractor {
158158
}
159159
override val returnValue = convertTypeToReference(internal.returnTpt.tpe)
160160
override val annotations = extractAnnotations(internal.symbol.annots)
161-
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.comment, this)(packages, userDocSyntax)
161+
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.documentation, this)(packages, userDocSyntax)
162162
}
163163

164164
class ValRepresentation(using QuoteContext)(internal: qctx.tasty.ValDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with ReturnValue {
@@ -171,7 +171,7 @@ object representations extends TastyExtractor {
171171
override val annotations = extractAnnotations(internal.symbol.annots)
172172
val isVar: Boolean = internal.symbol.flags.is(Flags.Mutable)
173173

174-
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.comment, this)(packages, userDocSyntax)
174+
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.documentation, this)(packages, userDocSyntax)
175175
}
176176

177177
class TypeRepresentation(using QuoteContext)(internal: qctx.tasty.TypeDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams {
@@ -188,7 +188,7 @@ object representations extends TastyExtractor {
188188
case _ => None
189189
}
190190
override def isAbstract: Boolean = !alias.isDefined
191-
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.comment, this)(packages, userDocSyntax)
191+
override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(internal.symbol.documentation, this)(packages, userDocSyntax)
192192
}
193193

194194
def convertToRepresentation(using QuoteContext)(tree: qctx.tasty.Tree, parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]): Representation = {

tests/run-custom-args/tasty-inspector/tasty-comment-inspector/Test.scala renamed to tests/run-custom-args/tasty-inspector/tasty-documentation-inspector/Test.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import scala.tasty.inspector._
33

44
object Test {
55
def main(args: Array[String]): Unit = {
6-
new CommentInspector().inspect("", List("Foo"))
6+
new DocumentationInspector().inspect("", List("Foo"))
77
}
88
}
99

10-
class CommentInspector extends TastyInspector {
10+
class DocumentationInspector extends TastyInspector {
1111

1212
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit = {
1313
import qctx.tasty._
1414
object Traverser extends TreeTraverser {
1515

1616
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
1717
case tree: Definition =>
18-
tree.symbol.comment match {
19-
case Some(com) => println(com.raw)
18+
tree.symbol.documentation match {
19+
case Some(doc) => println(doc.raw)
2020
case None => println()
2121
}
2222
super.traverseTree(tree)

0 commit comments

Comments
 (0)