Skip to content

Commit b65f2d5

Browse files
committed
Migrate scaladoc-new
1 parent 4a1506f commit b65f2d5

21 files changed

+45
-41
lines changed

library/src/scala/IArray.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ object IArray:
330330
extension [T, U >: T: ClassTag](x: T)
331331
def +:(arr: IArray[U]): IArray[U] = genericArrayOps(arr).prepended(x)
332332

333+
// For backward compatibility with code compiled without -Yexplicit-nulls.
334+
// If `a` is null, return null; otherwise, return `f`.
335+
// Have to add a private mapNull here to avoid errors
336+
private inline def mapNull[A, B](a: A, inline f: B): B =
337+
if((a: A | Null) == null) null.asInstanceOf[B] else f
338+
333339
/** Conversion from IArray to immutable.ArraySeq.
334340
*
335341
* Note: Both the parameter and the return type are non-nullable. However, if a null

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ object Build {
26382638
Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions"),
26392639
Compile / scalacOptions += "-experimental",
26402640
// TODO: Enable these flags when the new stdlib is explicitelly null checked
2641-
//Compile / scalacOptions ++= Seq("-Yexplicit-nulls", "-Wsafe-init"),
2641+
Compile / scalacOptions ++= Seq("-Yexplicit-nulls", "-Wsafe-init"),
26422642
// Make sure that the produced artifacts have the minimum JVM version in the bytecode
26432643
Compile / javacOptions ++= Seq("--release", Versions.minimumJVMVersion),
26442644
Compile / scalacOptions ++= Seq("--java-output-version", Versions.minimumJVMVersion),

scaladoc/src/dotty/tools/scaladoc/PathBased.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object PathBased:
2424

2525
def parse[T](args: Seq[String], projectRoot: Path = Paths.get("").toAbsolutePath())(using parser: ArgParser[T]): ParsingResult[T] = {
2626
val parsed = args.map {
27-
case PathExtractor(path, arg) => parser.parse(arg).map(elem => Entry(Some(Paths.get(path)), elem))
27+
case PathExtractor(path: String, arg: String) => parser.parse(arg).map(elem => Entry(Some(Paths.get(path)), elem))
2828
case arg => parser.parse(arg).map(elem => Entry(None, elem))
2929
}
3030
val errors = parsed.collect {

scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object Scaladoc:
1919
tastyFiles: Seq[File] = Nil,
2020
classpath: String = "",
2121
bootclasspath: String = "",
22-
output: File,
22+
output: File | Null,
2323
docsRoot: Option[String] = None,
2424
projectVersion: Option[String] = None,
2525
projectLogo: Option[String] = None,
@@ -66,13 +66,13 @@ object Scaladoc:
6666
if !ctx.reporter.hasErrors then
6767
val updatedArgs = parsedArgs.copy(tastyDirs = parsedArgs.tastyDirs, tastyFiles = tastyFiles)
6868

69-
if (parsedArgs.output.exists()) util.IO.delete(parsedArgs.output)
69+
if (parsedArgs.output.nn.exists()) util.IO.delete(parsedArgs.output)
7070

7171
run(updatedArgs)
7272
report.inform("Done")
7373
else report.error("Failure")
7474

75-
if parsedArgs.generateInkuire then dumpInkuireDB(parsedArgs.output.getAbsolutePath, parsedArgs)
75+
if parsedArgs.generateInkuire then dumpInkuireDB(parsedArgs.output.nn.getAbsolutePath, parsedArgs)
7676
}
7777

7878
ctx.reporter

scaladoc/src/dotty/tools/scaladoc/SourceLinks.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class SourceLinkParser(revision: Option[String]) extends ArgParser[SourceLink]:
7373
if unsupported.nonEmpty then Left(s"Unsupported patterns from scaladoc format are used: ${unsupported.mkString(" ")}")
7474
else Right(TemplateSourceLink(supported.foldLeft(string)((template, pattern) =>
7575
template.replace(pattern, SupportedScalaDocPatternReplacements(pattern)))))
76-
case KnownProvider(name, organization, repo, rawRevision, rawSubPath) =>
77-
val subPath = Option(rawSubPath).fold("")("/" + _.drop(1))
78-
val pathRev = Option(rawRevision).map(_.drop(1)).orElse(revision)
76+
case KnownProvider(name: String, organization: String, repo: String, rawRevision, rawSubPath) =>
77+
val subPath = Option.fromNullable(rawSubPath).fold("")("/" + _.drop(1))
78+
val pathRev = Option.fromNullable(rawRevision).map(_.drop(1)).orElse(revision)
7979

8080
def withRevision(template: String => SourceLink) =
8181
pathRev.fold(Left(s"No revision provided"))(r => Right(template(r)))

scaladoc/src/dotty/tools/scaladoc/compat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type JMap[K, V] = java.util.Map[K, V]
1717
type JHashMap[K, V] = java.util.HashMap[K, V]
1818
type JMapEntry[K, V] = java.util.Map.Entry[K, V]
1919

20-
private val emptyListInst = Collections.emptyList
20+
private val emptyListInst: JList[AnyRef] = Collections.emptyList
2121
def JNil[A] = emptyListInst.asInstanceOf[JList[A]]
2222

23-
private val emptyMapInst = Collections.emptyMap
23+
private val emptyMapInst: JMap[AnyRef, AnyRef] = Collections.emptyMap
2424
def emptyJMap[A, B] = emptyMapInst.asInstanceOf[JMap[A, B]]
2525

2626
enum DocLink:

scaladoc/src/dotty/tools/scaladoc/parsers/WikiCodeBlockParser.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ object WikiCodeBlockParser {
5555
def tryStart(state: ParserState, matchedBlockParser: MatchedBlockParser): BlockStart = {
5656
val nextNonSpace = state.getNextNonSpaceIndex
5757
val line = state.getLine
58-
var matcher: Matcher = null
5958
if state.getIndent < 4 then {
6059
val trySequence = line.subSequence(nextNonSpace, line.length)
61-
matcher = OPENING_FENCE.matcher(trySequence)
60+
val matcher = OPENING_FENCE.matcher(trySequence)
6261
if matcher.find then {
6362
val fenceLength = matcher.group(0).length
6463
val blockParser =
@@ -93,14 +92,13 @@ class WikiCodeBlockParser(
9392
val nextNonSpace = state.getNextNonSpaceIndex
9493
var newIndex = state.getIndex
9594
val line = state.getLine
96-
var matcher: Matcher = null
9795
val matches =
9896
state.getIndent <= 3
9997
&& nextNonSpace < line.length
10098

10199
if matches then {
102100
val trySequence = line.subSequence(nextNonSpace, line.length)
103-
matcher = WikiCodeBlockParser.CLOSING_FENCE.matcher(trySequence)
101+
val matcher = WikiCodeBlockParser.CLOSING_FENCE.matcher(trySequence)
104102
if matcher.find then {
105103
val foundFenceLength = matcher.group(0).length
106104
if (foundFenceLength >= fenceLength) { // closing fence - we're at end of line, so we can finalize now
@@ -150,7 +148,7 @@ class WikiCodeBlockParser(
150148
}
151149
else block.setContent(content)
152150
block.setCharsFromContent
153-
content = null
151+
content = null.asInstanceOf[BlockContent] // release for GC
154152
}
155153
}
156154

scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait SiteRenderer(using DocContext) extends Locations:
3333

3434
def tryAsDriPlain(str: String): Option[String] =
3535
val (path, prefix) = str match
36-
case HashRegex(path, prefix) => (path, prefix)
36+
case HashRegex(path: String, prefix: String) => (path, prefix)
3737
case _ => (str, "")
3838
val res = ctx.driForLink(content.template.file, path).filter(driExists)
3939
res.headOption.map(pathToPage(pageDri, _) + prefix)
@@ -46,7 +46,7 @@ trait SiteRenderer(using DocContext) extends Locations:
4646
case _ => str
4747

4848
val (path, prefix) = newStr match
49-
case HashRegex(path, prefix) => (path, prefix)
49+
case HashRegex(path: String, prefix: String) => (path, prefix)
5050
case _ => (newStr, "")
5151

5252
val res = ctx.driForLink(content.template.file, path).filter(driExists)

scaladoc/src/dotty/tools/scaladoc/renderers/Writer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait Writer(using ctx: DocContext) extends Locations:
1414
private val args = summon[DocContext].args
1515

1616
private def dest(path: String) =
17-
val absPath = args.output.toPath.resolve(path)
17+
val absPath = args.output.nn.toPath.resolve(path)
1818
if !Files.exists(absPath.getParent) then Files.createDirectories(absPath.getParent)
1919
absPath
2020

scaladoc/src/dotty/tools/scaladoc/site/BlogParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import scala.beans.{BooleanBeanProperty, BeanProperty}
88
import scala.util.Try
99

1010
case class BlogConfig(
11-
@BeanProperty input: String,
12-
@BeanProperty output: String,
11+
@BeanProperty input: String | Null,
12+
@BeanProperty output: String | Null,
1313
@BooleanBeanProperty hidden: Boolean
1414
):
1515
def this() = this(null, null, false)

0 commit comments

Comments
 (0)