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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
object Test {
import java.io.{File, FileReader, FileWriter}
/** Tests the generation of the HTML documentation for some Scala
* code samples (see value 'code' below) with different scaladoc
* options (currently -access:<value>).
*
* @author Stephane Micheloud
*/
def main(args: Array[String]) {
// overwrites value of UrlContext.generator in file DocUtil.scala
System.setProperty("doc.generator", "scaladoc")
var dirname = System.getProperty("partest.output")
if (dirname eq null) dirname = System.getProperty("java.io.tmpdir")
val tmpDir = new File(dirname)
tmpDir.mkdirs()
test1(tmpDir)
test2(tmpDir)
}
private def test1(tmpDir: File) {
def testOptions(inFile: File, outDirName: String, opts: String*) {
val outDir = createDir(tmpDir, outDirName)
val args = Array.concat(Array("-d", outDir.getPath, inFile.getPath), opts.toArray:Array[String])
if (MainDoc.main0(args)) {
for (name <- List("all-classes.html", "index.html")) {
val outFile = new File(outDir, name)
val n = outFile.length.toInt
val in = new FileReader(outFile)
val cbuf = new Array[Char](n)
in.read(cbuf, 0, n)
println(new String(cbuf))
}
println
}
}
val inFile = {
val f = new File(tmpDir.getPath, "docgenerator1.scala")
val writer = new FileWriter(f)
writer.write(code1, 0, code1.length)
writer.close
f
}
testOptions(inFile, "test1", "") // none (default is -access:protected)
testOptions(inFile, "test2", "-access:public")
testOptions(inFile, "test3", "-access:protected")
testOptions(inFile, "test4", "-access:private")
}
private def test2(tmpDir: File) {
val code ="""
package annots
@deprecated("msg")
object Foo { val x = 0 }
@deprecated("msg")
class Bar { val x = 1 }
object Foo1 {
@deprecated("msg")
object Foo11 { val x = 3 }
}
class Bar1 {
@deprecated("msg")
object Foo11 { val x = 2 }
}
class Bar2 {
def bar {
@deprecated("msg")
object Foo21 { val x = 4 }
()
}
}
object Foo2 {
def foo {
@deprecated("msg")
object Foo21 { val x = 5 }
()
}
}
"""
val inFile = {
val f = new File(tmpDir.getPath, "docgenerator2.scala")
val writer = new FileWriter(f)
writer.write(code, 0, code.length)
writer.close
f
}
val outDir = createDir(tmpDir, "annots1")
val args = Array.concat(Array("-d", outDir.getPath, inFile.getPath))
if (MainDoc.main0(args)) {
for (name <- List("all-classes.html", "index.html")) {
val outFile = new File(outDir, name)
val n = outFile.length.toInt
val in = new FileReader(outFile)
val cbuf = new Array[Char](n)
in.read(cbuf, 0, n)
println(new String(cbuf))
}
println
}
}
object MainDoc {
import scala.tools.nsc._
import scala.tools.nsc.doc.DefaultDocDriver
import scala.tools.nsc.reporters.ConsoleReporter
def error(msg: String) { Console.err.println(msg) }
var reporter: ConsoleReporter = _
def process(args: Array[String]) {
val docSettings = new scala.tools.nsc.doc.Settings(error)
// when running that compiler, give it a scala-library to the classpath
docSettings.classpath.value = System.getProperty("java.class.path")
reporter = new ConsoleReporter(docSettings)
val command = new CompilerCommand(args.toList, docSettings)
try {
object compiler extends Global(command.settings, reporter) {
override protected def computeInternalPhases() : Unit = {
phasesSet += syntaxAnalyzer
phasesSet += analyzer.namerFactory
phasesSet += analyzer.typerFactory
}
override def forScaladoc = true
}
if (reporter.hasErrors) {
reporter.flush()
return
}
val run = new compiler.Run
run compile command.files
object generator extends DefaultDocDriver {
lazy val global: compiler.type = compiler
lazy val settings = docSettings
}
generator process run.units
reporter.printSummary()
} catch {
case ex @ FatalError(msg) =>
if (command.settings.debug.value)
ex.printStackTrace();
reporter.error(null, "fatal error: " + msg)
}
}
def main(args: Array[String]) {
process(args)
exit(if (reporter.hasErrors) 1 else 0)
}
// main returning a status (no exit code)
def main0(args: Array[String]): Boolean = {
process(args)
!reporter.hasErrors
}
}
private def createDir(parent: File, dirname: String): File = {
val outDir = new File(parent, dirname)
outDir.mkdir
outDir
}
private val code1 = """
package examples
abstract class C0 {
def foo_public
protected def foo_protected
private def foo_private {}
class C1_Public {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
protected class C1_Protected {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
private class C1_Private {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
}
protected abstract class C0_Protected {
def foo_public
protected def foo_protected
private def foo_private {}
class C1_Public {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
protected class C1_Protected {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
private class C1_Private {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
}
private abstract class C0_Private {
def foo_public
protected def foo_protected
private def foo_private {}
class C1_Public {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
protected class C1_Protected {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
private class C1_Private {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
}
object obj0 {
def bar_public {}
protected def bar_protected {}
private def bar_private {}
object obj1_Public {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
protected object obj1_Protected {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
private object obj1_Private {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
}
protected object obj0_Protected {
def bar_public {}
protected def bar_protected {}
private def bar_private {}
object obj1_Public {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
protected object obj1_Protected {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
private object obj1_Private {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
}
private object obj0_Private {
def bar_public {}
protected def bar_protected {}
private def bar_private {}
object obj1_Public {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
protected object obj1_Protected {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
private object obj1_Private {
val x_public = ()
protected val x_protected = ()
private val x_private = ()
}
}
"""
}
|