Skip to content

Commit 3b154a0

Browse files
authored
Merge pull request scala#10502 from som-snytt/issue/12846-scaladoc-unicode
Use URI to compute Scaladoc URI [ci: last-only]
2 parents cc25c89 + f790c6d commit 3b154a0

23 files changed

+127
-83
lines changed

src/compiler/scala/reflect/reify/utils/NodePrinters.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package scala.reflect.reify
1414
package utils
1515

1616
import java.lang.System.{lineSeparator => EOL}
17+
import scala.util.matching.Regex.quoteReplacement
1718

1819
trait NodePrinters {
1920
self: Utils =>
@@ -63,7 +64,7 @@ trait NodePrinters {
6364
}
6465

6566
val replacement = "Modifiers(" + buf.reverse.mkString(", ") + ")"
66-
java.util.regex.Matcher.quoteReplacement(replacement)
67+
quoteReplacement(replacement)
6768
})
6869
s
6970
})

src/compiler/scala/reflect/reify/utils/SymbolTables.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.reflect.reify
1414
package utils
1515

16-
import scala.collection._
16+
import scala.collection.{immutable, mutable}, mutable.{ArrayBuffer, ListBuffer}
1717
import java.lang.System.{lineSeparator => EOL}
1818

1919
trait SymbolTables {
@@ -22,7 +22,7 @@ trait SymbolTables {
2222
import global._
2323

2424
class SymbolTable private[SymbolTable] (
25-
private[SymbolTable] val symtab: immutable.ListMap[Symbol, Tree] = immutable.ListMap[Symbol, Tree](),
25+
private[SymbolTable] val symtab: immutable.ListMap[Symbol, Tree] = immutable.ListMap.empty[Symbol, Tree],
2626
private[SymbolTable] val aliases: List[(Symbol, TermName)] = List[(Symbol, TermName)](),
2727
private[SymbolTable] val original: Option[List[Tree]] = None) {
2828

@@ -166,8 +166,8 @@ trait SymbolTables {
166166
reifier.state.symtab = symtab0.asInstanceOf[reifier.SymbolTable]
167167
def currtab = reifier.symtab.asInstanceOf[SymbolTable]
168168
try {
169-
val cumulativeSymtab = mutable.ArrayBuffer[Tree](symtab0.symtab.values.toList: _*)
170-
val cumulativeAliases = mutable.ArrayBuffer[(Symbol, TermName)](symtab0.aliases: _*)
169+
val cumulativeSymtab = ArrayBuffer[Tree](symtab0.symtab.values.toList: _*)
170+
val cumulativeAliases = ArrayBuffer[(Symbol, TermName)](symtab0.aliases: _*)
171171

172172
def fillInSymbol(sym: Symbol): Tree = {
173173
if (reifyDebug) println("Filling in: %s (%s)".format(sym, sym.accurateKindString))
@@ -203,7 +203,7 @@ trait SymbolTables {
203203
}
204204

205205
val withAliases = cumulativeSymtab flatMap (entry => {
206-
val result = mutable.ListBuffer[Tree]()
206+
val result = ListBuffer[Tree]()
207207
result += entry
208208
val sym = reifyBinding(entry).symbol
209209
if (sym != NoSymbol)

src/compiler/scala/tools/nsc/transform/CleanUp.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package transform
1515

1616
import symtab._
1717
import Flags._
18-
import scala.collection._
18+
import scala.collection.mutable, mutable.{Buffer, ListBuffer}
1919
import scala.tools.nsc.Reporting.WarningCategory
2020
import scala.util.chaining._
2121

@@ -35,8 +35,8 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
3535
new CleanUpTransformer(unit)
3636

3737
class CleanUpTransformer(unit: CompilationUnit) extends StaticsTransformer {
38-
private val newStaticMembers = mutable.Buffer.empty[Tree]
39-
private val newStaticInits = mutable.Buffer.empty[Tree]
38+
private val newStaticMembers = Buffer.empty[Tree]
39+
private val newStaticInits = Buffer.empty[Tree]
4040
private val symbolsStoredAsStatic = mutable.Map.empty[String, Symbol]
4141
private var transformListApplyLimit = 8
4242
private def reducingTransformListApply[A](depth: Int)(body: => A): A = {
@@ -438,7 +438,7 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
438438
* resulting switch may need to correspond to a single case body.
439439
*/
440440

441-
val labels = mutable.ListBuffer.empty[LabelDef]
441+
val labels = ListBuffer.empty[LabelDef]
442442
var defaultCaseBody = Throw(New(MatchErrorClass.tpe_*, selArg)): Tree
443443

444444
def LABEL(name: String) = currentOwner.newLabel(unit.freshTermName(name), swPos).setFlag(SYNTH_CASE_FLAGS)
@@ -523,7 +523,7 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
523523
gen.evalOnce(classTagEvidence, currentOwner, unit) { ev =>
524524
val arr = typedWithPos(tree.pos)(gen.mkMethodCall(classTagEvidence, definitions.ClassTagClass.info.decl(nme.newArray), Nil, Literal(Constant(elems.size)) :: Nil))
525525
gen.evalOnce(arr, currentOwner, unit) { arr =>
526-
val stats = mutable.ListBuffer[Tree]()
526+
val stats = ListBuffer[Tree]()
527527
foreachWithIndex(elems) { (elem, i) =>
528528
stats += gen.mkMethodCall(gen.mkAttributedRef(definitions.ScalaRunTimeModule), currentRun.runDefinitions.arrayUpdateMethod,
529529
Nil, arr() :: Literal(Constant(i)) :: elem :: Nil)

src/compiler/scala/tools/nsc/transform/Delambdafy.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package transform
1515

1616
import symtab._
1717
import Flags._
18-
import scala.collection._
18+
import scala.collection.mutable
1919

2020
/**
2121
* This transformer is responsible for preparing Function nodes for runtime,
@@ -68,7 +68,7 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
6868
class DelambdafyTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
6969
// we need to know which methods refer to the 'this' reference so that we can determine which lambdas need access to it
7070
// TODO: this looks expensive, so I made it a lazy val. Can we make it more pay-as-you-go / optimize for common shapes?
71-
private[this] lazy val methodReferencesThis: Set[Symbol] =
71+
private[this] lazy val methodReferencesThis: collection.Set[Symbol] =
7272
(new ThisReferringMethodsTraverser).methodReferencesThisIn(unit.body)
7373

7474
private def mkLambdaMetaFactoryCall(fun: Function, target: Symbol, functionalInterface: Symbol, samUserDefined: Symbol, userSamCls: Symbol, isSpecialized: Boolean): Tree = {
@@ -360,12 +360,12 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
360360
// finds all methods that reference 'this'
361361
class ThisReferringMethodsTraverser extends InternalTraverser {
362362
// the set of methods that refer to this
363-
private val thisReferringMethods = mutable.Set[Symbol]()
363+
private val thisReferringMethods = mutable.Set.empty[Symbol]
364364

365365
// the set of lifted lambda body methods that each method refers to
366-
private val liftedMethodReferences = mutable.Map[Symbol, mutable.Set[Symbol]]()
366+
private val liftedMethodReferences = mutable.Map.empty[Symbol, mutable.Set[Symbol]]
367367

368-
def methodReferencesThisIn(tree: Tree) = {
368+
def methodReferencesThisIn(tree: Tree): collection.Set[Symbol] = {
369369
traverse(tree)
370370
liftedMethodReferences.keys foreach refersToThis
371371

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import scala.language.implicitConversions
2525
import scala.reflect.internal.util.{ReusableInstance, Statistics, TriState}
2626
import scala.reflect.internal.TypesStats
2727
import scala.tools.nsc.Reporting.WarningCategory
28-
import scala.util.matching.Regex
2928
import symtab.Flags._
3029

3130
/** This trait provides methods to find various kinds of implicits.
@@ -40,6 +39,7 @@ trait Implicits extends splain.SplainData {
4039
import statistics._
4140
import typingStack.printTyping
4241
import typeDebug._
42+
import scala.util.matching.Regex.Match
4343

4444
// standard usage
4545
def inferImplicitFor(pt: Type, tree: Tree, context: Context, reportAmbiguous: Boolean = true): SearchResult =
@@ -1828,14 +1828,15 @@ trait Implicits extends splain.SplainData {
18281828
object ImplicitAmbiguousMsg extends ImplicitAnnotationMsg(_.implicitAmbiguousMsg, ImplicitAmbiguousClass, "implicitAmbiguous")
18291829

18301830
class Message(sym: Symbol, msg: String, annotationName: String) {
1831+
import scala.util.matching.Regex.{quoteReplacement, Groups}
18311832
// https://dcsobral.blogspot.com/2010/01/string-interpolation-in-scala-with.html
18321833
private val Intersobralator = """\$\{\s*([^}\s]+)\s*\}""".r
18331834

18341835
private def interpolate(text: String, vars: Map[String, String]) =
1835-
Intersobralator.replaceAllIn(text, (_: Regex.Match) match {
1836-
case Regex.Groups(v) => Regex.quoteReplacement(vars.getOrElse(v, ""))
1836+
Intersobralator.replaceAllIn(text, (_: Match) match {
1837+
case Groups(v) => quoteReplacement(vars.getOrElse(v, ""))
18371838
// #3915: need to quote replacement string since it may include $'s (such as the interpreter's $iw)
1838-
case x => throw new MatchError(x)
1839+
case x => throw new MatchError(x)
18391840
})
18401841

18411842
def referencedTypeParams: List[String] = Intersobralator.findAllMatchIn(msg).map(_.group(1)).distinct.toList

src/partest/scala/tools/partest/ReplTest.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ package scala.tools.partest
1414

1515
import scala.tools.nsc.Settings
1616
import scala.tools.nsc.interpreter.shell.{ILoop, ShellConfig}
17-
import scala.util.matching.Regex
18-
import scala.util.matching.Regex.Match
17+
import scala.util.matching.Regex.{quoteReplacement, Match}
1918

2019
/** Test code or commands in a REPL.
2120
*
@@ -76,7 +75,7 @@ trait Lambdaless extends ReplTest {
7675
}
7776
object Lambdaless {
7877
private val lambdaless = """\$Lambda(?:\$\d+)?/(?:0x[a-f0-9]{16}|\d+)(?:@[a-fA-F0-9]+)?""".r
79-
private def stripLambdaClassName(s: String): String = lambdaless.replaceAllIn(s, Regex.quoteReplacement("<function>"))
78+
private def stripLambdaClassName(s: String): String = lambdaless.replaceAllIn(s, quoteReplacement("<function>"))
8079
}
8180

8281
/** Normalize a REPL stack trace by stripping line numbers and count of elided frames. */
@@ -132,7 +131,7 @@ abstract class SessionTest extends ReplTest {
132131
override final def code = pasted.findAllMatchIn(expected.mkString("", "\n", "\n")).map {
133132
case pasted(null, null, prompted) =>
134133
def continued(m: Match): Option[String] = m match {
135-
case margin(text) => Some(Regex.quoteReplacement(text))
134+
case margin(text) => Some(quoteReplacement(text))
136135
case _ => None
137136
}
138137
margin.replaceSomeIn(prompted, continued)

src/partest/scala/tools/partest/nest/Runner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import scala.util.{Failure, Success, Try, Using}
3232
import scala.util.Properties.isJavaAtLeast
3333
import scala.util.chaining._
3434
import scala.util.control.{ControlThrowable, NonFatal}
35-
import scala.util.matching.Regex
35+
import scala.util.matching.Regex.quoteReplacement
3636
import ClassPath.join
3737
import FileManager.{compareContents, joinPaths, withTempFile}
3838
import TestState.{Crash, Fail, Pass, Skip, Updated}
@@ -367,7 +367,7 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
367367
def canonicalize: String => String = {
368368
val hiders = toolArgs(ToolName.hide).map(_.r)
369369
(s: String) => {
370-
val pathless = pathFinder.replaceAllIn(s, m => Regex.quoteReplacement(ellipsis + squashSlashes(m.group(1))))
370+
val pathless = pathFinder.replaceAllIn(s, m => quoteReplacement(ellipsis + squashSlashes(m.group(1))))
371371
if (hiders.isEmpty) pathless
372372
else hiders.foldLeft(pathless)((s, r) => r.replaceAllIn(s, m => "***"))
373373
}

src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ package base
1616

1717
import base.comment._
1818
import scala.annotation.{nowarn, tailrec}
19-
import scala.collection._
20-
import scala.util.matching.Regex
19+
import scala.collection.mutable, mutable.ListBuffer
2120
import scala.reflect.internal.util.Position
2221
import scala.tools.nsc.Reporting.WarningCategory
22+
import scala.util.matching.Regex.{quoteReplacement, Match}
2323

2424
/** The comment parser transforms raw comment strings into `Comment` objects.
2525
* Call `parse` to run the parser. Note that the parser is stateless and
@@ -121,16 +121,16 @@ trait CommentFactoryBase { this: MemberLookupBase =>
121121
/** The body of a line, dropping the (optional) start star-marker,
122122
* one leading whitespace and all trailing whitespace. */
123123
private val CleanCommentLine =
124-
new Regex("""(?:\s*\*\s?)?(.*)""")
124+
raw"(?:\s*\*\s?)?(.*)".r
125125

126126
/** Dangerous HTML tags that should be replaced by something safer,
127127
* such as wiki syntax, or that should be dropped. */
128128
private val DangerousTags =
129-
new Regex("""<(/?(div|ol|ul|li|h[1-6]|p))( [^>]*)?/?>|<!--.*-->""")
129+
raw"<(/?(div|ol|ul|li|h[1-6]|p))( [^>]*)?/?>|<!--.*-->".r
130130

131131
/** Maps a dangerous HTML tag to a safe wiki replacement, or an empty string
132132
* if it cannot be salvaged. */
133-
private def htmlReplacement(mtch: Regex.Match): String = mtch.group(1) match {
133+
private def htmlReplacement(mtch: Match): String = mtch.group(1) match {
134134
case "p" | "div" => "\n\n"
135135
case "h1" => "\n= "
136136
case "/h1" => " =\n"
@@ -147,10 +147,10 @@ trait CommentFactoryBase { this: MemberLookupBase =>
147147
/** Javadoc tags that should be replaced by something useful, such as wiki
148148
* syntax, or that should be dropped. */
149149
private val JavadocTags =
150-
new Regex("""\{\@(code|docRoot|linkplain|link|literal|value)\p{Zs}*([^}]*)\}""")
150+
raw"\{\@(code|docRoot|linkplain|link|literal|value)\p{Zs}*([^}]*)\}".r
151151

152152
/** Maps a javadoc tag to a useful wiki replacement, or an empty string if it cannot be salvaged. */
153-
private def javadocReplacement(mtch: Regex.Match): String = {
153+
private def javadocReplacement(mtch: Match): String = {
154154
mtch.group(1) match {
155155
case "code" => "<code>" + mtch.group(2) + "</code>"
156156
case "docRoot" => ""
@@ -164,30 +164,30 @@ trait CommentFactoryBase { this: MemberLookupBase =>
164164

165165
/** Safe HTML tags that can be kept. */
166166
private val SafeTags =
167-
new Regex("""((&\w+;)|(&#\d+;)|(</?(abbr|acronym|address|area|a|bdo|big|blockquote|br|button|b|caption|cite|code|col|colgroup|dd|del|dfn|em|fieldset|form|hr|img|input|ins|i|kbd|label|legend|link|map|object|optgroup|option|param|pre|q|samp|select|small|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|tr|tt|var)( [^>]*)?/?>))""")
167+
raw"((&\w+;)|(&#\d+;)|(</?(abbr|acronym|address|area|a|bdo|big|blockquote|br|button|b|caption|cite|code|col|colgroup|dd|del|dfn|em|fieldset|form|hr|img|input|ins|i|kbd|label|legend|link|map|object|optgroup|option|param|pre|q|samp|select|small|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|tr|tt|var)( [^>]*)?/?>))".r
168168

169169
private val safeTagMarker = '\u000E' // control-N
170170

171171
/** A Scaladoc tag not linked to a symbol and not followed by text */
172172
private val SingleTagRegex =
173-
new Regex("""\s*@(\S+)\s*""")
173+
raw"\s*@(\S+)\s*".r
174174

175175
/** A Scaladoc tag not linked to a symbol. Returns the name of the tag, and the rest of the line. */
176176
private val SimpleTagRegex =
177-
new Regex("""\s*@(\S+)\s+(.*)""")
177+
raw"\s*@(\S+)\s+(.*)".r
178178

179179
/** A Scaladoc tag linked to a symbol. Returns the name of the tag, the name
180180
* of the symbol, and the rest of the line. */
181181
private val SymbolTagRegex =
182-
new Regex("""\s*@(param|tparam|throws|groupdesc|groupname|groupprio)\s+(\S*)\s*(.*)""")
182+
raw"\s*@(param|tparam|throws|groupdesc|groupname|groupprio)\s+(\S*)\s*(.*)".r
183183

184184
/** The start of a Scaladoc code block */
185185
private val CodeBlockStartRegex =
186-
new Regex(s"""(.*?)((?:\\{\\{\\{)|(?:$safeTagMarker<pre(?: [^>]*)?>$safeTagMarker))(.*)""")
186+
raw"(.*?)((?:\{\{\{)|(?:$safeTagMarker<pre(?: [^>]*)?>$safeTagMarker))(.*)".r
187187

188188
/** The end of a Scaladoc code block */
189189
private val CodeBlockEndRegex =
190-
new Regex(s"""(.*?)((?:\\}\\}\\})|(?:$safeTagMarker</pre>$safeTagMarker))(.*)""")
190+
raw"(.*?)((?:\}\}\})|(?:$safeTagMarker</pre>$safeTagMarker))(.*)".r
191191

192192
/** A key used for a tag map. The key is built from the name of the tag and
193193
* from the linked symbol if the tag has one.
@@ -221,7 +221,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
221221
val javadoclessComment = JavadocTags.replaceAllIn(safeComment, { javadocReplacement(_) })
222222
val markedTagComment =
223223
SafeTags.replaceAllIn(javadoclessComment, { mtch =>
224-
java.util.regex.Matcher.quoteReplacement(s"$safeTagMarker${mtch.matched}$safeTagMarker")
224+
quoteReplacement(s"$safeTagMarker${mtch.matched}$safeTagMarker")
225225
})
226226
markedTagComment.linesIterator.toList map cleanLine
227227
}
@@ -239,7 +239,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
239239
* @param inCodeBlock Whether the next line is part of a code block (in which no tags must be read). */
240240
def parse0 (
241241
docBody: StringBuilder,
242-
tags: immutable.Map[TagKey, List[String]],
242+
tags: Map[TagKey, List[String]],
243243
lastTagKey: Option[TagKey],
244244
remaining: List[String],
245245
inCodeBlock: Boolean
@@ -414,7 +414,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
414414
com
415415
}
416416

417-
parse0(new StringBuilder(comment.length), immutable.Map.empty, None, clean(comment), inCodeBlock = false)
417+
parse0(new StringBuilder(comment.length), Map.empty, None, clean(comment), inCodeBlock = false)
418418

419419
}
420420

@@ -503,14 +503,14 @@ trait CommentFactoryBase { this: MemberLookupBase =>
503503
/** Consumes all list item blocks (possibly with nested lists) of the
504504
* same list and returns the list block. */
505505
def listLevel(indent: Int, style: String): Block = {
506-
val lines = mutable.ListBuffer.empty[Block]
506+
val lines = ListBuffer.empty[Block]
507507
var line: Option[Block] = listLine(indent, style)
508508
while (line.isDefined) {
509509
lines += line.get
510510
line = listLine(indent, style)
511511
}
512512
val constructor = listStyles(style)
513-
constructor(lines)
513+
constructor(lines.toList)
514514
}
515515

516516
val indent = countWhitespace

src/scaladoc/scala/tools/nsc/doc/base/comment/Body.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package doc
1515
package base
1616
package comment
1717

18-
import scala.collection._
18+
import scala.collection.immutable.SortedMap
1919

2020
/** A body of text. A comment has a single body, which is composed of
2121
* at least one block. Inside every body is exactly one summary.

src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package doc
1515
package base
1616
package comment
1717

18-
import scala.collection._
18+
import scala.collection.mutable.ListBuffer
1919

2020
/** A Scaladoc comment and all its tags.
2121
*
@@ -29,7 +29,7 @@ abstract class Comment {
2929
def body: Body
3030

3131
private def closeHtmlTags(inline: Inline): Inline = {
32-
val stack = mutable.ListBuffer.empty[HtmlTag]
32+
val stack = ListBuffer.empty[HtmlTag]
3333
def scan(i: Inline): Unit = {
3434
i match {
3535
case Chain(list) =>

src/scaladoc/scala/tools/nsc/doc/doclet/Generator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.tools.nsc.doc
1414
package doclet
1515

16-
import scala.collection._
16+
import scala.collection.mutable
1717

1818
/** Custom Scaladoc generators must implement the `Generator` class. A custom generator can be selected in Scaladoc
1919
* using the `-doc-generator` command line option.

src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package html
1717
import model._
1818
import java.io.{ File => JFile }
1919
import io.{ Streamable, Directory }
20-
import scala.collection._
20+
import scala.collection.mutable
2121
import page.diagram._
2222
import scala.reflect.internal.Reporter
2323

src/scaladoc/scala/tools/nsc/doc/model/CommentFactory.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package model
1616

1717
import base.comment._
1818

19-
import scala.collection._
19+
import scala.collection.mutable
2020
import scala.reflect.internal.util.Position
2121

2222
/** The comment parser transforms raw comment strings into `Comment` objects.

src/scaladoc/scala/tools/nsc/doc/model/Entity.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ package scala.tools.nsc
1414
package doc
1515
package model
1616

17-
import scala.collection._
1817
import base.comment._
1918
import diagram._
2019

0 commit comments

Comments
 (0)