Skip to content

Commit

Permalink
Merge pull request #9045 from eed3si9n/wip/wait
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Jun 9, 2020
2 parents 2e72f44 + 9f685f7 commit 7000734
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
9 changes: 3 additions & 6 deletions src/library-aux/scala/AnyRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,21 @@ trait AnyRef extends Any {
*/
final def notifyAll(): Unit

/** Causes the current Thread to wait until another Thread invokes
* the notify() or notifyAll() methods.
/** See [[https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--]].
*
* @note not specified by SLS as a member of AnyRef
*/
final def wait (): Unit

/** Causes the current Thread to wait until another Thread invokes
* the notify() or notifyAll() methods, or a specified amount of time has elapsed.
/** See [[https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-]]
*
* @param timeout the maximum time to wait in milliseconds.
* @param nanos additional time, in nanoseconds range 0-999999.
* @note not specified by SLS as a member of AnyRef
*/
final def wait (timeout: Long, nanos: Int): Unit

/** Causes the current Thread to wait until another Thread invokes
* the notify() or notifyAll() methods, or a specified amount of time has elapsed.
/** See [[https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-]].
*
* @param timeout the maximum time to wait in milliseconds.
* @note not specified by SLS as a member of AnyRef
Expand Down
32 changes: 25 additions & 7 deletions src/scaladoc/scala/tools/nsc/doc/Uncompilable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,40 @@ trait Uncompilable {
val global: Global
val settings: Settings

import global.{ reporter, inform, newTypeName, newTermName, runReporting, Symbol, DocComment, NoSymbol }
import global.definitions.AnyRefClass
import global.{ reporter, inform, newTypeName, newTermName, runReporting, DefDef, Symbol, DocComment, MethodSymbol, NoSymbol }
import global.definitions.{ AnyRefClass, AnyRefTpe }
import global.rootMirror.RootClass

private implicit def translateName(name: Global#Name) =
if (name.isTypeName) newTypeName("" + name) else newTermName("" + name)

def docSymbol(p: DocParser.Parsed) = p.nameChain.foldLeft(RootClass: Symbol)(_.tpe member _)
val WaitNames = List("scala", "AnyRef", "wait")

def docSymbol(p: DocParser.Parsed) =
p.nameChain match {
// for scala.AnyRef.wait, pick Object#wait with the same arity
case xs if xs.map(_.toString) == WaitNames =>
val arity = p.docDef.definition match {
case t: DocParser#DefDef => t.vparamss.flatten.size
case _ => 0
}
val wait = AnyRefTpe.members find {
case m: MethodSymbol =>
m.name == newTermName("wait") && m.paramLists.flatten.size == arity
case _ => false
}
wait.getOrElse(sys.error(s"Object#wait with $arity parameters was not found"))
case xs => xs.foldLeft(RootClass: Symbol)(_.tpe member _)
}
def docDefs(code: String) = new DocParser(settings, reporter) docDefs code
def docPairs(code: String) = docDefs(code) map (p => (docSymbol(p), DocComment(p.raw)))

lazy val pairs = files flatMap { f =>
val comments = docPairs(f.slurp())
if (settings.verbose)
inform("Found %d doc comments in parse-only file %s: %s".format(comments.size, f, comments.map(_._1).mkString(", ")))

val code = f.slurp()
val comments = docPairs(code)
if (settings.verbose) {
inform(s"Found ${comments.size} doc comments in parse-only file $f: " + comments.map(_._1).mkString(", "))
}
comments
}
def files = settings.uncompilableFiles
Expand Down
14 changes: 14 additions & 0 deletions test/scaladoc/run/anyref-doc.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Some(Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(Wakes up all threads that are waiting on the receiver object's monitor), Text(.)))), Text(
))))))
)
List(scala.AnyRef#wait, scala.AnyRef#wait, scala.AnyRef#wait)
Some(Body(List(Paragraph(Chain(List(Summary(Chain(List(Chain(List(Text(See ), Link(https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--,Text(https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--)))), Text(.)))), Text(
))))))
)
Some(Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(See ), Link(https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-,Text(https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)), Text(
), Text()))))))))
)
Some(Body(List(Paragraph(Chain(List(Summary(Chain(List(Chain(List(Text(See ), Link(https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-,Text(https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-)))), Text(.)))), Text(
))))))
)
Done.
38 changes: 38 additions & 0 deletions test/scaladoc/run/anyref-doc.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

import scala.tools.nsc.{ScalaDocReporter, doc, io}
import scala.tools.nsc.doc.DocFactory
import scala.tools.nsc.doc.model._
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.partest.ScaladocModelTest

object Test extends ScaladocModelTest {
def destinationDir = "target/anyref"
override def code = """class A"""
override def scaladocSettings =
s"-doc-no-compile src/library-aux -d ${destinationDir}"

def testModel(rootPackage: Package): Unit = {
import access._
val t = rootPackage._package("scala")._class("AnyRef")

val notifyAll = t._method("notifyAll")
println(notifyAll.comment)

val List(wait1, wait2, wait3) = t._methods("wait")
println(List(wait1, wait2, wait3))
println(wait1.comment)
println(wait2.comment)
println(wait3.comment)
}
}

0 comments on commit 7000734

Please sign in to comment.