summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-04-24 17:29:05 +0000
committermichelou <michelou@epfl.ch>2007-04-24 17:29:05 +0000
commit2647716232805f77ed81eabc491759f5362d5e01 (patch)
treec7b44c9c0c4fb39fbba08f97323570131146e215
parentfef68d7c3f75d5a5e5a0f05b8fcb60ede227a437 (diff)
downloadscala-2647716232805f77ed81eabc491759f5362d5e01.tar.gz
scala-2647716232805f77ed81eabc491759f5362d5e01.tar.bz2
scala-2647716232805f77ed81eabc491759f5362d5e01.zip
added scaladoc options and dependency check
-rw-r--r--src/compiler/scala/tools/ant/Scaladoc.scala24
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala3
-rw-r--r--src/compiler/scala/tools/nsc/Main.scala6
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala112
-rw-r--r--src/compiler/scala/tools/nsc/doc/DocDriver.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelFrames.scala82
6 files changed, 146 insertions, 83 deletions
diff --git a/src/compiler/scala/tools/ant/Scaladoc.scala b/src/compiler/scala/tools/ant/Scaladoc.scala
index fd8cfc61d0..33ba2f1ded 100644
--- a/src/compiler/scala/tools/ant/Scaladoc.scala
+++ b/src/compiler/scala/tools/ant/Scaladoc.scala
@@ -41,7 +41,7 @@ import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
* <li>extdirsref,</li>
* <li>encoding,</li>
* <li>windowtitle,</li>
- * <li>documenttitle,</li>
+ * <li>doctitle,</li>
* <li>addparams,</li>
* <li>deprecation,</li>
* <li>unchecked.</li>
@@ -101,7 +101,7 @@ class Scaladoc extends MatchingTask {
/** The window title of the generated HTML documentation. */
private var windowtitle: Option[String] = None
/** The document title of the generated HTML documentation. */
- private var documenttitle: Option[String] = None
+ private var doctitle: Option[String] = None
/** Instruct the compiler to use additional parameters */
private var addParams: String = ""
@@ -257,12 +257,12 @@ class Scaladoc extends MatchingTask {
def setWindowtitle(input: String): Unit =
windowtitle = Some(input)
- /** Sets the <code>documenttitle</code> attribute.
+ /** Sets the <code>doctitle</code> attribute.
*
- * @param input The value of <code>documenttitle</code>.
+ * @param input The value of <code>doctitle</code>.
*/
- def setDocumenttitle(input: String): Unit =
- documenttitle = Some(input)
+ def setDoctitle(input: String): Unit =
+ doctitle = Some(input)
/** Set the <code>addparams</code> info attribute.
*
@@ -476,14 +476,14 @@ class Scaladoc extends MatchingTask {
if (!extdirs.isEmpty) settings.extdirs.value = asString(getExtdirs)
if (!encoding.isEmpty) settings.encoding.value = encoding.get
if (!windowtitle.isEmpty) settings.windowtitle.value = windowtitle.get
- if (!documenttitle.isEmpty) settings.documenttitle.value =
+ if (!doctitle.isEmpty) settings.doctitle.value =
// In Ant script characters '<' and '>' must be encoded when
- // used in attribute values, e.g. for attribute "documenttitle"
+ // used in attribute values, e.g. for attribute "doctitle"
// in task Scaladoc you may write:
- // documenttitle="&lt;div&gt;Scala&lt;/div&gt;"
+ // doctitle="&lt;div&gt;Scala&lt;/div&gt;"
// so we have to decode them here.
- documenttitle.get.replaceAll("&lt;", "<").replaceAll("&gt;",">")
- .replaceAll("&amp;", "&").replaceAll("&quot;", "\"")
+ doctitle.get.replaceAll("&lt;", "<").replaceAll("&gt;",">")
+ .replaceAll("&amp;", "&").replaceAll("&quot;", "\"")
settings.deprecation.value = deprecation
settings.unchecked.value = unchecked
log("Scaladoc params = '" + addParams + "'", Project.MSG_DEBUG)
@@ -516,7 +516,7 @@ class Scaladoc extends MatchingTask {
val global: compiler.type = compiler
def outdir = settings.outdir.value
def windowTitle = settings.windowtitle.value
- def documentTitle = settings.documenttitle.value
+ def docTitle = settings.doctitle.value
}
generator.process(run.units)
if (reporter.ERROR.count > 0)
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index e34cf8c5b5..89302b0749 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -60,7 +60,8 @@ class CompilerCommand(arguments: List[String], val settings: Settings,
if (args eq args0) {
error("bad option: '" + args.head + "'")
ok = false
- }
+ } else
+ ok = settings.checkDependencies
}
} else if (settings.Xscript.value || args.head.endsWith(fileEnding)) {
fs = args.head :: fs
diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala
index d522ee07ff..31796d2f36 100644
--- a/src/compiler/scala/tools/nsc/Main.scala
+++ b/src/compiler/scala/tools/nsc/Main.scala
@@ -37,7 +37,7 @@ object Main extends AnyRef with EvalLoop {
(new compiler.Run) compile command.files
}
- def process(args: Array[String]): unit = {
+ def process(args: Array[String]) {
val settings = new Settings(error)
reporter = new ConsoleReporter(settings)
val command = new CompilerCommand(List.fromArray(args), settings, error, false)
@@ -47,7 +47,7 @@ object Main extends AnyRef with EvalLoop {
reporter.info(null, command.usageMsg, true)
else {
try {
- object compiler extends Global(command.settings, reporter);
+ object compiler extends Global(command.settings, reporter)
if (command.settings.resident.value)
resident(compiler)
else if (command.files.isEmpty)
@@ -60,7 +60,7 @@ object Main extends AnyRef with EvalLoop {
val global : compiler.type = compiler
def outdir = command.settings.outdir.value
def windowTitle = command.settings.windowtitle.value
- def documentTitle = command.settings.documenttitle.value
+ def docTitle = command.settings.doctitle.value
};
generator.process(run.units)
}
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index e1e239b92e..acfa98187f 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -6,8 +6,8 @@
package scala.tools.nsc
-import java.lang.System
import java.io.File
+import java.lang.System
class Settings(error: String => unit) {
def this() = this(Console.println)
@@ -73,9 +73,6 @@ class Settings(error: String => unit) {
new java.io.OutputStreamWriter(
new java.io.ByteArrayOutputStream()).getEncoding
- private val windowtitleDefault = "Scala Library Documentation"
- private val documenttitleDefault = "Scala 2"
-
val doc = new BooleanSetting("-doc", "Generate documentation") { override def hiddenToIDE = true }
val debuginfo = new DebugSetting("-g", "Generate debugging info", List("none", "source", "line", "vars", "notc"), "vars", "vars")
val nowarnings = BooleanSetting("-nowarn", "Generate no warnings")
@@ -88,12 +85,10 @@ class Settings(error: String => unit) {
val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions", extdirsDefault)
val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", ".")
val encoding = new StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", encodingDefault) { override def hiddenToIDE = false }
- val windowtitle = StringSetting ("-windowtitle", "windowtitle", "Specify window title of generated HTML documentation", windowtitleDefault)
- val documenttitle = StringSetting ("-documenttitle", "documenttitle", "Specify document title of generated HTML documentation", documenttitleDefault)
val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm-1.5", "jvm-1.4", "msil", "cldc"), "jvm-1.4")
val migrate = BooleanSetting("-migrate", "Assist in migrating from Scala version 1.0")
- val assemname = StringSetting ("-o", "file", "Name of the output assembly (only relevant with -target:msil)", "")
- val assemrefs = StringSetting ("-r", "path", "List of assemblies referenced by the program (only relevant with -target:msil)", ".")
+ val assemname = StringSetting ("-o", "file", "Name of the output assembly (only relevant with -target:msil)", "").dependsOn(target, "msil")
+ val assemrefs = StringSetting ("-r", "path", "List of assemblies referenced by the program (only relevant with -target:msil)", ".").dependsOn(target, "msil")
val debug = new BooleanSetting("-debug", "Output debugging messages") { override def hiddenToIDE = true }
val deprecation = BooleanSetting ("-deprecation", "enable detailed deprecation warnings")
val unchecked = BooleanSetting ("-unchecked", "enable detailed unchecked warnings")
@@ -138,6 +133,38 @@ class Settings(error: String => unit) {
//Xplugtypes.value = true // just while experimenting
val Xkilloption = BooleanSetting("-Xkilloption", "optimizes option types")
+ /** scaladoc specific options */
+ val windowtitle = StringSetting("-windowtitle", "windowtitle",
+ "Specify window title of generated HTML documentation",
+ /*default*/"Scala 2 API Specification").dependsOn(doc)
+ val doctitle = StringSetting("-doctitle", "doctitle",
+ "Include title for the overview page",
+ /*default*/"Scala 2").dependsOn(doc)
+ val stylesheetfile = StringSetting("-stylesheetfile", "stylesheetfile",
+ "File to change style of the generated documentation",
+ /*default*/"style.css").dependsOn(doc)
+ val pageheader = StringSetting("-header", "pageheader",
+ "Include header text for each page",
+ /*default*/"").dependsOn(doc)
+ val pagefooter = StringSetting("-footer", "pagefooter",
+ "Include footer text for each page",
+ /*default*/"").dependsOn(doc)
+ val pagetop = StringSetting("-top", "pagetop",
+ "Include top text for each page",
+ /*default*/"").dependsOn(doc)
+ val pagebottom = StringSetting("-bottom", "pagebottom",
+ "Include bottom text for each page",
+ /*default*/"").dependsOn(doc)
+ val nocomment = new BooleanSetting("-nocomment", "Suppress description and tags, generate only declarations.") {
+ override def hiddenToIDE = true; dependsOn(doc)
+ }
+ val doccharset = StringSetting("-charset", "doccharset",
+ "Charset for cross-platform viewing of generated documentation.",
+ /*default*/"").dependsOn(doc)
+ val linksource = new BooleanSetting("-linksource", "Generate source in HTML") {
+ override def hiddenToIDE = true; dependsOn(doc)
+ }
+
/** A list of all settings */
def allSettings: List[Setting] = allsettings.reverse
@@ -146,6 +173,24 @@ class Settings(error: String => unit) {
allsettings = allsettings filter (s !=)
}
+ def checkDependencies: boolean = {
+ def hasValue(s: Setting, value: String): boolean = s match {
+ case bs: BooleanSetting => bs.value
+ case ss: StringSetting => ss.value == value
+ case cs: ChoiceSetting => cs.value == value
+ case _ => "" == value
+ }
+ var ok = true
+ for (setting <- allsettings if !setting.dependency.isEmpty) {
+ val (dep, value) = setting.dependency.get
+ if (! (setting.isDefault || hasValue(dep, value))) {
+ error("incomplete option " + setting.name + " (requires " + dep.name + ")")
+ ok = false
+ }
+ }
+ ok
+ }
+
/** A base class for settings of all types.
* Subclasses each define a `value' field of the appropriate type.
*/
@@ -175,7 +220,14 @@ class Settings(error: String => unit) {
/** override if option should be hidden from IDE.
*/
- def hiddenToIDE : Boolean = false
+ def hiddenToIDE: Boolean = false
+
+ protected var setByUser: boolean = false
+ def isDefault: Boolean = !setByUser
+
+ protected[Settings] var dependency: Option[(Setting, String)] = None
+ def dependsOn(s: Setting, value: String): this.type = { dependency = Some((s, value)); this }
+ def dependsOn(s: Setting): this.type = dependsOn(s, "")
// initialization
allsettings = this :: allsettings
@@ -183,27 +235,29 @@ class Settings(error: String => unit) {
/** A setting represented by a boolean flag (false, unless set) */
case class BooleanSetting(name: String, descr: String) extends Setting(descr) {
- var value: boolean = false
+ protected var v: boolean = false
+
+ def value: boolean = this.v
+ def value_=(s: boolean) { setByUser = true; this.v = s }
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (n == name) => value = true; rest
case _ => args
}
- def unparse: List[String] =
- if (value)
- List(name)
- else
- Nil
+ def unparse: List[String] = if (value) List(name) else Nil
}
/** A setting represented by a string, (`default' unless set) */
case class StringSetting(name: String, arg: String, descr: String, default: String)
extends Setting(descr) {
- override def hiddenToIDE = true;
+ override def hiddenToIDE = true
var abbreviation: String = null
- var value: String = default
+ protected var v: String = default
+
+ def value: String = this.v
+ def value_=(s: String) { setByUser = true; this.v = s }
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (name == n || abbreviation == n) =>
@@ -220,10 +274,7 @@ class Settings(error: String => unit) {
override def helpSyntax = name + " <" + arg + ">"
def unparse: List[String] =
- if (value == default)
- Nil
- else
- List(name, value)
+ if (value == default) Nil else List(name, value)
}
/** A setting represented by a string in a given set of <code>choices</code>,
@@ -234,7 +285,7 @@ class Settings(error: String => unit) {
protected var v: String = default
def value: String = this.v
- def value_=(s: String): Unit = this.v = s;
+ def value_=(s: String) { setByUser = true; this.v = s }
protected def argument: String = name.substring(1)
@@ -256,10 +307,7 @@ class Settings(error: String => unit) {
override def helpSyntax = name + ":<" + argument + ">"
def unparse: List[String] =
- if (value == default)
- Nil
- else
- List(name + ":" + value)
+ if (value == default) Nil else List(name + ":" + value)
}
/** Same as ChoiceSetting but have a <code>level</code> int which tells the
@@ -276,10 +324,11 @@ class Settings(error: String => unit) {
}
case _ => None
}
- var level: Int = indexOf(choices, default).get;
+ var level: Int = indexOf(choices, default).get
- override def value_=(choice: String): Unit = {
- this.v = choice
+ override def value_=(choice: String) {
+ setByUser = true
+ this.v = choice
this.level = indexOf(choices, choice).get
}
@@ -311,7 +360,10 @@ class Settings(error: String => unit) {
case class PhasesSetting(name: String, descr: String)
extends Setting(descr + " <phase>") { // (see -showphases)") {
override def hiddenToIDE = true
- var value: List[String] = List()
+ protected var v: List[String] = List()
+
+ def value: List[String] = this.v
+ def value_=(s: List[String]) { setByUser = true; this.v = s }
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (n startsWith (name + ":")) =>
diff --git a/src/compiler/scala/tools/nsc/doc/DocDriver.scala b/src/compiler/scala/tools/nsc/doc/DocDriver.scala
index 1df9e84c2f..2560cb6027 100644
--- a/src/compiler/scala/tools/nsc/doc/DocDriver.scala
+++ b/src/compiler/scala/tools/nsc/doc/DocDriver.scala
@@ -16,7 +16,7 @@ import scala.xml._
* @author Sean McDirmid
*/
abstract class DocDriver extends ModelFrames with ModelToXML {
- import global._;
+ import global._
object additions extends jcl.LinkedHashSet[Symbol]
object additions0 extends ModelAdditions(global) {
diff --git a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
index 256e910fa4..315ad493f6 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
@@ -10,7 +10,7 @@ import java.io.{File, FileWriter}
import scala.collection.jcl
import scala.compat.Platform.{EOL => LINE_SEPARATOR}
-import scala.xml._
+import scala.xml.{NodeSeq, Text, Unparsed, Utility}
/** This class provides HTML document framing functionality.
*
@@ -20,17 +20,19 @@ trait ModelFrames extends ModelExtractor {
import DocUtil._
def outdir: String
def windowTitle: String
- def documentTitle: String
+ def docTitle: String
def contentFrame = "contentFrame"
def classesFrame = "classesFrame"
def modulesFrame = "modulesFrame"
+
protected val FILE_EXTENSION_HTML = ".html"
protected val NAME_SUFFIX_OBJECT = "$object"
protected val NAME_SUFFIX_PACKAGE = "$package"
-
- def rootTitle = <div class="page-title"> Scala 2<br/>API Specification</div>;
- def rootDesc = <p>This document is the API specification for Scala 2.</p>;
+ def rootTitle =
+ <div class="page-title">{load(docTitle)}<br/>API Specification</div>;
+ def rootDesc =
+ <p>{load("This document is the API specification for " + docTitle)}</p>;
final def hasLink(sym: global.Symbol): Boolean =
if (sym == global.NoSymbol) false
@@ -52,7 +54,7 @@ trait ModelFrames extends ModelExtractor {
idx = path.indexOf('/', idx)
//System.err.println(path + " idx=" + idx)
ct.append(if (idx != -1) "../" else "")
- idx = idx + (if (idx == -1) 0 else 1)
+ idx += (if (idx == -1) 0 else 1)
}
ct.toString
}
@@ -67,31 +69,38 @@ trait ModelFrames extends ModelExtractor {
writer.write(str, 0, str.length())
writer.close()
}
- protected def body: NodeSeq;
- protected def title: String;
- protected def hasBody = true;
+ protected def body: NodeSeq
+ protected def title: String
+ protected def hasBody = true
- //def urlFor(entity : Entity, target : String) : NodeSeq;
- def urlFor(entity : Entity) : String = {
- val ret = this.urlFor(entity.sym);
- assert(ret != null); ret;
+ //def urlFor(entity: Entity, target: String): NodeSeq
+ def urlFor(entity: Entity): String = {
+ val ret = this.urlFor(entity.sym)
+ assert(ret != null);
+ ret
}
- def link(entity : Entity, target : String) = aref(urlFor(entity), target, entity.name);
- protected def shortHeader(entity : Entity) : NodeSeq;
- protected def longHeader(entity : Entity) : NodeSeq;
- import global._;
- import symtab.Flags;
+ def link(entity: Entity, target: String) = aref(urlFor(entity), target, entity.name)
+ protected def shortHeader(entity: Entity): NodeSeq
+ protected def longHeader(entity: Entity): NodeSeq
+ import global._
+ import symtab.Flags
def urlFor(sym: Symbol): String = sym match {
- case sym : TypeSymbol if sym == definitions.AnyRefClass => urlFor0(sym,sym) + FILE_EXTENSION_HTML;
- case psym : ModuleSymbol if psym.isPackage => urlFor0(sym,sym) + FILE_EXTENSION_HTML;
- case sym if !hasLink(sym) => null;
- case msym: ModuleSymbol => urlFor0(sym, sym) + FILE_EXTENSION_HTML
- case csym: ClassSymbol => urlFor0(sym, sym) + FILE_EXTENSION_HTML
- case _ =>
- val cnt = urlFor(decode(sym.owner));
- if (cnt == null) null else cnt + "#" + docName(sym)
+ case sym : TypeSymbol if sym == definitions.AnyRefClass =>
+ urlFor0(sym,sym) + FILE_EXTENSION_HTML
+ case psym : ModuleSymbol if psym.isPackage =>
+ urlFor0(sym,sym) + FILE_EXTENSION_HTML
+ case sym if !hasLink(sym) =>
+ null
+ case msym: ModuleSymbol =>
+ urlFor0(sym, sym) + FILE_EXTENSION_HTML
+ case csym: ClassSymbol =>
+ urlFor0(sym, sym) + FILE_EXTENSION_HTML
+ case _ =>
+ val cnt = urlFor(decode(sym.owner));
+ if (cnt == null) null else cnt + "#" + docName(sym)
}
+
def docName(sym: Symbol): String = {
def javaParams(paramTypes: List[Type]): String = {
def javaName(pt: Type): String = {
@@ -117,6 +126,7 @@ trait ModelFrames extends ModelExtractor {
case _ => ""
}), encoding)
}
+
def urlFor0(sym: Symbol, orig: Symbol): String = {
(if (sym == NoSymbol) "XXX"
else if (sym.owner.isPackageClass) {
@@ -136,15 +146,15 @@ trait ModelFrames extends ModelExtractor {
})
}
}
- protected def rootFor(sym: global.Symbol) = "";
+ protected def rootFor(sym: global.Symbol) = ""
private val doctitle: NodeSeq =
- <div class="doctitle-larger">{load(documentTitle)}</div>;
+ <div class="doctitle-larger">{load(docTitle)}</div>;
abstract class AllPackagesFrame extends Frame {
- override val path = "modules";
- override val title = "List of all packages";
- def packages : Iterable[Package];
+ override val path = "modules"
+ override val title = "List of all packages"
+ def packages: Iterable[Package]
override def body: NodeSeq =
<div>
{doctitle}
@@ -158,9 +168,9 @@ trait ModelFrames extends ModelExtractor {
</ul>;
}
abstract class PackagesContentFrame extends Frame {
- val path = "root-content";
- val title = "All Packages";
- def packages : Iterable[Package];
+ val path = "root-content"
+ val title = "All Packages"
+ def packages : Iterable[Package]
//def modules: TreeMap[String, ModuleClassSymbol]
def body: NodeSeq =
{rootTitle} ++ {rootDesc} ++ <hr/> ++
@@ -184,7 +194,7 @@ trait ModelFrames extends ModelExtractor {
p.substring(0, p.length() - NAME_SUFFIX_PACKAGE.length());
else p) + navSuffix;
}
- protected def navSuffix = "$content.html";
+ protected def navSuffix = "$content.html"
def body: NodeSeq = {
val nav = if (navLabel == null) NodeSeq.Empty else
@@ -193,7 +203,7 @@ trait ModelFrames extends ModelExtractor {
{aref(navPath, contentFrame, navLabel)}
</td></tr>
</table>;
- val ids = new jcl.LinkedHashSet[String];
+ val ids = new jcl.LinkedHashSet[String]
def idFor(kind: Category, t: Entity)(seq : NodeSeq): NodeSeq = {
val ch = t.listName.charAt(0);
val id = kind.plural + "_" + ch;