/
Uncompilable.scala
79 lines (68 loc) · 2.85 KB
/
Uncompilable.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* 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.
*/
package scala.tools.nsc
package doc
import scala.language.implicitConversions
import scala.reflect.internal.util.NoPosition
import scala.tools.nsc.Reporting.WarningCategory
/** Some glue between DocParser (which reads source files which can't be compiled)
* and the scaladoc model.
*/
trait Uncompilable {
val global: Global
val settings: Settings
import global.{ reporter, inform, newTypeName, newTermName, runReporting, Symbol, DocComment, MethodSymbol, NoSymbol }
import global.definitions.{ AnyRefClass, AnyRefTpe }
import global.rootMirror.RootClass
private implicit def translateName(name: Global#Name): global.Name =
if (name.isTypeName) newTypeName("" + name) else newTermName("" + name)
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 code = f.slurp()
val comments = docPairs(code)
if (settings.verbose.value) {
inform(s"Found ${comments.size} doc comments in parse-only file $f: " + comments.map(_._1).mkString(", "))
}
comments
}
def files = settings.uncompilableFiles
def symbols = pairs map (_._1)
def templates = symbols.filter(x => x.isClass || x.isTrait || x == AnyRefClass/* which is now a type alias */).toSet
def comments = {
if (settings.isDebug || settings.verbose.value)
inform("Found %d uncompilable files: %s".format(files.size, files mkString ", "))
if (pairs.isEmpty)
runReporting.warning(NoPosition, "no doc comments read from " + settings.docUncompilable.value, WarningCategory.Scaladoc, site = "")
pairs
}
override def toString = "" + pairs.size + " uncompilable symbols:\n" + (
symbols filterNot (_ == NoSymbol) map (x => " " + x.owner.fullName + " " + x.defString) mkString "\n"
)
}