diff options
author | Paul Phillips <paulp@improving.org> | 2010-10-16 19:02:41 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-10-16 19:02:41 +0000 |
commit | 5cdb213d7d24ae357c518823e1054cb302b250eb (patch) | |
tree | 90812d869840df297b4fa9afa0a7dae43ddc1d9a /src/build | |
parent | 87134363a20bc81297037d8858ee88e961f255f9 (diff) | |
download | scala-5cdb213d7d24ae357c518823e1054cb302b250eb.tar.gz scala-5cdb213d7d24ae357c518823e1054cb302b250eb.tar.bz2 scala-5cdb213d7d24ae357c518823e1054cb302b250eb.zip |
Documentation being generated by genprod was pr...
Documentation being generated by genprod was pretty busted both in terms
of formatting and correctness. Spruced it up. Eliminated some of the
more distracting HTML entities in compiler source. No review.
Diffstat (limited to 'src/build')
-rw-r--r-- | src/build/genprod.scala | 111 |
1 files changed, 49 insertions, 62 deletions
diff --git a/src/build/genprod.scala b/src/build/genprod.scala index 08e907e99c..2017d7ff48 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -7,14 +7,11 @@ \* */ -/** <p> - * This program generates the <code>ProductN</code>, <code>TupleN</code> <code>FunctionN</code> classes, where - * <code>0 <= N <+ MAXWIDTH</code>. - * </p> - * <p> - * usage: <code>scala -classpath ... genprod PATH</code> - * where <code>PATH</code> is the desired output directory - * </p> +/** This program generates the ProductN, TupleN, FunctionN, + * and AbstractFunctionN, where 0 <= N <= MAX_ARITY. + * + * Usage: scala genprod <directory> + * where the argument is the desired output directory * * @author Burak Emir, Stephane Micheloud, Geoffrey Washburn, Paul Phillips * @version 1.1 @@ -73,7 +70,6 @@ object genprod { ** |/ ** \* */ - %s package %s @@ -88,21 +84,10 @@ package %s } val out = args(0) def writeFile(node: scala.xml.Node) { - import java.io.{File, FileOutputStream} - import java.nio.channels.Channels - val f = new File(out, node.attributes("name").toString) - try { - f.createNewFile - val fos = new FileOutputStream(f) - val c = fos.getChannel - val w = Channels.newWriter(c, "utf-8") - w.write(node.text) - w.close - } catch { - case e: java.io.IOException => - println(e.getMessage() + ": " + f) - exit(-1) - } + import scala.tools.nsc.io._ + val f = Path(out) / node.attributes("name").toString + f.parent.createDirectory(force = true) + f.toFile writeAll node.text } allfiles foreach writeFile @@ -118,15 +103,16 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz */ object FunctionZero extends Function(0) { override def covariantSpecs = "@specialized " override def descriptiveComment = functionNTemplate.format("currentSeconds", "anonfun0", -""" * - * <b>val</b> currentSeconds = () => System.currentTimeMillis() / 1000L +""" + * val currentSeconds = () => System.currentTimeMillis() / 1000L * - * <b>val</b> anonfun0 = <b>new</b> Function0[Long] { - * <b>def</b> apply(): Long = System.currentTimeMillis() / 1000L + * val anonfun0 = new Function0[Long] { + * def apply(): Long = System.currentTimeMillis() / 1000L * } * * println(currentSeconds()) - * println(anonfun0())""") + * println(anonfun0()) + * """) override def moreMethods = "" } @@ -135,15 +121,16 @@ object FunctionOne extends Function(1) { override def covariantSpecs = "@specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) " override def descriptiveComment = functionNTemplate.format("succ", "anonfun1", -""" * - * <b>val</b> succ = (x: Int) => x + 1 +""" + * val succ = (x: Int) => x + 1 * - * <b>val</b> anonfun1 = <b>new</b> Function1[Int, Int] { - * <b>def</b> apply(x: Int): Int = x + 1 + * val anonfun1 = new Function1[Int, Int] { + * def apply(x: Int): Int = x + 1 * } * * println(succ(0)) - * println(anonfun1(0))""") + * println(anonfun1(0)) + * """) override def moreMethods = """ /** (f compose g)(x) == f(g(x)) @@ -177,15 +164,16 @@ object FunctionTwo extends Function(2) { override def covariantSpecs = "@specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) " override def descriptiveComment = functionNTemplate.format("max", "anonfun2", -""" * - * <b>val</b> max = (x: Int, y: Int) => <b>if</b> (x < y) y <b>else</b> x +""" + * val max = (x: Int, y: Int) => if (x < y) y else x * - * <b>val</b> anonfun2 = <b>new</b> Function2[Int, Int, Int] { - * <b>def</b> apply(x: Int, y: Int): Int = <b>if</b> (x < y) y <b>else</b> x + * val anonfun2 = new Function2[Int, Int, Int] { + * def apply(x: Int, y: Int): Int = if (x < y) y else x * } * * println(max(0, 1)) - * println(anonfun2(0, 1))""") + * println(anonfun2(0, 1)) + * """) } object Function @@ -199,25 +187,21 @@ object Function } } -class Function(val i: Int) extends Group("Function") with Arity -{ - val functionNTemplate = """<p> +class Function(val i: Int) extends Group("Function") with Arity { + val functionNTemplate = """ * In the following example the definition of - * <code>%s</code> is a shorthand for the anonymous class - * definition <code>%s</code>: - * </p> - * <pre> - * <b>object</b> Main <b>extends</b> Application { -%s - * }</pre>""" + * %s is a shorthand for the anonymous class + * definition %s: + * + * {{{ + * object Main extends Application { %s } + * }}}""" def toStr() = "\"" + ("<function%d>" format i) + "\"" def apply() = { <file name={fileName}>{header} -/** <p> - * Function with {i} parameter{s}. - * </p> +/** Function with {i} parameter{s}. * {descriptiveComment} */ trait {className}{contraCoArgs} extends AnyRef {{ self => @@ -599,8 +583,18 @@ object ProductTwo extends Product(2) override def covariantSpecs = "@specialized(Int, Long, Double) " } -class Product(val i: Int) extends Group("Product") with Arity -{ +class Product(val i: Int) extends Group("Product") with Arity { + val productElementComment = """ + /** + * Returns the n-th projection of this product if 0 < n <= productArity, + * otherwise throws IndexOutOfBoundsException. + * + * @param n number of the projection to be returned + * @return same as _(n+1) + * @throws IndexOutOfBoundsException + */ +""" + def cases = { val xs = for ((x, i) <- mdefs.zipWithIndex) yield "case %d => %s".format(i, x) val default = "case _ => throw new IndexOutOfBoundsException(n.toString())" @@ -630,14 +624,7 @@ trait {className}{covariantArgs} extends Product {{ */ override def productArity = {i} - /** - * Returns the n-th projection of this product if 0&lt;=n&lt;arity, - * otherwise <code>null</code>. - * - * @param n number of the projection to be returned - * @return same as _(n+1) - * @throws IndexOutOfBoundsException - */ + {productElementComment} @throws(classOf[IndexOutOfBoundsException]) override def productElement(n: Int) = n match {{ {cases} }} |