Skip to content

Commit c291a96

Browse files
committed
Rename Reflection.{Comment => Documentation}
The name of the concept does not suggest that these are the documentation string. It also suggests that the comments can be accessed which is not the case.
1 parent 01fc4a1 commit c291a96

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

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

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

22412241
def localContext: Context =
22422242
if self.exists then ctx.withOwner(self) else ctx
2243-
def comment: Option[Comment] =
2243+
def documentation: Option[Documentation] =
22442244
import dotc.core.Comments.CommentsContext
22452245
val docCtx = ctx.docCtx.getOrElse {
22462246
throw new RuntimeException(
2247-
"DocCtx could not be found and comments are unavailable. This is a compiler-internal error."
2247+
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
22482248
)
22492249
}
22502250
docCtx.docstring(self)
@@ -2527,18 +2527,18 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25272527
def warning(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit =
25282528
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
25292529

2530-
type Comment = dotc.core.Comments.Comment
2530+
type Documentation = dotc.core.Comments.Comment
25312531

2532-
object Comment extends CommentModule
2532+
object Documentation extends DocumentationModule
25332533

2534-
object CommentMethodsImpl extends CommentMethods:
2535-
extension (self: Comment):
2534+
object DocumentationMethodsImpl extends DocumentationMethods:
2535+
extension (self: Documentation):
25362536
def raw: String = self.raw
25372537
def expanded: Option[String] = self.expanded
25382538
def usecases: List[(String, Option[DefDef])] =
25392539
self.usecases.map { uc => (uc.code, uc.tpdCode) }
25402540
end extension
2541-
end CommentMethodsImpl
2541+
end DocumentationMethodsImpl
25422542

25432543
private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
25442544
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
@@ -107,7 +107,7 @@ import scala.tasty.reflect._
107107
*
108108
* +- Position
109109
*
110-
* +- Comment
110+
* +- Documentation
111111
*
112112
* +- Constant
113113
*
@@ -2575,8 +2575,8 @@ trait Reflection { reflection =>
25752575

25762576
def localContext: Context
25772577

2578-
/** The comment for this symbol, if any */
2579-
def comment: Option[Comment]
2578+
/** The documentation for this symbol, if any */
2579+
def documentation: Option[Documentation]
25802580

25812581
/** Tree of this definition
25822582
*
@@ -3162,28 +3162,26 @@ trait Reflection { reflection =>
31623162
/** Emits a warning at a specific range of a file */
31633163
def warning(msg: => String, source: SourceFile, start: Int, end: Int): Unit
31643164

3165-
//////////////
3166-
// COMMENTS //
3167-
//////////////
3168-
3169-
// TODO: misnomer. Rename to `Documentation`
3165+
///////////////////
3166+
// DOCUMENTATION //
3167+
///////////////////
31703168

31713169
/** Attachment representing the documentation of a definition */
3172-
type Comment <: AnyRef
3170+
type Documentation <: AnyRef
31733171

3174-
val Comment: CommentModule
3172+
val Documentation: DocumentationModule
31753173

3176-
trait CommentModule { this: Comment.type => }
3174+
trait DocumentationModule { this: Documentation.type => }
31773175

3178-
given CommentMethods as CommentMethods = CommentMethodsImpl
3179-
protected val CommentMethodsImpl: CommentMethods
3176+
given DocumentationMethods as DocumentationMethods = DocumentationMethodsImpl
3177+
protected val DocumentationMethodsImpl: DocumentationMethods
31803178

3181-
trait CommentMethods {
3182-
extension (self: Comment):
3183-
/** Raw comment string */
3179+
trait DocumentationMethods {
3180+
extension (self: Documentation):
3181+
/** Raw documentation string */
31843182
def raw: String
31853183

3186-
/** Expanded comment string, if any */
3184+
/** Expanded documentation string, if any */
31873185
def expanded: Option[String]
31883186

31893187
/** 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 = {

0 commit comments

Comments
 (0)